Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddCompilerFlags.cmake
Show All 12 Lines | function(check_compiler_flag RESULT LANGUAGE FLAG) | ||||
else() | else() | ||||
message(FATAL_ERROR "check_compiler_flag LANGUAGE should be C or CXX") | message(FATAL_ERROR "check_compiler_flag LANGUAGE should be C or CXX") | ||||
endif() | endif() | ||||
set(${RESULT} ${${TEST_NAME}} PARENT_SCOPE) | set(${RESULT} ${${TEST_NAME}} PARENT_SCOPE) | ||||
endfunction() | endfunction() | ||||
function(add_compiler_flags_to_var TARGET LANGUAGE) | function(add_compiler_flags_to_var TARGET LANGUAGE) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
# If the flag is already set, avoid duplicating it | |||||
string(FIND "${${TARGET}}" "${f}" FLAG_POSITION) | |||||
if(${FLAG_POSITION} LESS 0) | |||||
check_compiler_flag(FLAG_IS_SUPPORTED ${LANGUAGE} ${f}) | check_compiler_flag(FLAG_IS_SUPPORTED ${LANGUAGE} ${f}) | ||||
if(${FLAG_IS_SUPPORTED}) | if(${FLAG_IS_SUPPORTED}) | ||||
string(APPEND ${TARGET} " ${f}") | string(APPEND ${TARGET} " ${f}") | ||||
endif() | endif() | ||||
endif() | |||||
endforeach() | endforeach() | ||||
set(${TARGET} ${${TARGET}} PARENT_SCOPE) | set(${TARGET} ${${TARGET}} PARENT_SCOPE) | ||||
endfunction() | endfunction() | ||||
macro(add_c_compiler_flags) | macro(add_c_compiler_flags) | ||||
add_compiler_flags_to_var(CMAKE_C_FLAGS C ${ARGN}) | add_compiler_flags_to_var(CMAKE_C_FLAGS C ${ARGN}) | ||||
endmacro() | endmacro() | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | foreach(f ${ARGN}) | ||||
add_compiler_flags_to_var( | add_compiler_flags_to_var( | ||||
CMAKE_REQUIRED_FLAGS | CMAKE_REQUIRED_FLAGS | ||||
CXX | CXX | ||||
"-Werror=unused-command-line-argument" | "-Werror=unused-command-line-argument" | ||||
) | ) | ||||
# Save the current linker flags | # Save the current linker flags | ||||
set(SAVE_CMAKE_EXE_LINKERFLAGS ${CMAKE_EXE_LINKER_FLAGS}) | set(SAVE_CMAKE_EXE_LINKERFLAGS ${CMAKE_EXE_LINKER_FLAGS}) | ||||
# If the flag is already set, avoid duplicating it | |||||
string(FIND "${CMAKE_EXE_LINKER_FLAGS}" "${f}" FLAG_POSITION) | |||||
if(${FLAG_POSITION} LESS 0) | |||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${f}") | string(APPEND CMAKE_EXE_LINKER_FLAGS " ${f}") | ||||
endif() | |||||
# CHECK_CXX_COMPILER_FLAG calls CHECK_CXX_SOURCE_COMPILES which in turn | # CHECK_CXX_COMPILER_FLAG calls CHECK_CXX_SOURCE_COMPILES which in turn | ||||
# calls try_compile, so it will check our flag | # calls try_compile, so it will check our flag | ||||
CHECK_CXX_COMPILER_FLAG("" ${FLAG_IS_SUPPORTED}) | CHECK_CXX_COMPILER_FLAG("" ${FLAG_IS_SUPPORTED}) | ||||
# Unset the -Werror=unused-command-line-argument flag if it is set. | # Unset the -Werror=unused-command-line-argument flag if it is set. | ||||
remove_compiler_flags_from_var( | remove_compiler_flags_from_var( | ||||
CMAKE_REQUIRED_FLAGS | CMAKE_REQUIRED_FLAGS | ||||
Show All 10 Lines |