summaryrefslogtreecommitdiffstats
path: root/cmake/ExtractValidFlags.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 19:37:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 19:37:08 +0000
commitd710a65c8b50bc3d4d0920dc6e865296f42edd5e (patch)
treed3bf9843448af9398b55f49a50a194bbaacd724e /cmake/ExtractValidFlags.cmake
parentInitial commit. (diff)
downloadnghttp2-d710a65c8b50bc3d4d0920dc6e865296f42edd5e.tar.xz
nghttp2-d710a65c8b50bc3d4d0920dc6e865296f42edd5e.zip
Adding upstream version 1.59.0.upstream/1.59.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--cmake/ExtractValidFlags.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake
new file mode 100644
index 0000000..ccd57dc
--- /dev/null
+++ b/cmake/ExtractValidFlags.cmake
@@ -0,0 +1,31 @@
+# Convenience function that checks the availability of certain
+# C or C++ compiler flags and returns valid ones as a string.
+
+include(CheckCCompilerFlag)
+include(CheckCXXCompilerFlag)
+
+function(extract_valid_c_flags varname)
+ set(valid_flags)
+ foreach(flag IN LISTS ARGN)
+ string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
+ set(flag_var "C_FLAG_${flag_var}")
+ check_c_compiler_flag("${flag}" "${flag_var}")
+ if(${flag_var})
+ set(valid_flags "${valid_flags} ${flag}")
+ endif()
+ endforeach()
+ set(${varname} "${valid_flags}" PARENT_SCOPE)
+endfunction()
+
+function(extract_valid_cxx_flags varname)
+ set(valid_flags)
+ foreach(flag IN LISTS ARGN)
+ string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
+ set(flag_var "CXX_FLAG_${flag_var}")
+ check_cxx_compiler_flag("${flag}" "${flag_var}")
+ if(${flag_var})
+ set(valid_flags "${valid_flags} ${flag}")
+ endif()
+ endforeach()
+ set(${varname} "${valid_flags}" PARENT_SCOPE)
+endfunction()