summaryrefslogtreecommitdiff
path: root/cmake/Modules/AddCFlagIfSupported.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules/AddCFlagIfSupported.cmake')
-rw-r--r--cmake/Modules/AddCFlagIfSupported.cmake16
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()