| 1 |
# - Append compiler flag to CMAKE_C_FLAGS if compiler supports it |
| 2 |
# ADD_C_FLAG_IF_SUPPORTED(<flag>) |
| 3 |
# <flag> - the compiler flag to test |
| 4 |
# This internally calls the CHECK_C_COMPILER_FLAG macro. |
| 5 |
|
| 6 |
include(CheckCCompilerFlag) |
| 7 |
|
| 8 |
macro(ADD_C_FLAG _FLAG) |
| 9 |
string(TOUPPER ${_FLAG} UPCASE) |
| 10 |
string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) |
| 11 |
string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) |
| 12 |
check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) |
| 13 |
|
| 14 |
if(IS_${UPCASE_PRETTY}_SUPPORTED) |
| 15 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") |
| 16 |
else() |
| 17 |
message(FATAL_ERROR "Required flag ${_FLAG} is not supported") |
| 18 |
endif() |
| 19 |
endmacro() |
| 20 |
|
| 21 |
macro(ADD_C_FLAG_IF_SUPPORTED _FLAG) |
| 22 |
string(TOUPPER ${_FLAG} UPCASE) |
| 23 |
string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) |
| 24 |
string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) |
| 25 |
check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) |
| 26 |
|
| 27 |
if(IS_${UPCASE_PRETTY}_SUPPORTED) |
| 28 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") |
| 29 |
endif() |
| 30 |
endmacro() |