Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddCompilerFlags.cmake
Show All 21 Lines | function(add_cxx_compiler_flag) | ||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) | set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) | ||||
endfunction() | endfunction() | ||||
macro(add_compiler_flag) | macro(add_compiler_flag) | ||||
add_c_compiler_flag(${ARGN}) | add_c_compiler_flag(${ARGN}) | ||||
add_cxx_compiler_flag(${ARGN}) | add_cxx_compiler_flag(${ARGN}) | ||||
endmacro() | endmacro() | ||||
macro(remove_compiler_flags) | macro(remove_c_compiler_flags) | ||||
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") | if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") | ||||
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) | 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}") | set(BUILD_TYPE_C_FLAGS "CMAKE_C_FLAGS_${BUILD_TYPE}") | ||||
endif() | endif() | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
string(REGEX REPLACE "${f}( |$)" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | |||||
string(REGEX REPLACE "${f}( |$)" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | string(REGEX REPLACE "${f}( |$)" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | ||||
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "") | 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}}") | string(REGEX REPLACE "${f}( |$)" "" ${BUILD_TYPE_C_FLAGS} "${${BUILD_TYPE_C_FLAGS}}") | ||||
endif() | endif() | ||||
endforeach() | endforeach() | ||||
endmacro() | 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 | # 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 | # supported by the compiler, but most linker will just drop any unsupported flag | ||||
# (eventually with a warning). | # (eventually with a warning). | ||||
function(add_linker_flag) | function(add_linker_flag) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${f}") | string(APPEND CMAKE_EXE_LINKER_FLAGS " ${f}") | ||||
endforeach() | endforeach() | ||||
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} PARENT_SCOPE) | set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} PARENT_SCOPE) | ||||
endfunction() | endfunction() |