@@ -43,10 +43,8 @@ include(CheckSymbolExists)
4343include (CMakeDependentOption)
4444include (FeatureSummary)
4545include (PHP/CheckCompilerFlag)
46- include (PHP/SearchLibraries)
4746
4847option (EXT_OPCACHE "Enable the opcache extension" ON )
49-
5048add_feature_info(
5149 "ext/opcache"
5250 EXT_OPCACHE
@@ -65,21 +63,15 @@ cmake_dependent_option(
6563 EXT_OPCACHE_JIT
6664 "Enable JIT"
6765 ON
68- " EXT_OPCACHE"
66+ EXT_OPCACHE
6967 OFF
7068)
7169
72- add_feature_info(
73- "ext/opcache JIT"
74- EXT_OPCACHE_JIT
75- "Opcache's JIT (Just-In-Time compiler)"
76- )
77-
7870cmake_dependent_option(
7971 EXT_OPCACHE_CAPSTONE
8072 "Support opcache JIT disassembly through Capstone"
8173 OFF
82- " EXT_OPCACHE"
74+ EXT_OPCACHE
8375 OFF
8476)
8577
@@ -132,15 +124,6 @@ set_target_properties(
132124 PHP_ZEND_EXTENSION TRUE
133125)
134126
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-
144127target_compile_definitions (php_opcache PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
145128
146129if (EXT_OPCACHE_HUGE_CODE_PAGES)
@@ -151,142 +134,33 @@ endif()
151134# JIT.
152135################################################################################
153136
154- # Check JIT requirements.
155137if (EXT_OPCACHE_JIT)
156- if (
157- # *nix:
158- NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[34567]86.*|x86.*|amd64|aarch64.*)$"
159- # Windows:
160- AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(X86|AMD64|ARM64)$"
161- )
162- message (
163- WARNING
164- "JIT is not supported by target architecture ${CMAKE_SYSTEM_PROCESSOR} "
165- )
166- set_property (CACHE EXT_OPCACHE_JIT PROPERTY VALUE 0)
167- elseif (
168- CMAKE_SYSTEM_NAME STREQUAL "Darwin"
169- AND CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*$"
170- AND PHP_THREAD_SAFETY
171- )
172- message (
173- WARNING
174- "JIT is not supported on Apple Silicon with thread safety enabled"
175- )
176- set_property (CACHE EXT_OPCACHE_JIT PROPERTY VALUE 0)
177- endif ()
138+ add_subdirectory (jit)
178139endif ()
179140
180- 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-
210- # Find out which ABI to use.
211- if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64|ARM64)$" )
212- set (DASM_FLAGS -D X64=1)
213- set (DASM_ARCH "x86" )
214- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[34567]86.*|x86.*|X86)$" )
215- set (DASM_ARCH "x86" )
216- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*" )
217- set (DASM_FLAGS -D ARM64=1)
218- set (DASM_ARCH "arm64" )
219- endif ()
141+ add_feature_info(
142+ "ext/opcache JIT"
143+ [[HAVE_JIT]]
144+ "Opcache's JIT (Just-In-Time compiler)"
145+ )
220146
221- if (
222- CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
223- AND CMAKE_SYSTEM_NAME STREQUAL "Darwin"
224- )
225- list (APPEND DASM_FLAGS -D X64APPLE=1)
226- endif ()
147+ add_feature_info(
148+ "ext/opcache JIT Capstone"
149+ [[HAVE_CAPSTONE]]
150+ "opcache JIT disassembly supported through Capstone"
151+ )
227152
228- if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
229- list (APPEND DASM_FLAGS -D WIN=1)
230- endif ()
153+ if (HAVE_JIT)
154+ target_link_libraries (php_opcache PRIVATE php_opcache_jit)
231155
232- if (
233- CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|ARM64)$"
234- AND CMAKE_SYSTEM_NAME STREQUAL "Windows"
156+ php_check_compiler_flag(
157+ C
158+ -Wno-implicit-fallthrough
159+ _HAVE_WNO_IMPLICIT_FALLTHROUGH_C
235160 )
236- list (APPEND DASM_FLAGS -D X64WIN=1)
161+ if (_HAVE_WNO_IMPLICIT_FALLTHROUGH_C)
162+ target_compile_options (php_opcache PUBLIC -Wno-implicit-fallthrough)
237163 endif ()
238-
239- if (PHP_THREAD_SAFETY)
240- list (APPEND DASM_FLAGS -D ZTS=1)
241- endif ()
242-
243- add_executable (
244- php_opcache_jit_minilua
245- jit/dynasm/minilua.c
246- )
247- set_target_properties (
248- php_opcache_jit_minilua
249- PROPERTIES
250- OUTPUT_NAME minilua
251- )
252-
253- # Link math library as needed.
254- php_search_libraries(
255- floor
256- _HAVE_FLOOR
257- HEADERS math.h
258- LIBRARIES m
259- TARGET php_opcache_jit_minilua PRIVATE
260- )
261-
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- )
268-
269- # Generate Jit for architecture.
270- add_custom_command (
271- OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /jit/zend_jit_${DASM_ARCH} .c
272- COMMAND
273- php_opcache_jit_minilua ${CMAKE_CURRENT_LIST_DIR} /jit/dynasm/dynasm.lua
274- ${DASM_FLAGS}
275- -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
280- COMMENT "[ext/opcache] Generating ext/opcache/jit/zend_jit_${DASM_ARCH} .c"
281- )
282-
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} "
287- )
288-
289- add_dependencies (php_opcache php_opcache_jit)
290164endif ()
291165
292166################################################################################
0 commit comments