]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Move add_compile_flag_if_supported to Utils.cmake
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 17 Mar 2024 18:13:27 +0000 (19:13 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 24 Mar 2024 08:32:13 +0000 (09:32 +0100)
CMakeLists.txt
cmake/DevModeWarnings.cmake
cmake/Utils.cmake [new file with mode: 0644]

index 3e70e94f3a60022ee9a5fae24840840583038da0..4088f8f30d028451afb82932ffb50e4e980cd1d5 100644 (file)
@@ -66,6 +66,7 @@ if(ENABLE_IPO AND NOT MINGW)
   set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
 endif()
 
+include(Utils)
 include(CIBuildType)
 include(DefaultBuildType)
 include(UseFastestLinker)
index c17d4e29c47bd006fc4b869c49ac9fbddd9b795d..f7f1b0c4513f81540f89619fa388aac6963c3ad9 100644 (file)
@@ -1,37 +1,3 @@
-include(CheckCXXCompilerFlag)
-
-# check_cxx_compiler_flag caches the result, so a unique variable name is
-# required for every flag to be checked.
-#
-# Parameters:
-#
-# * flag [in], e.g. FLAG
-# * var_name_of_var_name [in], e.g. "TEMP". This is the variable that "HAS_FLAG"
-#   will be written to.
-function(generate_unique_has_flag_var_name flag var_name_of_var_name)
-  string(REGEX REPLACE "[=-]" "_" var_name "${flag}")
-  string(TOUPPER "${var_name}" var_name)
-  set(${var_name_of_var_name} "HAS_${var_name}" PARENT_SCOPE)
-endfunction()
-
-macro(add_compile_flag_if_supported_ex varname flag alternative_flag)
-  # has_flag will contain "HAS_$flag" so each flag gets a unique HAS variable.
-  generate_unique_has_flag_var_name("${flag}" "has_flag")
-
-  # Instead of passing "has_flag" this passes the content of has_flag.
-  check_cxx_compiler_flag("${flag}" "${has_flag}")
-
-  if(${${has_flag}})
-    list(APPEND "${varname}" "${flag}")
-  elseif("${alternative_flag}")
-    add_compile_flag_if_supported_ex("${varname}" ${alternative_flag} "")
-  endif()
-endmacro()
-
-macro(add_compile_flag_if_supported varname flag)
-  add_compile_flag_if_supported_ex("${varname}" "${flag}" "")
-endmacro()
-
 set(
   _clang_gcc_warnings
   -Wcast-align
diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake
new file mode 100644 (file)
index 0000000..431b8d2
--- /dev/null
@@ -0,0 +1,33 @@
+include(CheckCXXCompilerFlag)
+
+# check_cxx_compiler_flag caches the result, so a unique variable name is
+# required for every flag to be checked.
+#
+# Parameters:
+#
+# * flag [in], e.g. FLAG
+# * var_name_of_var_name [in], e.g. "TEMP". This is the variable that "HAS_FLAG"
+#   will be written to.
+function(_generate_unique_has_flag_var_name flag var_name_of_var_name)
+  string(REGEX REPLACE "[=-]" "_" var_name "${flag}")
+  string(TOUPPER "${var_name}" var_name)
+  set(${var_name_of_var_name} "HAS_${var_name}" PARENT_SCOPE)
+endfunction()
+
+macro(add_compile_flag_if_supported_ex varname flag alternative_flag)
+  # has_flag will contain "HAS_$flag" so each flag gets a unique HAS variable.
+  _generate_unique_has_flag_var_name("${flag}" "has_flag")
+
+  # Instead of passing "has_flag" this passes the content of has_flag.
+  check_cxx_compiler_flag("${flag}" "${has_flag}")
+
+  if(${${has_flag}})
+    list(APPEND "${varname}" "${flag}")
+  elseif("${alternative_flag}")
+    add_compile_flag_if_supported_ex("${varname}" ${alternative_flag} "")
+  endif()
+endmacro()
+
+macro(add_compile_flag_if_supported varname flag)
+  add_compile_flag_if_supported_ex("${varname}" "${flag}" "")
+endmacro()