Skip to content

Commit 36eb009

Browse files
committed
Simplify Zend language parser patching
1 parent 68f50a8 commit 36eb009

File tree

1 file changed

+27
-40
lines changed

1 file changed

+27
-40
lines changed

cmake/Zend/cmake/GenerateGrammar.cmake

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,34 @@ php_bison(
3737
# See: https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md
3838
block()
3939
string(
40-
CONCAT patch
41-
"cmake_path(SET SOURCE_DIR NORMALIZE ${CMAKE_CURRENT_SOURCE_DIR})\n"
40+
CONFIGURE
4241
[[
43-
cmake_path(
44-
RELATIVE_PATH
45-
SOURCE_DIR
46-
BASE_DIRECTORY ${CMAKE_SOURCE_DIR}
47-
OUTPUT_VARIABLE relativeDir
48-
)
49-
file(READ "${SOURCE_DIR}/zend_language_parser.h" content)
50-
string(
51-
REPLACE
52-
"int zendparse"
53-
"ZEND_API int zendparse"
54-
content_2
55-
"${content}"
56-
)
57-
if(
58-
NOT content MATCHES "ZEND_API int zendparse"
59-
AND NOT content STREQUAL "${content_2}"
60-
)
61-
message(STATUS "Patching ${relativeDir}/zend_language_parser.h")
62-
file(WRITE "${SOURCE_DIR}/zend_language_parser.h" "${content_2}")
63-
endif()
64-
65-
file(READ "${SOURCE_DIR}/zend_language_parser.c" content)
66-
string(
67-
REPLACE
68-
"int zendparse"
69-
"ZEND_API int zendparse"
70-
content_2
71-
"${content}"
72-
)
73-
if(
74-
NOT content MATCHES "ZEND_API int zendparse"
75-
AND NOT content STREQUAL "${content_2}"
76-
)
77-
message(STATUS "Patching ${relativeDir}/zend_language_parser.c")
78-
file(WRITE "${SOURCE_DIR}/zend_language_parser.c" "${content_2}")
79-
endif()
80-
]])
42+
foreach(
43+
file IN ITEMS
44+
@CMAKE_CURRENT_SOURCE_DIR@/zend_language_parser.h
45+
@CMAKE_CURRENT_SOURCE_DIR@/zend_language_parser.c
46+
)
47+
file(READ "${file}" content)
48+
string(
49+
REPLACE
50+
"int zendparse"
51+
"ZEND_API int zendparse"
52+
patchedContent
53+
"${content}"
54+
)
55+
if(
56+
NOT content MATCHES "ZEND_API int zendparse"
57+
AND NOT content STREQUAL "${patchedContent}"
58+
)
59+
cmake_path(GET file FILENAME filename)
60+
message(STATUS "[Zend] Patching ${filename}")
61+
file(WRITE "${file}" "${patchedContent}")
62+
endif()
63+
endforeach()
64+
]]
65+
patch
66+
@ONLY
67+
)
8168

8269
# Run patch based on whether building or running inside a script.
8370
if(CMAKE_SCRIPT_MODE_FILE)

0 commit comments

Comments
 (0)