MantisBT - CMake
View Issue Details
0013815CMakeCMakepublic2012-12-26 19:102016-06-10 14:31
Stephen McCracken 
Kitware Robot 
normalminoralways
closedmoved 
Visual Studio 11 Win64Windows7
CMake 2.8.10.2 
 
0013815: CMake uses compiler settings under CMakeFiles without verifying that they match the current generator.
The first time you run CMake in a clean directory, the enable_language(C) and enable_language(CXX) commands test the compilers for the currently-selected generator (say 32-bit Visual Studio 11) and caches the results in the files CMakeFiles/CMakeCCompiler.cmake and CMakeFiles/CMakeCXXCompiler.cmake.

If you then delete CMakeCache.txt and switch the generator to 64-bit Visual Studio 11 Win64, CMake will not re-test the compiler, and it will proceed with the incorrect cached results for the old (32-bit) generator.

This behavior can be very confusing when debugging CMake errors. In my case, find_package( PythonLibs 2.7 ) was failing because I was trying to use a 64-bit Python 2.7.3 installation with the 32-bit Visual Studio 11 generator. However, when I switched to 64-bit and deleted CMakeCache.txt (but not the CMakeFiles directory), PythonLibs still was not found because CMake was reading CMAKE_SIZEOF_VOID_P=4 from the CMakeFiles directory, which make it look for 32-bit registry settings for the Python installation directory.
1) Create a simple CMakeLists.txt file with the following 2 lines:

   enable_language( CXX )
   message( STATUS "CMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}" )

2) Run cmake-gui with the Visual Studio 11 generator, and observe the output:
   CMAKE_SIZEOF_VOID_P=4

3) Delete the CMakeCache.txt file.

4) Run cmake-gui again from the same directory, but choose the Visual Studio 11 Win64 generator. Observe the incorrect output value:
   CMAKE_SIZEOF_VOID_P=4

No tags attached.
Issue History
2012-12-26 19:10Stephen McCrackenNew Issue
2012-12-27 04:04Rolf Eike BeerNote Added: 0031944
2012-12-27 08:47David ColeNote Added: 0031945
2012-12-27 13:21Stephen McCrackenNote Added: 0031949
2016-06-10 14:28Kitware RobotNote Added: 0042184
2016-06-10 14:28Kitware RobotStatusnew => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0031944)
Rolf Eike Beer   
2012-12-27 04:04   
Switching the generator requires cleaning the build directory, and this means not only CMakeCache.txt but everything.
(0031945)
David Cole   
2012-12-27 08:47   
I second what Eike said: switching generators invalidates everything in your build tree. Blow the whole thing away and start from scratch.
(0031949)
Stephen McCracken   
2012-12-27 13:21   
Requiring starting from scratch is ok as a policy, but why not put in some simple checks to catch this mistake? It would make the system more robust and possibly reduce the number of bug reports you receive.
(0042184)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.