Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddCompilerFlags.cmake
Show All 28 Lines | |||||
macro(remove_compiler_flags) | macro(remove_compiler_flags) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
string(REGEX REPLACE "${f}( |^)" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) | 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}) | ||||
endforeach() | endforeach() | ||||
endmacro() | endmacro() | ||||
function(add_cxx_compiler_flag_with_fallback TARGET_VAR FLAG FALLBACK) | |||||
set(TMP_FLAG ${FLAG}) | |||||
CHECK_CXX_COMPILER_FLAG(${TMP_FLAG} FLAG_IS_SUPPORTED) | |||||
if(NOT FLAG_IS_SUPPORTED) | |||||
set(TMP_FLAG ${FALLBACK}) | |||||
endif() | |||||
string(APPEND ${TARGET_VAR} "${TMP_FLAG}") | |||||
deadalnix: You probably want to check that the fallback is supported. You also want to make sure you… | |||||
set(${TARGET_VAR} ${${TARGET_VAR}} PARENT_SCOPE) | |||||
endfunction() | |||||
# 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() |
You probably want to check that the fallback is supported. You also want to make sure you remove the fallback flag when you add the other one.