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) | |||||
function(check_compiler_flag RESULT LANGUAGE FLAG) | |||||
sanitize_variable(${FLAG} TEST_NAME) | |||||
string(PREPEND TEST_NAME "have_${LANGUAGE}_") | |||||
if("${LANGUAGE}" STREQUAL "C") | |||||
CHECK_C_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | |||||
elseif("${LANGUAGE}" STREQUAL "CXX") | |||||
CHECK_CXX_COMPILER_FLAG(${FLAG} ${TEST_NAME}) | |||||
else() | |||||
message(FATAL_ERROR "check_compiler_flag LANGUAGE should be C or CXX") | |||||
endif() | |||||
set(${RESULT} ${${TEST_NAME}} PARENT_SCOPE) | |||||
endfunction() | |||||
function(add_c_compiler_flag) | function(add_c_compiler_flag) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
CHECK_C_COMPILER_FLAG(${f} FLAG_IS_SUPPORTED) | check_compiler_flag(FLAG_IS_SUPPORTED C ${f}) | ||||
if(FLAG_IS_SUPPORTED) | if(${FLAG_IS_SUPPORTED}) | ||||
string(APPEND CMAKE_C_FLAGS " ${f}") | string(APPEND CMAKE_C_FLAGS " ${f}") | ||||
endif() | endif() | ||||
endforeach() | endforeach() | ||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) | set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) | ||||
endfunction() | endfunction() | ||||
function(add_cxx_compiler_flag) | function(add_cxx_compiler_flag) | ||||
foreach(f ${ARGN}) | foreach(f ${ARGN}) | ||||
CHECK_CXX_COMPILER_FLAG(${f} FLAG_IS_SUPPORTED) | check_compiler_flag(FLAG_IS_SUPPORTED CXX ${f}) | ||||
if(FLAG_IS_SUPPORTED) | if(${FLAG_IS_SUPPORTED}) | ||||
string(APPEND CMAKE_CXX_FLAGS " ${f}") | string(APPEND CMAKE_CXX_FLAGS " ${f}") | ||||
endif() | endif() | ||||
endforeach() | endforeach() | ||||
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}) | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |