88# Create custom properties called CXX_EXCEPTIONS, CXX_RTTI and CXX_STATIC_RUNTIME
99# These get placed at global, directory and target scopes
1010foreach (scope GLOBAL DIRECTORY TARGET )
11- define_property (${scope} PROPERTY "CXX_EXCEPTIONS" INHERITED
12- BRIEF_DOCS "Enable C++ exceptions, defaults to ON at global scope"
13- FULL_DOCS "Enable C++ exceptions, defaults to ON at global scope"
14- )
15- define_property (${scope} PROPERTY "CXX_RTTI" INHERITED
16- BRIEF_DOCS "Enable C++ runtime type information, defaults to ON at global scope"
17- FULL_DOCS "Enable C++ runtime type information, defaults to ON at global scope"
18- )
19- define_property (${scope} PROPERTY "CXX_STATIC_RUNTIME" INHERITED
20- BRIEF_DOCS "Enable linking against the static C++ runtime, defaults to OFF at global scope"
21- FULL_DOCS "Enable linking against the static C++ runtime, defaults to OFF at global scope"
22- )
23- define_property (${scope} PROPERTY "CXX_WARNINGS" INHERITED
24- BRIEF_DOCS "Controls the warning level of compilers, defaults to ON at global scope"
25- FULL_DOCS "Controls the warning level of compilers, defaults to ON at global scope"
26- )
27- define_property (${scope} PROPERTY "CXX_WARNINGS_AS_ERRORS" INHERITED
28- BRIEF_DOCS "Treat warnings as errors and abort compilation on a warning, defaults to OFF at global scope"
29- FULL_DOCS "Treat warnings as errors and abort compilation on a warning, defaults to OFF at global scope"
30- )
11+ define_property (${scope} PROPERTY "CXX_EXCEPTIONS" INHERITED
12+ BRIEF_DOCS "Enable C++ exceptions, defaults to ON at global scope"
13+ FULL_DOCS "Enable C++ exceptions, defaults to ON at global scope"
14+ )
15+ define_property (${scope} PROPERTY "CXX_RTTI" INHERITED
16+ BRIEF_DOCS "Enable C++ runtime type information, defaults to ON at global scope"
17+ FULL_DOCS "Enable C++ runtime type information, defaults to ON at global scope"
18+ )
19+ define_property (${scope} PROPERTY "CXX_STATIC_RUNTIME" INHERITED
20+ BRIEF_DOCS "Enable linking against the static C++ runtime, defaults to OFF at global scope"
21+ FULL_DOCS "Enable linking against the static C++ runtime, defaults to OFF at global scope"
22+ )
23+ define_property (${scope} PROPERTY "CXX_WARNINGS" INHERITED
24+ BRIEF_DOCS "Controls the warning level of compilers, defaults to ON at global scope"
25+ FULL_DOCS "Controls the warning level of compilers, defaults to ON at global scope"
26+ )
27+ define_property (${scope} PROPERTY "CXX_WARNINGS_AS_ERRORS" INHERITED
28+ BRIEF_DOCS "Treat warnings as errors and abort compilation on a warning, defaults to OFF at global scope"
29+ FULL_DOCS "Treat warnings as errors and abort compilation on a warning, defaults to OFF at global scope"
30+ )
3131endforeach ()
3232# Set the default for these properties at global scope. If they are not set per target or
3333# whatever, the next highest scope will be looked up
@@ -44,48 +44,49 @@ set_property(GLOBAL PROPERTY CXX_WARNINGS ${CMAKE_CXX_WARNINGS})
4444set_property (GLOBAL PROPERTY CXX_WARNINGS_AS_ERRORS ${CMAKE_CXX_WARNINGS_AS_ERRORS} )
4545
4646if (MSVC )
47- # Purge unconditional use of /MDd, /MD and /EHsc.
48- foreach (flag
49- CMAKE_C_FLAGS CMAKE_CXX_FLAGS
50- CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG
51- CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE
52- CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL
53- CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO
54- )
55- string (REPLACE "/MDd" "" ${flag} "${${flag} }" )
56- string (REPLACE "/MD" "" ${flag} "${${flag} }" )
57- string (REPLACE "/EHsc" "" ${flag} "${${flag} }" )
58- string (REPLACE "/GR" "" ${flag} "${${flag} }" )
59- endforeach ()
60- # Restore those same, but now selected by the properties
61- add_compile_options (
62- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>,ON >:/EHsc>
63- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_RTTI>>,OFF >:/GR->
64- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,OFF >:$<$<CONFIG:Debug>:/MDd>$<$<NOT :$<CONFIG:Debug>>:/MD >>
65- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,ON >:$<$<CONFIG:Debug>:/MTd>$<$<NOT :$<CONFIG:Debug>>:/MT>>
66- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ON >:/W3>
67- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,OFF >:/W0>
68- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:/W4>
69- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS_AS_ERRORS>>,ON >:/WX>
70- )
47+ # Purge unconditional use of /MDd, /MD and /EHsc.
48+ foreach (flag
49+ CMAKE_C_FLAGS CMAKE_CXX_FLAGS
50+ CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG
51+ CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE
52+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL
53+ CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO
54+ )
55+ string (REPLACE "/MDd" "" ${flag} "${${flag} }" )
56+ string (REPLACE "/MD" "" ${flag} "${${flag} }" )
57+ string (REPLACE "/EHsc" "" ${flag} "${${flag} }" )
58+ string (REPLACE "/GR" "" ${flag} "${${flag} }" )
59+ endforeach ()
60+ # Restore those same, but now selected by the properties
61+ add_compile_options (
62+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>,ON >:/EHsc>
63+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_RTTI>>,OFF >:/GR->
64+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,OFF >:$<$<CONFIG:Debug>:/MDd>$<$<NOT :$<CONFIG:Debug>>:/MD >>
65+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,ON >:$<$<CONFIG:Debug>:/MTd>$<$<NOT :$<CONFIG:Debug>>:/MT>>
66+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ON >:/W3>
67+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,OFF >:/W0>
68+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:/W4>
69+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS_AS_ERRORS>>,ON >:/WX>
70+ )
7171else ()
72- add_compile_options (
73- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>,OFF >:-fno-exceptions>
74- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_RTTI>>,OFF >:-fno-rtti>
75- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,ON >:-static >
76- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ON >:-Wall>
77- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,OFF >:-w>
78- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wall>
79- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-pedantic>
80- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS_AS_ERRORS>>,ON >:-Werror>
81- )
82- if (CMAKE_${COMPILER} _COMPILER_ID MATCHES "Clang" )
8372 add_compile_options (
84- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Weverything>
85- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wall -Wno-macro-redefined>
86- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wno-c++98-compat>
87- $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wno-c++98-compat-pedantic>
73+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>,OFF >:-fno-exceptions>
74+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_RTTI>>,OFF >:-fno-rtti>
75+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_STATIC_RUNTIME>>,ON >:-static >
76+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ON >:-Wall>
77+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,OFF >:-w>
78+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wall>
79+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-pedantic>
80+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS_AS_ERRORS>>,ON >:-Werror>
8881 )
89- endif ()
82+ if (CMAKE_${COMPILER} _COMPILER_ID MATCHES "Clang" )
83+ add_compile_options (
84+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Weverything>
85+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wno-macro-redefined>
86+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wall>
87+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wno-c++98-compat>
88+ $<$<STREQUAL :$<UPPER_CASE:$<TARGET_PROPERTY:CXX_WARNINGS>>,ALL >:-Wno-c++98-compat-pedantic>
89+ )
90+ endif ()
9091endif ()
9192
0 commit comments