[CMake] VS2005: CMAKE_CXX_FLAGS not used when project() is placed after definition
Jens Auer
jensa at miltenyibiotec.de
Wed Sep 21 03:26:08 EDT 2011
> The PROJECT() command has significant side effects, e.g. for
> C++ projects, it loads Modules/CMakeCXXInformation.cmake containing:
>
> SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
> "Flags used by the compiler during all build types.")
>
> If CMAKE_CXX_FLAGS has no value in the cache before, this
> command will write to the cache *and* to the current scope,
> see [1]. Thus, it will overwrite the value provided in the
> CMakeLists.txt in the first case.
> In the second case, the CMakeLists.txt file provides the
> definitive value in the current scope which will be in effect
> afterwards.
>
> IMO, it's best to have PROJECT() as one of the very first
> commands in CMakeLists.txt files, and to only put other
> commands before it if one really knows about the consequences.
This behvaior seems to be a little inconsistent. When I remember correctly, the optimization switch gets set correctly in both cases, but the /EHa is lost. I also think that overwriting the variable in the current scope is unobivious and should at least be documented in the manual, but I would prefer to not touch the variable or even use the current value.
Best regards,
Jens
More information about the CMake
mailing list