11#[=============================================================================[
2- # CheckFnmatch
2+ Check for a working POSIX 'fnmatch()' function.
33
4- Check for a working POSIX `fnmatch()` function.
4+ This check is based on the 'AC_FUNC_FNMATCH' Autoconf macro. Some versions of
5+ Solaris (2.4), SCO, and the GNU C Library have a broken or incompatible fnmatch.
6+ In cross-compilation it is checked with the CheckSymbolExists module instead
7+ and assumed to have a POSIX-compatible implementation.
58
6- Some versions of Solaris (2.4), SCO, and the GNU C Library have a broken or
7- incompatible fnmatch. When cross-compiling we only enable it for Linux systems.
8- Based on the `AC_FUNC_FNMATCH` Autoconf macro.
9-
10- TODO: This is obsolescent. See Gnulib's fnmatch-gnu module:
9+ Gnulib provides also fnmatch-gnu module:
1110https://www.gnu.org/software/gnulib/MODULES.html#module=fnmatch
1211
13- ## Cache variables
14-
15- * `HAVE_FNMATCH`
12+ Result variables:
1613
17- Whether `fnmatch` is a working POSIX variant.
14+ * HAVE_FNMATCH
15+ #]=============================================================================]
1816
19- ## Usage
17+ # PHP has fnmatch() emulation implemented on Windows.
18+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
19+ set (HAVE_FNMATCH TRUE )
20+ return ()
21+ endif ()
2022
21- ```cmake
22- # CMakeLists.txt
23- include(cmake/CheckFnmatch.cmake)
24- ```
25- #]=============================================================================]
23+ set (HAVE_FNMATCH FALSE )
2624
27- include_guard (GLOBAL )
25+ # Skip in consecutive configuration phases or if overridden.
26+ if (DEFINED PHP_HAS_FNMATCH)
27+ if (PHP_HAS_FNMATCH)
28+ set (HAVE_FNMATCH TRUE )
29+ endif ()
2830
29- # Skip in consecutive configuration phases.
30- if (DEFINED HAVE_FNMATCH)
3131 return ()
3232endif ()
3333
34+ include_guard (GLOBAL )
35+
3436include (CheckSourceRuns)
37+ include (CheckSymbolExists)
3538include (CMakePushCheckState)
3639
3740message (CHECK_START "Checking for a working POSIX fnmatch() function" )
3841
39- if (
40- NOT DEFINED HAVE_FNMATCH_EXITCODE
41- AND CMAKE_CROSSCOMPILING
42- AND NOT CMAKE_CROSSCOMPILING_EMULATOR
43- AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
44- )
45- set (HAVE_FNMATCH_EXITCODE 0)
46- endif ()
47-
4842cmake_push_check_state(RESET)
4943 set (CMAKE_REQUIRED_QUIET TRUE )
5044
45+ if (
46+ CMAKE_CROSSCOMPILING
47+ AND NOT CMAKE_CROSSCOMPILING_EMULATOR
48+ AND NOT DEFINED PHP_HAS_FNMATCH_EXITCODE
49+ )
50+ check_symbol_exists(fnmatch fnmatch.h PHP_HAS_FNMATCH)
51+ endif ()
52+
5153 check_source_runs(C [[
5254 #include <fnmatch.h>
5355 #define y(a, b, c) (fnmatch (a, b, c) == 0)
@@ -64,10 +66,11 @@ cmake_push_check_state(RESET)
6466 && n ("*x", ".x", FNM_PERIOD)
6567 && 1));
6668 }
67- ]] HAVE_FNMATCH )
69+ ]] PHP_HAS_FNMATCH )
6870cmake_pop_check_state()
6971
70- if (HAVE_FNMATCH)
72+ if (PHP_HAS_FNMATCH)
73+ set (HAVE_FNMATCH TRUE )
7174 message (CHECK_PASS "yes" )
7275else ()
7376 message (CHECK_FAIL "no" )
0 commit comments