Skip to content

Commit 7502fad

Browse files
committed
Simplify opcache JIT configuration
- Instead of adding custom targets source file can be indicator to run the custom command. - Some redundant compile properties removed, and some adjusted. - CMakeFiles can also serve to store temporary minilua generator to not pollute the binary directory and using Gitignore for that.
1 parent ddc368d commit 7502fad

File tree

1 file changed

+66
-76
lines changed

1 file changed

+66
-76
lines changed

cmake/ext/opcache/CMakeLists.txt

Lines changed: 66 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ include(PHP/CheckCompilerFlag)
4646
include(PHP/SearchLibraries)
4747

4848
option(EXT_OPCACHE "Enable the opcache extension" ON)
49-
5049
add_feature_info(
5150
"ext/opcache"
5251
EXT_OPCACHE
@@ -65,16 +64,10 @@ cmake_dependent_option(
6564
EXT_OPCACHE_JIT
6665
"Enable JIT"
6766
ON
68-
"EXT_OPCACHE"
67+
EXT_OPCACHE
6968
OFF
7069
)
7170

72-
add_feature_info(
73-
"ext/opcache JIT"
74-
EXT_OPCACHE_JIT
75-
"Opcache's JIT (Just-In-Time compiler)"
76-
)
77-
7871
cmake_dependent_option(
7972
EXT_OPCACHE_CAPSTONE
8073
"Support opcache JIT disassembly through Capstone"
@@ -113,13 +106,6 @@ target_sources(
113106
ZendAccelerator.c
114107
)
115108

116-
target_include_directories(
117-
php_opcache
118-
PRIVATE
119-
${CMAKE_CURRENT_SOURCE_DIR}/jit
120-
${CMAKE_CURRENT_BINARY_DIR}/jit
121-
)
122-
123109
add_dependencies(php_opcache php_date php_pcre)
124110

125111
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
@@ -132,15 +118,6 @@ set_target_properties(
132118
PHP_ZEND_EXTENSION TRUE
133119
)
134120

135-
php_check_compiler_flag(
136-
C
137-
-Wno-implicit-fallthrough
138-
_HAVE_WNO_IMPLICIT_FALLTHROUGH_C
139-
)
140-
if(_HAVE_WNO_IMPLICIT_FALLTHROUGH_C)
141-
target_compile_options(php_opcache PRIVATE -Wno-implicit-fallthrough)
142-
endif()
143-
144121
target_compile_definitions(php_opcache PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
145122

146123
if(EXT_OPCACHE_HUGE_CODE_PAGES)
@@ -151,7 +128,7 @@ endif()
151128
# JIT.
152129
################################################################################
153130

154-
# Check JIT requirements.
131+
# Check if JIT is supported by the target architecture.
155132
if(EXT_OPCACHE_JIT)
156133
if(
157134
# *nix:
@@ -178,35 +155,6 @@ if(EXT_OPCACHE_JIT)
178155
endif()
179156

180157
if(EXT_OPCACHE_JIT)
181-
set(HAVE_JIT 1)
182-
183-
target_sources(
184-
php_opcache
185-
PRIVATE
186-
$<$<NOT:$<PLATFORM_ID:Windows>>:jit/zend_jit_gdb.c>
187-
jit/zend_jit_vm_helpers.c
188-
jit/zend_jit.c
189-
)
190-
191-
# The string.h header is always available with C89 standard. The bundled
192-
# ext/opcache/jit/libudis86 still includes it conditionally.
193-
target_compile_definitions(php_opcache PRIVATE HAVE_STRING_H=1)
194-
195-
# Check for Capstone.
196-
if(EXT_OPCACHE_CAPSTONE)
197-
find_package(Capstone 3.0.0)
198-
set_package_properties(
199-
Capstone
200-
PROPERTIES
201-
TYPE REQUIRED
202-
PURPOSE "Necessary to enable OPcache JIT disassembly through Capstone."
203-
)
204-
205-
target_link_libraries(php_opcache PRIVATE Capstone::Capstone)
206-
207-
set(HAVE_CAPSTONE 1)
208-
endif()
209-
210158
# Find out which ABI to use.
211159
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64|ARM64)$")
212160
set(DASM_FLAGS -D X64=1)
@@ -240,14 +188,12 @@ if(EXT_OPCACHE_JIT)
240188
list(APPEND DASM_FLAGS -D ZTS=1)
241189
endif()
242190

243-
add_executable(
244-
php_opcache_jit_minilua
245-
jit/dynasm/minilua.c
246-
)
191+
# Generate zend_jit_<arch>.c file.
192+
add_executable(php_opcache_jit_minilua jit/dynasm/minilua.c)
247193
set_target_properties(
248194
php_opcache_jit_minilua
249195
PROPERTIES
250-
OUTPUT_NAME minilua
196+
RUNTIME_OUTPUT_DIRECTORY CMakeFiles
251197
)
252198

253199
# Link math library as needed.
@@ -259,36 +205,80 @@ if(EXT_OPCACHE_JIT)
259205
TARGET php_opcache_jit_minilua PRIVATE
260206
)
261207

262-
# Create jit directory in the current build directory if it doesn't exist yet.
263-
add_custom_command(
264-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jit
265-
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/jit
266-
COMMENT "[ext/opcache] Creating ext/opcache/jit directory"
267-
)
208+
# Help minilua create a jit build directory.
209+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/jit)
268210

269211
# Generate Jit for architecture.
270212
add_custom_command(
271-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
213+
OUTPUT jit/zend_jit_${DASM_ARCH}.c
272214
COMMAND
273-
php_opcache_jit_minilua ${CMAKE_CURRENT_LIST_DIR}/jit/dynasm/dynasm.lua
215+
php_opcache_jit_minilua ${CMAKE_CURRENT_SOURCE_DIR}/jit/dynasm/dynasm.lua
274216
${DASM_FLAGS}
275217
-o ${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
276-
${CMAKE_CURRENT_LIST_DIR}/jit/zend_jit_${DASM_ARCH}.dasc
277-
DEPENDS
278-
php_opcache_jit_minilua
279-
${CMAKE_CURRENT_BINARY_DIR}/jit
218+
${CMAKE_CURRENT_SOURCE_DIR}/jit/zend_jit_${DASM_ARCH}.dasc
280219
COMMENT "[ext/opcache] Generating ext/opcache/jit/zend_jit_${DASM_ARCH}.c"
220+
VERBATIM
221+
COMMAND_EXPAND_LISTS
222+
)
223+
224+
target_sources(
225+
php_opcache
226+
PRIVATE
227+
$<$<NOT:$<PLATFORM_ID:Windows>>:jit/zend_jit_gdb.c>
228+
jit/zend_jit_vm_helpers.c
229+
jit/zend_jit.c
230+
${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
281231
)
282232

283-
add_custom_target(
284-
php_opcache_jit
285-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
286-
COMMENT "[ext/opcache] Building JIT for architecture ${DASM_ARCH}"
233+
# Mark generated file as "header" to not get compiled into object at this level.
234+
set_source_files_properties(
235+
${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
236+
PROPERTIES HEADER_FILE_ONLY ON
287237
)
288238

289-
add_dependencies(php_opcache php_opcache_jit)
239+
# The string.h header is always available with C89 standard. The bundled
240+
# ext/opcache/jit/libudis86 still includes it conditionally.
241+
target_compile_definitions(php_opcache PRIVATE HAVE_STRING_H=1)
242+
243+
php_check_compiler_flag(
244+
C
245+
-Wno-implicit-fallthrough
246+
_HAVE_WNO_IMPLICIT_FALLTHROUGH_C
247+
)
248+
if(_HAVE_WNO_IMPLICIT_FALLTHROUGH_C)
249+
target_compile_options(php_opcache PRIVATE -Wno-implicit-fallthrough)
250+
endif()
251+
252+
# Check for Capstone.
253+
if(EXT_OPCACHE_CAPSTONE)
254+
find_package(Capstone 3.0.0)
255+
set_package_properties(
256+
Capstone
257+
PROPERTIES
258+
TYPE REQUIRED
259+
PURPOSE "Necessary to enable OPcache JIT disassembly through Capstone."
260+
)
261+
262+
target_link_libraries(php_opcache PRIVATE Capstone::Capstone)
263+
264+
set(HAVE_CAPSTONE 1)
265+
endif()
266+
267+
set(HAVE_JIT 1)
290268
endif()
291269

270+
add_feature_info(
271+
"ext/opcache JIT"
272+
HAVE_JIT
273+
"Opcache's JIT (Just-In-Time compiler)"
274+
)
275+
276+
add_feature_info(
277+
"ext/opcache JIT Capstone"
278+
HAVE_CAPSTONE
279+
"opcache JIT disassembly supported through Capstone"
280+
)
281+
292282
################################################################################
293283
# Configuration checks.
294284
################################################################################

0 commit comments

Comments
 (0)