15 lines
596 B
CMake
15 lines
596 B
CMake
include(CheckCCompilerFlag)
|
|
function(add_if_flag_compiles flag)
|
|
CHECK_C_COMPILER_FLAG("${flag}" COMPILER_HAS_THOSE_TOGGLES)
|
|
set(outcome "Failed")
|
|
if(COMPILER_HAS_THOSE_TOGGLES)
|
|
foreach(var ${ARGN})
|
|
set(${var} "${flag} ${${var}}" PARENT_SCOPE)
|
|
endforeach()
|
|
set(outcome "compiles")
|
|
endif()
|
|
message(STATUS "Testing if ${flag} can be used -- ${outcome}")
|
|
# It must be manually removed from the cache; otherwise, the check won't be re-evalated
|
|
# https://cmake.org/cmake/help/latest/module/CheckCCompilerFlag.html
|
|
unset(COMPILER_HAS_THOSE_TOGGLES CACHE)
|
|
endfunction()
|