diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:08 +0000 |
commit | 29b5ab554790bb57337a3b6ab9dcd963cf69d22e (patch) | |
tree | be1456d2bc6c1fb078695fad7bc8f6b212062d3c /cmake/AddCFlagIfSupported.cmake | |
parent | Initial commit. (diff) | |
download | libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.tar.xz libgit2-29b5ab554790bb57337a3b6ab9dcd963cf69d22e.zip |
Adding upstream version 1.7.2+ds.upstream/1.7.2+ds
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/AddCFlagIfSupported.cmake')
-rw-r--r-- | cmake/AddCFlagIfSupported.cmake | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cmake/AddCFlagIfSupported.cmake b/cmake/AddCFlagIfSupported.cmake new file mode 100644 index 0000000..685f26a --- /dev/null +++ b/cmake/AddCFlagIfSupported.cmake @@ -0,0 +1,30 @@ +# - 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 _FLAG) + string(TOUPPER ${_FLAG} UPCASE) + string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) + check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) + + if(IS_${UPCASE_PRETTY}_SUPPORTED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") + else() + message(FATAL_ERROR "Required flag ${_FLAG} is not supported") + endif() +endmacro() + +macro(ADD_C_FLAG_IF_SUPPORTED _FLAG) + string(TOUPPER ${_FLAG} UPCASE) + string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) + check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) + + if(IS_${UPCASE_PRETTY}_SUPPORTED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") + endif() +endmacro() |