Skip to content

Commit 3f710ba

Browse files
committed
Group libmbfl configuration
1 parent 6d506b6 commit 3f710ba

File tree

3 files changed

+76
-35
lines changed

3 files changed

+76
-35
lines changed

cmake/cmake/platforms/Windows.cmake

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,28 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2323
# these are always known on Windows systems.
2424
# TODO: Update and fix this better.
2525

26-
# PHP has custom syslog.h for Windows platform.
27-
set(HAVE_SYSLOG_H TRUE)
26+
set(HAVE_FNMATCH TRUE)
2827

29-
# PHP has custom usleep for Windows platform.
30-
set(HAVE_USLEEP TRUE)
28+
# PHP has unconditional getaddrinfo() support on Windows for now.
29+
set(HAVE_GETADDRINFO TRUE)
30+
31+
# PHP defines getpid as _getpid on Windows.
32+
set(HAVE_GETPID TRUE)
3133

3234
# PHP has custom nanosleep for Windows platform.
3335
set(HAVE_NANOSLEEP TRUE)
3436

35-
# PHP supports socketpair by the emulation in win32/sockets.c
37+
set(HAVE_NICE TRUE)
38+
39+
# PHP supports socketpair by the emulation in win32/sockets.c.
3640
set(HAVE_SOCKETPAIR TRUE)
3741

38-
# PHP has unconditional getaddrinfo() support on Windows for now.
39-
set(HAVE_GETADDRINFO TRUE)
42+
# PHP defines strcasecmp in zend_config.w32.h.
43+
set(HAVE_STRCASECMP TRUE)
4044

41-
set(HAVE_NICE TRUE)
42-
set(HAVE_FNMATCH TRUE)
45+
# PHP has custom syslog.h for Windows platform.
46+
set(HAVE_SYSLOG_H TRUE)
4347

44-
# PHP defines getpid as _getpid on Windows.
45-
set(HAVE_GETPID TRUE)
48+
# PHP has custom usleep for Windows platform.
49+
set(HAVE_USLEEP TRUE)
4650
endif()

cmake/ext/mbstring/CMakeLists.txt

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ project(
3232
LANGUAGES C
3333
)
3434

35+
include(CheckIncludeFile)
3536
include(CheckSourceCompiles)
37+
include(CheckSymbolExists)
3638
include(CMakeDependentOption)
3739
include(CMakePushCheckState)
3840
include(FeatureSummary)
@@ -71,12 +73,41 @@ if(NOT EXT_MBSTRING)
7173
return()
7274
endif()
7375

76+
################################################################################
77+
# Configure mbstring extension.
78+
################################################################################
79+
7480
if(EXT_MBSTRING_SHARED)
7581
add_library(php_mbstring SHARED)
7682
else()
7783
add_library(php_mbstring)
7884
endif()
7985

86+
target_sources(
87+
php_mbstring
88+
PRIVATE
89+
mb_gpc.c
90+
mbstring.c
91+
mbstring.stub.php
92+
php_unicode.c
93+
PUBLIC
94+
FILE_SET HEADERS
95+
FILES
96+
mbstring.h
97+
)
98+
99+
target_compile_definitions(php_mbstring PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
100+
101+
# The mbstring extension doesn't seem to support interprocedural optimization
102+
# (IPO).
103+
set_target_properties(php_mbstring PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
104+
105+
add_dependencies(php_mbstring php_pcre)
106+
107+
################################################################################
108+
# Configure libmbfl.
109+
################################################################################
110+
80111
target_sources(
81112
php_mbstring
82113
PRIVATE
@@ -117,10 +148,6 @@ target_sources(
117148
libmbfl/nls/nls_ua.c
118149
libmbfl/nls/nls_uni.c
119150
libmbfl/nls/nls_zh.c
120-
mb_gpc.c
121-
mbstring.c
122-
mbstring.stub.php
123-
php_unicode.c
124151
PUBLIC
125152
FILE_SET HEADERS
126153
FILES
@@ -137,7 +164,6 @@ target_sources(
137164
libmbfl/mbfl/mbfl_language.h
138165
libmbfl/mbfl/mbfl_memory_device.h
139166
libmbfl/mbfl/mbfl_string.h
140-
mbstring.h
141167
# A separate file set so binary dir can also be created within a source dir.
142168
PUBLIC
143169
FILE_SET HEADERS
@@ -146,7 +172,27 @@ target_sources(
146172
${CMAKE_CURRENT_BINARY_DIR}/libmbfl/config.h
147173
)
148174

149-
add_dependencies(php_mbstring php_pcre)
175+
target_include_directories(
176+
php_mbstring
177+
PRIVATE
178+
${CMAKE_CURRENT_BINARY_DIR}/libmbfl
179+
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl
180+
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl/mbfl
181+
)
182+
183+
target_compile_definitions(
184+
php_mbstring
185+
PRIVATE
186+
$<$<AND:$<PLATFORM_ID:Windows>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>>:MBFL_DLL_EXPORT>
187+
)
188+
189+
# There are duplicate strings.h and strcasecmp checks for the time being.
190+
# See: https://github.com/php/php-src/pull/13713
191+
# Once upstream is refactored, global strings.h and strcasecmp checks with
192+
# Windows unconditional definition can be removed in favor of these checks only
193+
# or done differently.
194+
check_include_file(strings.h HAVE_STRINGS_H)
195+
check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP)
150196

151197
cmake_path(
152198
RELATIVE_PATH CMAKE_CURRENT_BINARY_DIR
@@ -166,9 +212,9 @@ file(CONFIGURE OUTPUT libmbfl/config.h CONTENT [[
166212
#endif
167213
]])
168214

169-
# The mbstring extension doesn't seem to support interprocedural optimization
170-
# (IPO).
171-
set_target_properties(php_mbstring PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
215+
################################################################################
216+
# MB regex.
217+
################################################################################
172218

173219
if(EXT_MBSTRING_MBREGEX)
174220
find_package(Oniguruma)
@@ -230,21 +276,6 @@ if(EXT_MBSTRING_MBREGEX)
230276
)
231277
endif()
232278

233-
target_compile_definitions(
234-
php_mbstring
235-
PRIVATE
236-
$<$<AND:$<PLATFORM_ID:Windows>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>>:MBFL_DLL_EXPORT>
237-
ZEND_ENABLE_STATIC_TSRMLS_CACHE
238-
)
239-
240-
target_include_directories(
241-
php_mbstring
242-
PRIVATE
243-
${CMAKE_CURRENT_BINARY_DIR}/libmbfl
244-
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl
245-
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl/mbfl
246-
)
247-
248279
set(HAVE_MBSTRING TRUE)
249280

250281
configure_file(cmake/config.h.in config.h)

cmake/ext/mbstring/cmake/config.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
/* Define to 1 if the PHP extension 'mbstring' is available. */
55
#cmakedefine HAVE_MBSTRING 1
66

7+
/* Define to 1 if you have the 'strcasecmp' function. */
8+
#cmakedefine HAVE_STRCASECMP 1
9+
10+
/* Define to 1 if you have the <strings.h> header file. */
11+
#cmakedefine HAVE_STRINGS_H 1
12+
713
/* Define to 1 if Oniguruma has an invalid entry for KOI8 encoding. */
814
#cmakedefine PHP_ONIG_BAD_KOI8_ENTRY 1

0 commit comments

Comments
 (0)