Skip to content

Commit 626e3d1

Browse files
committed
Refactor nits
- php_version.h created directly instead of via deferred call - php_version.h template moved to CMakeLists.txt - ext/mbstring refactored a bit
1 parent 5052856 commit 626e3d1

File tree

3 files changed

+58
-38
lines changed

3 files changed

+58
-38
lines changed

cmake/ext/mbstring/CMakeLists.txt

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ if(NOT EXT_MBSTRING)
7171
return()
7272
endif()
7373

74+
################################################################################
75+
# Configure mbstring extension.
76+
################################################################################
77+
7478
if(EXT_MBSTRING_SHARED)
7579
add_library(php_mbstring SHARED)
7680
else()
@@ -146,8 +150,20 @@ target_sources(
146150
${CMAKE_CURRENT_BINARY_DIR}/libmbfl/config.h
147151
)
148152

153+
target_compile_definitions(php_mbstring PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
154+
155+
# The mbstring extension doesn't seem to support interprocedural optimization
156+
# (IPO).
157+
set_target_properties(php_mbstring PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
158+
149159
add_dependencies(php_mbstring php_pcre)
150160

161+
set(HAVE_MBSTRING TRUE)
162+
163+
################################################################################
164+
# Configure libmbfl.
165+
################################################################################
166+
151167
# TODO: Fix this better. See also https://github.com/php/php-src/pull/13713
152168
# TODO: Should status message be here?
153169
message(STATUS "Creating ext/mbstring/libmbfl/config.h")
@@ -161,9 +177,17 @@ file(CONFIGURE OUTPUT libmbfl/config.h CONTENT [[
161177
#endif
162178
]])
163179

164-
# The mbstring extension doesn't seem to support interprocedural optimization
165-
# (IPO).
166-
set_target_properties(php_mbstring PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
180+
target_include_directories(
181+
php_mbstring
182+
PRIVATE
183+
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl
184+
${CMAKE_CURRENT_BINARY_DIR}/libmbfl
185+
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl/mbfl
186+
)
187+
188+
################################################################################
189+
# Multibyte regex.
190+
################################################################################
167191

168192
if(EXT_MBSTRING_MBREGEX)
169193
find_package(Oniguruma)
@@ -177,7 +201,7 @@ if(EXT_MBSTRING_MBREGEX)
177201
target_link_libraries(php_mbstring PRIVATE Oniguruma::Oniguruma)
178202

179203
if(TARGET Oniguruma::Oniguruma)
180-
message(CHECK_START "Checking if Oniguruma has invalid entry for KOI8 encoding")
204+
message(CHECK_START "Checking for invalid KOI8 encoding entry in Oniguruma")
181205
cmake_push_check_state(RESET)
182206
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
183207
set(CMAKE_REQUIRED_LIBRARIES Oniguruma::Oniguruma)
@@ -196,7 +220,6 @@ if(EXT_MBSTRING_MBREGEX)
196220
message(CHECK_PASS "no")
197221
else()
198222
message(CHECK_FAIL "yes")
199-
200223
set(PHP_ONIG_BAD_KOI8_ENTRY TRUE)
201224
endif()
202225
endif()
@@ -211,8 +234,6 @@ if(EXT_MBSTRING_MBREGEX)
211234
$<$<PLATFORM_ID:Windows>:ONIG_EXTERN=extern>
212235
)
213236

214-
set(HAVE_MBREGEX TRUE)
215-
216237
target_sources(
217238
php_mbstring
218239
PRIVATE
@@ -223,18 +244,8 @@ if(EXT_MBSTRING_MBREGEX)
223244
php_mbregex.h
224245
php_onig_compat.h
225246
)
226-
endif()
227-
228-
target_compile_definitions(php_mbstring PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
229247

230-
target_include_directories(
231-
php_mbstring
232-
PRIVATE
233-
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl
234-
${CMAKE_CURRENT_BINARY_DIR}/libmbfl
235-
${CMAKE_CURRENT_SOURCE_DIR}/libmbfl/mbfl
236-
)
237-
238-
set(HAVE_MBSTRING TRUE)
248+
set(HAVE_MBREGEX TRUE)
249+
endif()
239250

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

cmake/main/CMakeLists.txt

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ if(PHP_DMALLOC)
271271
endif()
272272
endif()
273273

274+
################################################################################
275+
# Create main/php_version.h. Template is based on the configure.ac.
276+
################################################################################
277+
278+
cmake_path(
279+
RELATIVE_PATH
280+
CMAKE_CURRENT_SOURCE_DIR
281+
BASE_DIRECTORY ${CMAKE_SOURCE_DIR}
282+
OUTPUT_VARIABLE relativeSourceDir
283+
)
284+
285+
message(STATUS "Creating ${relativeSourceDir}/php_version.h")
286+
file(CONFIGURE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/php_version.h CONTENT [[
287+
/* automatically generated by configure */
288+
/* edit configure.ac to change version number */
289+
#define PHP_MAJOR_VERSION @PHP_VERSION_MAJOR@
290+
#define PHP_MINOR_VERSION @PHP_VERSION_MINOR@
291+
#define PHP_RELEASE_VERSION @PHP_VERSION_PATCH@
292+
#define PHP_EXTRA_VERSION "@PHP_VERSION_LABEL@"
293+
#define PHP_VERSION "@PHP_VERSION@"
294+
#define PHP_VERSION_ID @PHP_VERSION_ID@
295+
]])
296+
274297
################################################################################
275298
# Create main/internal_functions*.c files with a list of static enabled PHP
276299
# extensions based on the PHP SAPI type.
@@ -319,17 +342,17 @@ block()
319342
RELATIVE_PATH
320343
CMAKE_CURRENT_BINARY_DIR
321344
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
322-
OUTPUT_VARIABLE relativeDir
345+
OUTPUT_VARIABLE relativeBinaryDir
323346
)
324347

325348
set(EXT_INCLUDE_CODE "${includes}")
326349
set(EXT_MODULE_PTRS "${pointers}")
327-
message(STATUS "Creating ${relativeDir}/internal_functions.c")
350+
message(STATUS "Creating ${relativeBinaryDir}/internal_functions.c")
328351
configure_file(internal_functions.c.in internal_functions.c)
329352

330353
set(EXT_INCLUDE_CODE "${includesCli}")
331354
set(EXT_MODULE_PTRS "${pointersCli}")
332-
message(STATUS "Creating ${relativeDir}/internal_functions_cli.c")
355+
message(STATUS "Creating ${relativeBinaryDir}/internal_functions_cli.c")
333356
configure_file(internal_functions.c.in internal_functions_cli.c)
334357
endblock()
335358

@@ -420,12 +443,6 @@ function(_php_main_create_files)
420443
set(DEFAULT_SHORT_OPEN_TAG "0")
421444
endif()
422445

423-
message(STATUS "Creating main/php_version.h")
424-
configure_file(
425-
main/cmake/php_version.h.in
426-
${PHP_SOURCE_DIR}/main/php_version.h
427-
)
428-
429446
# Add sapis configuration.
430447
set(config "")
431448
get_property(sapis GLOBAL PROPERTY PHP_SAPIS)
@@ -475,7 +492,7 @@ function(_php_main_create_files)
475492
GENERATE
476493
# TODO: Multi-config generators need to write separate files.
477494
#OUTPUT $<CONFIG>/main/build-defs.h
478-
OUTPUT ${PHP_BINARY_DIR}/main/build-defs.h
495+
OUTPUT main/build-defs.h
479496
CONTENT "${content}"
480497
)
481498

@@ -526,7 +543,7 @@ function(_php_main_create_files)
526543
GENERATE
527544
# TODO: Multi-config generators need to write separate files.
528545
#OUTPUT $<CONFIG>/main/${file}
529-
OUTPUT ${PHP_BINARY_DIR}/main/${file}
546+
OUTPUT main/${file}
530547
CONTENT "${content}"
531548
)
532549
endfunction()

cmake/main/cmake/php_version.h.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)