summaryrefslogtreecommitdiffstats
path: root/src/civetweb/cmake/AddCCompilerFlag.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/civetweb/cmake/AddCCompilerFlag.cmake
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/civetweb/cmake/AddCCompilerFlag.cmake38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/civetweb/cmake/AddCCompilerFlag.cmake b/src/civetweb/cmake/AddCCompilerFlag.cmake
new file mode 100644
index 00000000..f5550fa7
--- /dev/null
+++ b/src/civetweb/cmake/AddCCompilerFlag.cmake
@@ -0,0 +1,38 @@
+# - Adds a compiler flag if it is supported by the compiler
+#
+# This function checks that the supplied compiler flag is supported and then
+# adds it to the corresponding compiler flags
+#
+# add_c_compiler_flag(<FLAG> [<VARIANT>])
+#
+# - Example
+#
+# include(AddCCompilerFlag)
+# add_c_compiler_flag(-Wall)
+# add_c_compiler_flag(-no-strict-aliasing RELEASE)
+# Requires CMake 2.6+
+
+if(__add_c_compiler_flag)
+ return()
+endif()
+set(__add_c_compiler_flag INCLUDED)
+
+include(CheckCCompilerFlag)
+
+function(add_c_compiler_flag FLAG)
+ string(TOUPPER "HAVE_C_FLAG_${FLAG}" SANITIZED_FLAG)
+ string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
+ string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+ string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ check_c_compiler_flag("" ${SANITIZED_FLAG})
+ if(${SANITIZED_FLAG})
+ set(VARIANT ${ARGV1})
+ if(ARGV1)
+ string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
+ string(TOUPPER "_${VARIANT}" VARIANT)
+ endif()
+ set(CMAKE_C_FLAGS${VARIANT} "${CMAKE_C_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
+ endif()
+endfunction()
+