@@ -25,27 +25,25 @@ Bypasses:
2525Module exposes the following function:
2626
2727```cmake
28- php_check_compiler_flag(<lang> <flag > <result_var>)
28+ php_check_compiler_flag(<lang> <flags > <result_var>)
2929```
3030
31- Check that the <flag> is accepted by the <lang> compiler without issuing any
32- diagnostic message. The result is stored in an internal cache entry named
33- `<result_var>`. The language `<lang>` can be one of the supported languages by
34- the CMake's `CheckCompilerFlag` module.
31+ Check that the given flag(s) specified in `<flags>` are accepted by the `<lang>`
32+ compiler without issuing any diagnostic message. The result is stored in an
33+ internal cache entry named `<result_var>`. The language `<lang>` can be one of
34+ the supported languages by the CMake's `CheckCompilerFlag` module. Multiple
35+ flags can be passed as a semicolon-separated list.
3536
36- For example:
37+ # Examples
3738
38- ```cmake
39- include(PHP/CheckCompilerFlag)
40-
41- php_check_compiler_flag(C -Wno-clobbered PHP_HAVE_WNO_CLOBBERED)
42- ```
43-
44- ## Usage
39+ Usage example:
4540
4641```cmake
4742# CMakeLists.txt
43+
4844include(PHP/CheckCompilerFlag)
45+
46+ php_check_compiler_flag(C -Wno-clobbered PHP_HAS_WNO_CLOBBERED)
4947```
5048#]=============================================================================]
5149
@@ -54,7 +52,7 @@ include_guard(GLOBAL)
5452include (CheckCompilerFlag)
5553include (CMakePushCheckState)
5654
57- function (php_check_compiler_flag lang flag result)
55+ function (php_check_compiler_flag lang flags result)
5856 cmake_parse_arguments (
5957 PARSE_ARGV
6058 3
@@ -78,27 +76,37 @@ function(php_check_compiler_flag lang flag result)
7876 endif ()
7977
8078 if (NOT CMAKE_REQUIRED_QUIET)
81- message (CHECK_START "Checking whether the ${lang} compiler accepts ${flag } " )
79+ message (CHECK_START "Checking whether the ${lang} compiler accepts ${flags } " )
8280 endif ()
8381
8482 cmake_push_check_state()
8583 set (CMAKE_REQUIRED_QUIET TRUE )
8684
8785 # Bypass the '-Wno-*' compile options for all compilers except those known
8886 # to emit diagnostic messages for unknown -Wno-* flags.
89- if (
90- NOT CMAKE_${lang} _COMPILER_ID MATCHES "^(AppleClang|Clang|MSVC)$"
91- AND flag MATCHES "^-Wno-"
92- # Exclude the '-Wno-error' and '-Wno-attributes=*' flags.
93- AND NOT flag MATCHES "^-Wno-error(=|$)|^-Wno-attributes="
94- )
95- string (REGEX REPLACE "^-Wno-" "-W" flag ${flag} )
96- endif ()
87+ set (processedFlags "" )
88+ foreach (flag IN LISTS flags )
89+ if (
90+ NOT CMAKE_${lang} _COMPILER_ID MATCHES "^(AppleClang|Clang|MSVC)$"
91+ AND flag MATCHES "^-Wno-"
92+ # Exclude the '-Wno-error' and '-Wno-attributes=*' flags.
93+ AND NOT flag MATCHES "^-Wno-error(=|$)|^-Wno-attributes="
94+ )
95+ string (REGEX REPLACE "^-Wno-" "-W" flag "${flag} " )
96+ endif ()
97+
98+ list (APPEND processedFlags "${flag} " )
99+ endforeach ()
100+ set (flags ${processedFlags} )
97101
98102 # Append -Wunknown-warning-option option if compiler supports it (Clang or
99103 # similar) and was by any chance configured with -Wno-unknown-warning-option
100104 # (via environment CFLAGS or CMAKE_C_FLAGS).
101- if (flag MATCHES "^-W" )
105+ foreach (flag IN LISTS flags )
106+ if (NOT flag MATCHES "^-W" )
107+ continue ()
108+ endif ()
109+
102110 check_compiler_flag(
103111 ${lang}
104112 -Wunknown-warning-option
@@ -108,9 +116,11 @@ function(php_check_compiler_flag lang flag result)
108116 if (_php_check_compiler_flag_${lang} _unknown_warning_option)
109117 string (APPEND CMAKE_REQUIRED_FLAGS " -Wunknown-warning-option" )
110118 endif ()
111- endif ()
112119
113- check_compiler_flag(${lang} ${flag} ${result} )
120+ break ()
121+ endforeach ()
122+
123+ check_compiler_flag(${lang} "${flags} " ${result} )
114124 cmake_pop_check_state()
115125
116126 if (NOT CMAKE_REQUIRED_QUIET)
0 commit comments