[CMake] VS2005: CMAKE_CXX_FLAGS not used when project() is placed after definition

Rolf Eike Beer eike at sf-mail.de
Tue Sep 20 10:54:51 EDT 2011


> Hi,
>
> I encountered a problem with CMAKE_CXX_FLAGS and the place in the
> CMakeLists.txt where the project() command is placed. Consider two
> CMakeLists.txt files, the first containing
> 	SET(CMAKE_CXX_FLAGS "/EHa /O2")
>
> 	project(CMAKE_BUG)
>
> 	add_executable(testEHa "c:/work/tmp/cmake_eha/test.cpp")
>
> And the second containing
>
> 	project(CMAKE_BUG)
>
> 	SET(CMAKE_CXX_FLAGS "/EHa /O2")
>
> 	add_executable(testEHa "c:/work/tmp/cmake_eha/test.cpp")
>
> When I run cmake 2.8.5 on both files, the exception handling option
> differs. For the first file, it is set to 1 in the generated VS project
> file, which means /Ehsc, the default. The second file generates the
> intended project file with windows structured exceptions enabled.
>
> I only checked the generated VS2005 files, so I don't know if this is an
> issue of this specific generator or a more global one.

PROJECT() initializes a bunch of stuff, e.g. it does the compiler
detection and sets the default flags. So what you are seeing is absolutely
expected behaviour.

Eike


More information about the CMake mailing list