MantisBT - CMake
View Issue Details
0014017CMakeCMakepublic2013-03-15 07:562016-06-10 14:31
Sylwester Arabas 
Kitware Robot 
normalminoralways
closedmoved 
CMake 2.8.11 
 
0014017: Option -DCMAKE_<LANG>_COMPILER=... deletes cached settings even if given original value
Hello,

The commands listed below exemplify that one may get different behaviour of CMake when running:

cmake . -DCMAKE_CXX_COMPILER=g++-4.7 -DCMAKE_BUILD_TYPE=Release

and

cmake . -DCMAKE_CXX_COMPILER=g++-4.7;
cmake . -DCMAKE_BUILD_TYPE=Release

HTH,
Sylwester
$ cat CMakeLists.txt
project(test CXX)
set(CMAKE_CXX_FLAGS_RELEASE "-Ofaast")
add_executable(test test.cpp)


$ cat test.cpp
int main() {}


$ cmake . -DCMAKE_CXX_COMPILER=g++-4.7 -DCMAKE_BUILD_TYPE=Release
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= g++-4.7

-- The CXX compiler identification is GNU 4.7.2
-- Check for working CXX compiler: /usr/bin/g++-4.7
-- Check for working CXX compiler: /usr/bin/g++-4.7 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/slayoo/Temp/cmake-test


$ make
Scanning dependencies of target test
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.o
Linking CXX executable test
[100%] Built target test


$ cmake . -DCMAKE_CXX_COMPILER=g++-4.7; cmake . -DCMAKE_BUILD_TYPE=Release
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= g++-4.7

-- The CXX compiler identification is GNU 4.7.2
-- Check for working CXX compiler: /usr/bin/g++-4.7
-- Check for working CXX compiler: /usr/bin/g++-4.7 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/slayoo/Temp/cmake-test
-- Configuring done
-- Generating done
-- Build files have been written to: /home/slayoo/Temp/cmake-test


$ make
Scanning dependencies of target test
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.o
cc1plus: error: argument to ‘-O’ should be a non-negative integer
make[2]: *** [CMakeFiles/test.dir/test.cpp.o] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
No tags attached.
Issue History
2013-03-15 07:56Sylwester ArabasNew Issue
2013-03-15 08:22Brad KingNote Added: 0032638
2013-03-15 08:22Brad KingStatusnew => resolved
2013-03-15 08:22Brad KingResolutionopen => won't fix
2013-03-16 19:41Brad KingStatusresolved => backlog
2013-03-16 19:41Brad KingResolutionwon't fix => open
2013-03-16 19:41Brad KingProduct VersionCMake 2.8.9 => CMake 2.8.11
2013-03-16 19:41Brad KingSummary-DCMAKE_BUILD_TYPE silently ignored if specified together with -DCMAKE_CXX_COMPILER => Option -DCMAKE_<LANG>_COMPILER=... deletes cached settings even if given original value
2013-03-16 19:44Brad KingNote Edited: 0032638bug_revision_view_page.php?bugnote_id=32638#r1075
2013-03-16 19:50Brad KingNote Added: 0032650
2016-06-10 14:28Kitware RobotNote Added: 0042249
2016-06-10 14:28Kitware RobotStatusbacklog => 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
(0032638)
Brad King   
2013-03-15 08:22   
(edited on: 2013-03-16 19:44)
Using

 cmake . -DCMAKE_CXX_COMPILER=g++-4.7 -DCMAKE_BUILD_TYPE=Release

works correctly when run with a fresh tree.

(0032650)
Brad King   
2013-03-16 19:50   
This is an accidental side effect of the implementation of the "change compiler" feature requested by 0006102. The feature is meant for use when first configuring a source tree with "ccmake" so the compiler can be changed interactively even after the initial configuration. Whenever the value of a CMAKE_<LANG>_COMPILER cache entry changes CMake wipes out the entire CMakeCache.txt so that all try_compile tests and other checks that depend on the compiler choice will be re-run. As a side effect it wipes out all other settings too but in the "ccmake" initial configuration case that is not a problem.

This is triggering improperly in your case. On the first run CMake converts the "-DCMAKE_CXX_COMPILER=g++-4.7" value to a full path, e.g. /usr/bin/g++-4.7. When you run CMake on an existing tree with the same option then the name "g++-4.7" is not the same as the full path so CMake thinks you're changing the compiler (which technically you could be if the PATH is different). Then it wipes out the entire cache including the CMAKE_BUILD_TYPE value it just recorded. It is not completely silent as you originally reported because the output says it is deleting the cache, but it is not a very clear explanation either.
(0042249)
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.