diff options
author | Jacques Germishuys <jacquesg@striata.com> | 2014-04-19 23:07:50 +0200 |
---|---|---|
committer | Jacques Germishuys <jacquesg@striata.com> | 2014-04-19 23:07:50 +0200 |
commit | 5c8d5eac35794391c935e273612744a0684beb29 (patch) | |
tree | 0e7156abc56bc666331ed9d575926e1a6cdd8cb6 /cmake/Modules | |
parent | 364ef52881f98293a5e454aab447bc7c2a3d3725 (diff) | |
download | libgit2-5c8d5eac35794391c935e273612744a0684beb29.tar.gz |
Introduce AddCFlagIfSupported CMake macro
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/AddCFlagIfSupported.cmake | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cmake/Modules/AddCFlagIfSupported.cmake b/cmake/Modules/AddCFlagIfSupported.cmake new file mode 100644 index 000000000..67fc89510 --- /dev/null +++ b/cmake/Modules/AddCFlagIfSupported.cmake @@ -0,0 +1,16 @@ +# - Append compiler flag to CMAKE_C_FLAGS if compiler supports it +# ADD_C_FLAG_IF_SUPPORTED(<flag>) +# <flag> - the compiler flag to test +# This internally calls the CHECK_C_COMPILER_FLAG macro. + +INCLUDE(CheckCCompilerFlag) + +MACRO(ADD_C_FLAG_IF_SUPPORTED _FLAG) + STRING(TOUPPER ${_FLAG} UPCASE) + STRING(REGEX REPLACE "^-" "" UPCASE_PRETTY ${UPCASE}) + CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) + + IF(IS_${UPCASE_PRETTY}_SUPPORTED) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") + ENDIF() +ENDMACRO() |