]>
Commit | Line | Data |
---|---|---|
5c8d5eac JG |
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 | ||
e579e0f7 | 6 | include(CheckCCompilerFlag) |
5c8d5eac | 7 | |
e579e0f7 MB |
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) | |
ac3d33df | 13 | |
e579e0f7 MB |
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() | |
ac3d33df | 20 | |
e579e0f7 MB |
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) | |
5c8d5eac | 26 | |
e579e0f7 MB |
27 | if(IS_${UPCASE_PRETTY}_SUPPORTED) |
28 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") | |
29 | endif() | |
30 | endmacro() |