diff --git a/cmake/modules/AddCompilerFlags.cmake b/cmake/modules/AddCompilerFlags.cmake --- a/cmake/modules/AddCompilerFlags.cmake +++ b/cmake/modules/AddCompilerFlags.cmake @@ -98,6 +98,21 @@ set(${TARGET_VAR} ${${TARGET_VAR}} PARENT_SCOPE) endfunction() +function(add_compile_options_to_configuration CONFIGURATION) + foreach(f ${ARGN}) + check_compiler_flag(FLAG_IS_SUPPORTED CXX ${f}) + if(${FLAG_IS_SUPPORTED}) + add_compile_options($<$:${f}>) + endif() + endforeach() +endfunction() + +function(add_compile_definitions_to_configuration CONFIGURATION) + foreach(f ${ARGN}) + add_compile_definitions($<$:${f}>) + endforeach() +endfunction() + # Note that CMake does not provide any facility to check that a linker flag is # supported by the compiler. # However since CMake 3.2 introduced the CMP0056 policy, the diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,10 +47,10 @@ # Define the debugging symbols DEBUG and DEBUG_LOCKORDER when the Debug build # type is selected. -string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DDEBUG -DDEBUG_LOCKORDER") +add_compile_definitions_to_configuration(Debug DEBUG DEBUG_LOCKORDER) # Add -ftrapv when building in Debug -add_compiler_flags_to_var(CMAKE_CXX_FLAGS_DEBUG CXX -ftrapv) +add_compile_options_to_configuration(Debug -ftrapv) # Ensure that WINDRES_PREPROC is enabled when using windres. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") @@ -62,7 +62,7 @@ endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - add_definitions(-DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0) + add_compile_definitions(MAC_OSX OBJC_OLD_DISPATCH_PROTOTYPES=0) endif() if(ENABLE_REDUCE_EXPORTS)