diff --git a/cmake/modules/AddCompilerFlags.cmake b/cmake/modules/AddCompilerFlags.cmake --- a/cmake/modules/AddCompilerFlags.cmake +++ b/cmake/modules/AddCompilerFlags.cmake @@ -27,23 +27,39 @@ add_cxx_compiler_flag(${ARGN}) endmacro() -macro(remove_compiler_flags) +macro(remove_c_compiler_flags) if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) - set(BUILD_TYPE_CXX_FLAGS "CMAKE_CXX_FLAGS_${BUILD_TYPE}") set(BUILD_TYPE_C_FLAGS "CMAKE_C_FLAGS_${BUILD_TYPE}") endif() foreach(f ${ARGN}) - string(REGEX REPLACE "${f}( |$)" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REGEX REPLACE "${f}( |$)" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") - string(REGEX REPLACE "${f}( |$)" "" ${BUILD_TYPE_CXX_FLAGS} "${${BUILD_TYPE_CXX_FLAGS}}") string(REGEX REPLACE "${f}( |$)" "" ${BUILD_TYPE_C_FLAGS} "${${BUILD_TYPE_C_FLAGS}}") endif() endforeach() endmacro() +macro(remove_cxx_compiler_flags) + if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") + string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) + set(BUILD_TYPE_CXX_FLAGS "CMAKE_CXX_FLAGS_${BUILD_TYPE}") + endif() + + foreach(f ${ARGN}) + string(REGEX REPLACE "${f}( |$)" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") + string(REGEX REPLACE "${f}( |$)" "" ${BUILD_TYPE_CXX_FLAGS} "${${BUILD_TYPE_CXX_FLAGS}}") + endif() + endforeach() +endmacro() + +macro(remove_compiler_flags) + remove_c_compiler_flags(${ARGN}) + remove_cxx_compiler_flags(${ARGN}) +endmacro() + # Note that CMake does not provide any facility to check that a linker flag is # supported by the compiler, but most linker will just drop any unsupported flag # (eventually with a warning).