11#[=============================================================================[
2- # The opcache extension
3-
4- Configure the `opcache` extension.
2+ # The Zend OPcache extension
53
64This 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
3735project (
@@ -44,8 +42,7 @@ include(CMakeDependentOption)
4442include (FeatureSummary)
4543include (PHP/SearchLibraries)
4644
47- option (EXT_OPCACHE "Enable the opcache extension" ON )
48-
45+ option (EXT_OPCACHE "Enable the Zend OPcache extension" ON )
4946add_feature_info(
5047 "ext/opcache"
5148 EXT_OPCACHE
@@ -64,21 +61,15 @@ cmake_dependent_option(
6461 EXT_OPCACHE_JIT
6562 "Enable JIT"
6663 ON
67- " EXT_OPCACHE"
64+ EXT_OPCACHE
6865 OFF
6966)
7067
71- add_feature_info(
72- "ext/opcache JIT"
73- EXT_OPCACHE_JIT
74- "Opcache's JIT (Just-In-Time compiler)"
75- )
76-
7768cmake_dependent_option(
7869 EXT_OPCACHE_CAPSTONE
79- "Support opcache JIT disassembly through Capstone"
70+ "Support OPcache JIT disassembly through Capstone engine "
8071 OFF
81- " EXT_OPCACHE"
72+ EXT_OPCACHE
8273 OFF
8374)
8475
@@ -112,13 +103,6 @@ target_sources(
112103 ZendAccelerator.c
113104)
114105
115- target_include_directories (
116- php_opcache
117- PRIVATE
118- ${CMAKE_CURRENT_SOURCE_DIR} /jit
119- ${CMAKE_CURRENT_BINARY_DIR} /jit
120- )
121-
122106add_dependencies (php_opcache php_date php_pcre)
123107
124108if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
@@ -141,7 +125,7 @@ endif()
141125# JIT.
142126################################################################################
143127
144- # Check JIT requirements .
128+ # Check if JIT is supported by the target architecture .
145129if (EXT_OPCACHE_JIT)
146130 if (
147131 # *nix:
@@ -168,50 +152,6 @@ if(EXT_OPCACHE_JIT)
168152endif ()
169153
170154if (EXT_OPCACHE_JIT)
171- set (HAVE_JIT 1)
172-
173- target_sources (
174- php_opcache
175- PRIVATE
176- jit/ir/ir_cfg.c
177- jit/ir/ir_check.c
178- jit/ir/ir_dump.c
179- jit/ir/ir_emit.c
180- jit/ir/ir_gcm.c
181- $<$<NOT :$<PLATFORM_ID:Windows>>:jit/ir/ir_gdb.c>
182- jit/ir/ir_patch.c
183- $<$<NOT :$<PLATFORM_ID:Windows>>:jit/ir/ir_perf.c>
184- jit/ir/ir_ra.c
185- jit/ir/ir_save.c
186- jit/ir/ir_sccp.c
187- jit/ir/ir_strtab.c
188- jit/ir/ir.c
189- jit/zend_jit_vm_helpers.c
190- jit/zend_jit.c
191- )
192-
193- target_include_directories (
194- php_opcache
195- PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /jit/ir
196- )
197-
198- # Check for Capstone.
199- if (EXT_OPCACHE_CAPSTONE)
200- find_package (Capstone 3.0.0)
201- set_package_properties(
202- Capstone
203- PROPERTIES
204- TYPE REQUIRED
205- PURPOSE "Necessary to enable OPcache JIT disassembly through Capstone."
206- )
207-
208- target_sources (php_opcache PRIVATE jit/ir/ir_disasm.c)
209-
210- target_link_libraries (php_opcache PRIVATE Capstone::Capstone)
211-
212- set (HAVE_CAPSTONE 1)
213- endif ()
214-
215155 # Find out which ABI to use.
216156 if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64|ARM64)$" )
217157 set (IR_TARGET "IR_TARGET_X64" )
@@ -243,23 +183,12 @@ if(EXT_OPCACHE_JIT)
243183 list (APPEND DASM_FLAGS -D X64WIN=1)
244184 endif ()
245185
246- target_compile_definitions (
247- php_opcache
248- PRIVATE
249- IR_PHP
250- ${IR_TARGET}
251- $<$<CONFIG:Debug,DebugAssertions>:IR_DEBUG>
252- )
253-
254- add_executable (
255- php_opcache_jit_minilua
256- jit/ir/dynasm/minilua.c
257- )
186+ # Generate ir_emit_<arch>.h file.
187+ add_executable (php_opcache_jit_minilua jit/ir/dynasm/minilua.c)
258188 set_target_properties (
259189 php_opcache_jit_minilua
260190 PROPERTIES
261- OUTPUT_NAME minilua
262- RUNTIME_OUTPUT_DIRECTORY jit/ir
191+ RUNTIME_OUTPUT_DIRECTORY CMakeFiles
263192 )
264193
265194 # Link math library as needed.
@@ -271,18 +200,27 @@ if(EXT_OPCACHE_JIT)
271200 TARGET php_opcache_jit_minilua PRIVATE
272201 )
273202
274- # Create jit directory in the current build directory if it doesn't exist yet.
203+ # Help generators create a jit/ir build directory.
204+ file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /jit/ir)
205+
206+ # Generate native code generator for selected architecture.
275207 add_custom_command (
276- OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /jit
277- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /jit
278- COMMENT "[ext/opcache] Creating ext/opcache/jit directory"
208+ OUTPUT jit/ir/ir_emit_${DASM_ARCH} .h
209+ COMMAND
210+ php_opcache_jit_minilua ${CMAKE_CURRENT_SOURCE_DIR} /jit/ir/dynasm/dynasm.lua
211+ ${DASM_FLAGS}
212+ -o ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_emit_${DASM_ARCH} .h
213+ ${CMAKE_CURRENT_SOURCE_DIR} /jit/ir/ir_${DASM_ARCH} .dasc
214+ COMMENT "[ext/opcache] Generating native code generator ext/opcache/jit/ir/ir_emit_${DASM_ARCH} .h"
215+ DEPENDS
216+ jit/ir/dynasm/dynasm.lua
217+ jit/ir/ir_${DASM_ARCH} .dasc
218+ VERBATIM
219+ COMMAND_EXPAND_LISTS
279220 )
280221
281222 # Create IR folding engine generator.
282- add_executable (
283- php_opcache_jit_generator
284- jit/ir/gen_ir_fold_hash.c
285- )
223+ add_executable (php_opcache_jit_generator jit/ir/gen_ir_fold_hash.c)
286224 target_compile_definitions (
287225 php_opcache_jit_generator
288226 PRIVATE
@@ -293,45 +231,90 @@ if(EXT_OPCACHE_JIT)
293231 set_target_properties (
294232 php_opcache_jit_generator
295233 PROPERTIES
296- OUTPUT_NAME gen_ir_fold_hash
297- RUNTIME_OUTPUT_DIRECTORY jit/ir
234+ RUNTIME_OUTPUT_DIRECTORY CMakeFiles
298235 )
299236
300237 # Generate IR folding engine rules header.
301238 add_custom_command (
302- OUTPUT ${CMAKE_CURRENT_BINARY_DIR} / jit/ir/ir_fold_hash.h
239+ OUTPUT jit/ir/ir_fold_hash.h
303240 COMMAND php_opcache_jit_generator
304241 < ${CMAKE_CURRENT_SOURCE_DIR} /jit/ir/ir_fold.h
305242 > ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_fold_hash.h
306- DEPENDS php_opcache_jit_generator ${CMAKE_CURRENT_BINARY_DIR} /jit
307243 COMMENT "[ext/opcache] Generating folding engine rules ext/opcache/jit/ir/ir_fold_hash.h"
308- )
309-
310- # Generate native code generator for selected architecture.
311- add_custom_command (
312- OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_emit_${DASM_ARCH} .h
313- COMMAND
314- php_opcache_jit_minilua ${CMAKE_CURRENT_SOURCE_DIR} /jit/ir/dynasm/dynasm.lua
315- ${DASM_FLAGS}
316- -o ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_emit_${DASM_ARCH} .h
317- ${CMAKE_CURRENT_SOURCE_DIR} /jit/ir/ir_${DASM_ARCH} .dasc
318244 DEPENDS
319- php_opcache_jit_minilua
320- ${CMAKE_CURRENT_BINARY_DIR} /jit
321- COMMENT "[ext/opcache] Generating native code generator ext/opcache/jit/ir/ir_emit_ ${DASM_ARCH} .h"
245+ jit/ir/ir_fold.h
246+ VERBATIM
247+ COMMAND_EXPAND_LISTS
322248 )
323249
324- add_custom_target (
325- php_opcache_jit
326- DEPENDS
250+ target_sources (
251+ php_opcache
252+ PRIVATE
253+ jit/ir/ir_cfg.c
254+ jit/ir/ir_check.c
255+ jit/ir/ir_dump.c
256+ jit/ir/ir_emit.c
257+ jit/ir/ir_gcm.c
258+ $<$<NOT :$<PLATFORM_ID:Windows>>:jit/ir/ir_gdb.c>
259+ jit/ir/ir_patch.c
260+ $<$<NOT :$<PLATFORM_ID:Windows>>:jit/ir/ir_perf.c>
261+ jit/ir/ir_ra.c
262+ jit/ir/ir_save.c
263+ jit/ir/ir_sccp.c
264+ jit/ir/ir_strtab.c
265+ jit/ir/ir.c
266+ jit/zend_jit_vm_helpers.c
267+ jit/zend_jit.c
327268 ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_emit_${DASM_ARCH} .h
328269 ${CMAKE_CURRENT_BINARY_DIR} /jit/ir/ir_fold_hash.h
329- COMMENT "[ext/opcache] Building JIT for architecture ${DASM_ARCH} "
330270 )
331271
332- add_dependencies (php_opcache php_opcache_jit)
272+ target_include_directories (
273+ php_opcache
274+ PRIVATE
275+ ${CMAKE_CURRENT_BINARY_DIR} /jit/ir
276+ )
277+
278+ target_compile_definitions (
279+ php_opcache
280+ PRIVATE
281+ IR_PHP
282+ ${IR_TARGET}
283+ $<$<CONFIG:Debug,DebugAssertions>:IR_DEBUG>
284+ )
285+
286+ # Check for Capstone.
287+ if (EXT_OPCACHE_CAPSTONE)
288+ find_package (Capstone 3.0.0)
289+ set_package_properties(
290+ Capstone
291+ PROPERTIES
292+ TYPE REQUIRED
293+ PURPOSE "Necessary to enable OPcache JIT disassembly through Capstone."
294+ )
295+
296+ target_sources (php_opcache PRIVATE jit/ir/ir_disasm.c)
297+
298+ target_link_libraries (php_opcache PRIVATE Capstone::Capstone)
299+
300+ set (HAVE_CAPSTONE 1)
301+ endif ()
302+
303+ set (HAVE_JIT 1)
333304endif ()
334305
306+ add_feature_info(
307+ "ext/opcache JIT"
308+ HAVE_JIT
309+ "OPcache JIT (Just-In-Time compiler)"
310+ )
311+
312+ add_feature_info(
313+ "ext/opcache JIT Capstone"
314+ HAVE_CAPSTONE
315+ "OPcache JIT disassembly supported through Capstone engine"
316+ )
317+
335318################################################################################
336319# Configuration checks.
337320################################################################################
0 commit comments