Skip to content

Commit 3212a2e

Browse files
authored
Simplify JIT configuration (#17)
- 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. - Updated comments and help texts
1 parent ddc368d commit 3212a2e

File tree

1 file changed

+72
-84
lines changed

1 file changed

+72
-84
lines changed

cmake/ext/opcache/CMakeLists.txt

Lines changed: 72 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[=============================================================================[
2-
# The opcache extension
3-
4-
Configure the `opcache` extension.
2+
# The Zend OPcache extension
53
64
This extension enables the PHP OPcode caching engine.
75
@@ -17,7 +15,7 @@ Enable the extension. This extension is always built as shared when enabled.
1715
* Default: `ON`
1816
* Values: `ON|OFF`
1917
20-
Enable copying PHP CODE pages into HUGE PAGES
18+
Enable copying PHP CODE pages into HUGE PAGES.
2119
2220
## EXT_OPCACHE_JIT
2321
@@ -31,7 +29,7 @@ Enable JIT (Just-In-Time compiler).
3129
* Default: `OFF`
3230
* Values: `ON|OFF`
3331
34-
Enable opcache JIT disassembly through Capstone.
32+
Enable OPcache JIT disassembly through Capstone engine.
3533
#]=============================================================================]
3634

3735
project(
@@ -45,8 +43,7 @@ include(FeatureSummary)
4543
include(PHP/CheckCompilerFlag)
4644
include(PHP/SearchLibraries)
4745

48-
option(EXT_OPCACHE "Enable the opcache extension" ON)
49-
46+
option(EXT_OPCACHE "Enable the Zend OPcache extension" ON)
5047
add_feature_info(
5148
"ext/opcache"
5249
EXT_OPCACHE
@@ -65,21 +62,15 @@ cmake_dependent_option(
6562
EXT_OPCACHE_JIT
6663
"Enable JIT"
6764
ON
68-
"EXT_OPCACHE"
65+
EXT_OPCACHE
6966
OFF
7067
)
7168

72-
add_feature_info(
73-
"ext/opcache JIT"
74-
EXT_OPCACHE_JIT
75-
"Opcache's JIT (Just-In-Time compiler)"
76-
)
77-
7869
cmake_dependent_option(
7970
EXT_OPCACHE_CAPSTONE
80-
"Support opcache JIT disassembly through Capstone"
71+
"Support OPcache JIT disassembly through Capstone engine"
8172
OFF
82-
"EXT_OPCACHE"
73+
EXT_OPCACHE
8374
OFF
8475
)
8576

@@ -113,13 +104,6 @@ target_sources(
113104
ZendAccelerator.c
114105
)
115106

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

125109
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
@@ -132,15 +116,6 @@ set_target_properties(
132116
PHP_ZEND_EXTENSION TRUE
133117
)
134118

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-
144119
target_compile_definitions(php_opcache PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
145120

146121
if(EXT_OPCACHE_HUGE_CODE_PAGES)
@@ -151,7 +126,7 @@ endif()
151126
# JIT.
152127
################################################################################
153128

154-
# Check JIT requirements.
129+
# Check if JIT is supported by the target architecture.
155130
if(EXT_OPCACHE_JIT)
156131
if(
157132
# *nix:
@@ -178,35 +153,6 @@ if(EXT_OPCACHE_JIT)
178153
endif()
179154

180155
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-
210156
# Find out which ABI to use.
211157
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64|ARM64)$")
212158
set(DASM_FLAGS -D X64=1)
@@ -240,14 +186,12 @@ if(EXT_OPCACHE_JIT)
240186
list(APPEND DASM_FLAGS -D ZTS=1)
241187
endif()
242188

243-
add_executable(
244-
php_opcache_jit_minilua
245-
jit/dynasm/minilua.c
246-
)
189+
# Generate zend_jit_<arch>.c file.
190+
add_executable(php_opcache_jit_minilua jit/dynasm/minilua.c)
247191
set_target_properties(
248192
php_opcache_jit_minilua
249193
PROPERTIES
250-
OUTPUT_NAME minilua
194+
RUNTIME_OUTPUT_DIRECTORY CMakeFiles
251195
)
252196

253197
# Link math library as needed.
@@ -259,36 +203,80 @@ if(EXT_OPCACHE_JIT)
259203
TARGET php_opcache_jit_minilua PRIVATE
260204
)
261205

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-
)
206+
# Help minilua create a jit build directory.
207+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/jit)
268208

269209
# Generate Jit for architecture.
270210
add_custom_command(
271-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
211+
OUTPUT jit/zend_jit_${DASM_ARCH}.c
272212
COMMAND
273-
php_opcache_jit_minilua ${CMAKE_CURRENT_LIST_DIR}/jit/dynasm/dynasm.lua
213+
php_opcache_jit_minilua ${CMAKE_CURRENT_SOURCE_DIR}/jit/dynasm/dynasm.lua
274214
${DASM_FLAGS}
275215
-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
216+
${CMAKE_CURRENT_SOURCE_DIR}/jit/zend_jit_${DASM_ARCH}.dasc
280217
COMMENT "[ext/opcache] Generating ext/opcache/jit/zend_jit_${DASM_ARCH}.c"
218+
VERBATIM
219+
COMMAND_EXPAND_LISTS
220+
)
221+
222+
target_sources(
223+
php_opcache
224+
PRIVATE
225+
$<$<NOT:$<PLATFORM_ID:Windows>>:jit/zend_jit_gdb.c>
226+
jit/zend_jit_vm_helpers.c
227+
jit/zend_jit.c
228+
${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
281229
)
282230

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}"
231+
# Mark generated file as "header" to not get compiled into its own object.
232+
set_source_files_properties(
233+
${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
234+
PROPERTIES HEADER_FILE_ONLY ON
287235
)
288236

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

268+
add_feature_info(
269+
"ext/opcache JIT"
270+
HAVE_JIT
271+
"OPcache JIT (Just-In-Time compiler)"
272+
)
273+
274+
add_feature_info(
275+
"ext/opcache JIT Capstone"
276+
HAVE_CAPSTONE
277+
"OPcache JIT disassembly supported through Capstone engine"
278+
)
279+
292280
################################################################################
293281
# Configuration checks.
294282
################################################################################

0 commit comments

Comments
 (0)