Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddCompilerFlags.cmake
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | macro(remove_cxx_compiler_flags) | ||||
endforeach() | endforeach() | ||||
endmacro() | endmacro() | ||||
macro(remove_compiler_flags) | macro(remove_compiler_flags) | ||||
remove_c_compiler_flags(${ARGN}) | remove_c_compiler_flags(${ARGN}) | ||||
remove_cxx_compiler_flags(${ARGN}) | remove_cxx_compiler_flags(${ARGN}) | ||||
endmacro() | endmacro() | ||||
function(add_cxx_compiler_flag_with_fallback TARGET_VAR FLAG FALLBACK) | |||||
# Remove the fallback flag if it exists, so that the main flag will override | |||||
# it if it was previously added. | |||||
remove_cxx_compiler_flags(${FALLBACK}) | |||||
set(FLAG_CANDIDATE ${FLAG}) | |||||
build_test_name_from_flag(FLAG_IS_SUPPORTED ${FLAG_CANDIDATE}) | |||||
CHECK_CXX_COMPILER_FLAG(${FLAG_CANDIDATE} ${FLAG_IS_SUPPORTED}) | |||||
if(NOT ${FLAG_IS_SUPPORTED}) | |||||
set(FLAG_CANDIDATE ${FALLBACK}) | |||||
build_test_name_from_flag(FLAG_IS_SUPPORTED ${FLAG_CANDIDATE}) | |||||
CHECK_CXX_COMPILER_FLAG(${FLAG_CANDIDATE} ${FLAG_IS_SUPPORTED}) | |||||
endif() | |||||
if(${FLAG_IS_SUPPORTED}) | |||||
append_flag_to_variable(${TARGET_VAR} ${FLAG_CANDIDATE}) | |||||
set(${TARGET_VAR} ${${TARGET_VAR}} PARENT_SCOPE) | |||||
endif() | |||||
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}) | ||||
append_flag_to_variable(CMAKE_EXE_LINKER_FLAGS ${f}) | append_flag_to_variable(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() |