summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-07-19 15:13:40 +0200
committerPatrick Steinhardt <ps@pks.im>2018-08-03 09:50:35 +0200
commit186a7ba5d71c38e96af07ec9b8dfa29661fabb5a (patch)
treea60db273f13ae68876383dfdf6078619cd7467cc /cmake
parent07cf8b38dbad7de3f0a5da053726d8e697a65d0d (diff)
downloadlibgit2-186a7ba5d71c38e96af07ec9b8dfa29661fabb5a.tar.gz
cmake: error out if required C flags are not supported
We do want to notify users compiling our source code early on if they try to use C flags which aren't supported. Add a new macro `AddCFlag`, which results in a fatal error in case the flag is not supported, and use it for our fuzzing flags.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/AddCFlagIfSupported.cmake14
1 files changed, 13 insertions, 1 deletions
diff --git a/cmake/Modules/AddCFlagIfSupported.cmake b/cmake/Modules/AddCFlagIfSupported.cmake
index 67fc89510..1d6181cac 100644
--- a/cmake/Modules/AddCFlagIfSupported.cmake
+++ b/cmake/Modules/AddCFlagIfSupported.cmake
@@ -5,9 +5,21 @@
INCLUDE(CheckCCompilerFlag)
+MACRO(ADD_C_FLAG _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}")
+ 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})
CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
IF(IS_${UPCASE_PRETTY}_SUPPORTED)