[CMake] CMAKE_CONFIGURATION_TYPES and PROJECT in macros - strange behavio ur

Brad King brad.king at kitware.com
Wed Feb 9 10:10:53 EST 2005


Dekeyser, Kris wrote:
> However, if we change the BUILD_TYPE in the GUI and reconfigure, the 
> CMAKE_CONFIGURATION_TYPES is not overwritten, but appended to. After a 
> couple of changes from and to debug and release we end up with 
> CMAKE_CONFIGURATION_TYPES="Debug;Release;RelWithDebInfo;MinSizeRel".
[snip]
> I traced this down to the fact that the PROJECT setting is only done in 
> the macro, but why is not clear to me. If I include a PROJECT setting 
> directly in the CMakeLists.txt everything workes as expected.
>  
> WHY ????

The PROJECT command is special in that it internally calls an 
"EnableLanguage" method on the generator.  This call must be done before 
anything can be generated, so there is a check when the top-level 
listfile is parsed to make sure it has a PROJECT command.  If it does 
not, an IMPLICIT project command is automatically added at the top. 
Since in your case the project command is hidden inside the macro it is 
not found and the implicit project command is invoked first.  When it 
runs it sees that CMAKE_CONFIGURATION_TYPES is empty so it adds the 
default configurations "Debug;Release".  Then your project command comes 
along and calls the EnableLanguage code again.  This code has a bug that 
is only exposed in this situation and causes the append behavior.

Please report this bug here:

http://www.cmake.org/Bug

However, having a PROJECT command inside the macro is still probably not 
a good idea, at least in the top-level directory.  CMake will still add 
the implicit PROJECT command.

-Brad


More information about the CMake mailing list