views:

30

answers:

1

Probably an easy beginners question: I want to add the compiler flag /EHsc to my project and tried both

SET_TARGET_PROPERTIES(name_of_my_project PROPERTIES COMPILER_FLAGS "/EHsc")

and

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")

in my CMakeLists.txt. With both, CMake generates a Visual Studio Solution without complaining.

EDIT: initially I asked why both versions did not work. Well, because I am an idiot and made an error elsewhere so that none of the two lines where ever processed. Still, I'm wondering if both versions are equivalent.

+2  A: 

They are equivalent on a project that has just 1 target.

SET_TARGET_PROPERTIES sets the compiler flag for the named target (which in your case happens to also be the name of the project). If you have more than one target, then the other targets will not have the "/EHsc" flag set.

SET(CMAKE_CXX_FLAGS ...) will set the C++ flags for all targets in the current directory, as well as in any sub-directories. So you can use this to set global C++ flags that apply to all of your targets, i.e. the libraries and executables defined in the project.

rq