@@ -32,7 +32,9 @@ project(
3232 LANGUAGES C
3333)
3434
35+ include (CheckIncludeFile)
3536include (CheckSourceCompiles)
37+ include (CheckSymbolExists)
3638include (CMakeDependentOption)
3739include (CMakePushCheckState)
3840include (FeatureSummary)
@@ -71,12 +73,41 @@ if(NOT EXT_MBSTRING)
7173 return ()
7274endif ()
7375
76+ ################################################################################
77+ # Configure mbstring extension.
78+ ################################################################################
79+
7480if (EXT_MBSTRING_SHARED)
7581 add_library (php_mbstring SHARED)
7682else ()
7783 add_library (php_mbstring)
7884endif ()
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+
80111target_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
151197cmake_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
173219if (EXT_MBSTRING_MBREGEX)
174220 find_package (Oniguruma)
@@ -230,21 +276,6 @@ if(EXT_MBSTRING_MBREGEX)
230276 )
231277endif ()
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-
248279set (HAVE_MBSTRING TRUE )
249280
250281configure_file (cmake/config.h.in config.h)
0 commit comments