I am trying to control the flow of my program based on the value of a cmake variable called CMAKE_SIZEOF_VOID_P.
To start off, I wanted to just see what value this variable took under multiple different configurations, by issuing the following command in my cmakelists.txt file:
message(${CMAKE_SIZEOF_VOID_P})
This works perfectly. However, whenever I try to run the above command on my BuildSetup.cmake file, I get no value returned to me (it just throws an error).
It is important that I am able to access the value of this variable in my BuildSetup.cmake file, as that will help me decide what flags and other parameters to pass in to the compiler.
All I really need is a way to determine whether cmake is running a x64 compile or a 32 bit compile, so if there is any other variable (other than this one, since it is not defined in BuildSetup.cmake file) that will give me this, then that would also work for my purposes.
Any help would greatly be appreciated. Thanks.
You can’t use
CMAKE_SIZEOF_VOID_Puntil after you have invoked thePROJECT()command, (I think it’s set during theTRY_COMPILEphase of thePROJECTexecution).Since you’re invoking BuildSetup.cmake using
cmake -C, the contents of BuildSetup.cmake are parsed before anything in your main CMakeLists.txt.However, you probably shouldn’t be using a config file to determine which compiler flags CMake needs, they really belong inside your CMakeLists.txt somewhere after the
PROJECT()command.