View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014294CMakeCMakepublic2013-07-15 20:172015-01-05 08:39
ReporterGreg Coombe 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformLinuxOSUbuntuOS Version12.04
Product VersionCMake 2.8.11.2 
Target VersionCMake 3.1Fixed in VersionCMake 3.1 
Summary0014294: Specifying CMAKE_CXX_COMPILER=g++ after first run deletes all cached values
DescriptionIf I specify a command-line option using the "option()" function and provide it on the command line along with CMAKE_<lang>_COMPILER option (specified without full path), it is overwritten.
Steps To Reproduce1. Make a small CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.11)
option(RERUN_TEST "Re-run me!" OFF)
message(STATUS "Re-run test variable is " ${RERUN_TEST})


2. Run twice with both the option specified, as well as the compiler:

$ cmake -D RERUN_TEST=ON -D CMAKE_CXX_COMPILER=g++ CMakeLists.txt
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Re-run test variable is ON
-- Configuring done
-- Generating done


$ cmake -D RERUN_TEST=ON -D CMAKE_CXX_COMPILER=g++ CMakeLists.txt
-- Re-run test variable is ON
-- 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++

-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Re-run test variable is OFF
-- Configuring done
-- Generating done


So now we've built the project without the command-line option.

3. Interestingly, note that using the full path of the compiler doesn't have the same behavior:

$ cmake -D RERUN_TEST=ON -D CMAKE_CXX_COMPILER=/usr/bin/g++ CMakeLists.txt
-- Re-run test variable is ON
-- Configuring done
-- Generating done


Additional InformationSpeculation:
It appears that CMake is writing the CMAKE_<lang>_COMPILER value to the cache before expanding it, then interpreting the different value as requiring a re-run. This re-run ignores the command-line options (maybe because the cache is nuked: http://public.kitware.com/Bug/view.php?id=13756 [^]).
TagsNo tags attached.
Attached Filestxt file icon CMakeLists.txt [^] (131 bytes) 2013-07-15 20:17 [Show Content]

 Relationships
duplicate of 0014366closedStephen Kelly Command line definitions ignored if -DCMAKE_C_COMPILER is passed 
related to 0006102closedBill Hoffman Changing compilers should be an easier operation 
related to 0013756closedBrad King Infinite loop when reconfiguring with different CMAKE_C_COMPILER 

  Notes
(0033549)
Brad King (manager)
2013-07-16 08:43

This is caused by the cache-deletion-to-change-compiler created for issue 0006102.

You can work around this by using the environment to select the compiler:

 CXX=g++ cmake ...

or by always passing a full path to set CMAKE_CXX_COMPILER.
(0033550)
Brad King (manager)
2013-07-16 08:48

What happens on the second run is that CMake processes your command-line cache options first. Since they "change" the compiler CMake wipes out the current cache which includes anything just processed.

We have to store the full path in the CMAKE_CXX_COMPILER cache option so that future re-configurations (possibly during "make") are not affected by the PATH. The logic that decides that the compiler has changed does not account for the transformation to a full path.
(0036455)
Brad King (manager)
2014-07-24 13:49

I think this was resolved for 0014366 by:

 Fix resetting the compiler on the command line
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8b2a2db0 [^]

first released in CMake 3.0.

However I think a follow-up change is needed:

 cmGlobalGenerator: Do not re-add CMAKE_<LANG>_COMPILER
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=731427a6 [^]
(0037594)
Robert Maynard (manager)
2015-01-05 08:39

Closing resolved issues that have not been updated in more than 4 months

 Issue History
Date Modified Username Field Change
2013-07-15 20:17 Greg Coombe New Issue
2013-07-15 20:17 Greg Coombe File Added: CMakeLists.txt
2013-07-16 08:39 Brad King Relationship added related to 0006102
2013-07-16 08:39 Brad King Relationship added related to 0013756
2013-07-16 08:43 Brad King Status new => backlog
2013-07-16 08:43 Brad King Summary Command-line options overwritten by re-run => Specifying CMAKE_CXX_COMPILER=g++ after first run deletes all cached values
2013-07-16 08:43 Brad King Note Added: 0033549
2013-07-16 08:48 Brad King Note Added: 0033550
2014-07-24 13:46 Brad King Relationship added duplicate of 0014366
2014-07-24 13:49 Brad King Note Added: 0036455
2014-07-24 13:50 Brad King Assigned To => Brad King
2014-07-24 13:50 Brad King Status backlog => assigned
2014-07-24 13:50 Brad King Target Version => CMake 3.1
2014-07-28 10:52 Brad King Status assigned => resolved
2014-07-28 10:52 Brad King Resolution open => fixed
2014-07-28 10:52 Brad King Fixed in Version => CMake 3.1
2015-01-05 08:39 Robert Maynard Note Added: 0037594
2015-01-05 08:39 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team