Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddCompilerFlags.cmake
# Allow to easily add flags for C and C++ | # Allow to easily add flags for C and C++ | ||||
include(CheckCXXCompilerFlag) | include(CheckCXXCompilerFlag) | ||||
include(CheckCCompilerFlag) | include(CheckCCompilerFlag) | ||||
include(SanitizeHelper) | include(SanitizeHelper) | ||||
function(check_compiler_flag RESULT LANGUAGE FLAG) | function(check_compiler_flag RESULT LANGUAGE FLAG) | ||||
sanitize_variable("have_${LANGUAGE}_" ${FLAG} TEST_NAME) | sanitize_c_cxx_definition("have_${LANGUAGE}_" ${FLAG} TEST_NAME) | ||||
if("${LANGUAGE}" STREQUAL "C") | if("${LANGUAGE}" STREQUAL "C") | ||||
CHECK_C_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | CHECK_C_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | ||||
elseif("${LANGUAGE}" STREQUAL "CXX") | elseif("${LANGUAGE}" STREQUAL "CXX") | ||||
CHECK_CXX_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | CHECK_CXX_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | ||||
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() | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
# 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. | # supported by the compiler. | ||||
# However since CMake 3.2 introduced the CMP0056 policy, the | # However since CMake 3.2 introduced the CMP0056 policy, the | ||||
# CMAKE_EXE_LINKER_FLAGS variable is used by the try_compile function, so there | # CMAKE_EXE_LINKER_FLAGS variable is used by the try_compile function, so there | ||||
# is a workaround that allow for testing the linker flags. | # is a workaround that allow for testing the linker flags. | ||||
function(add_linker_flag) | function(add_linker_flag) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
sanitize_variable("have_linker_" ${f} FLAG_IS_SUPPORTED) | sanitize_c_cxx_definition("have_linker_" ${f} FLAG_IS_SUPPORTED) | ||||
# Some linkers (e.g.: Clang) will issue a -Wunused-command-line-argument | # Some linkers (e.g.: Clang) will issue a -Wunused-command-line-argument | ||||
# warning when an unknown linker flag is set. | # warning when an unknown linker flag is set. | ||||
# Using -Werror will promote these warnings to errors so | # Using -Werror will promote these warnings to errors so | ||||
# CHECK_CXX_COMPILER_FLAG() will return false, preventing the flag from | # CHECK_CXX_COMPILER_FLAG() will return false, preventing the flag from | ||||
# being set. | # being set. | ||||
check_compiler_flag(WUNUSED_CLI_ARGUMENT_IS_SUPPORTED | check_compiler_flag(WUNUSED_CLI_ARGUMENT_IS_SUPPORTED | ||||
CXX | CXX | ||||
Show All 32 Lines |