Skip to content

Commit 235d2a6

Browse files
committed
Merge branch 'PHP-8.3'
2 parents bb44d91 + 8a7ca99 commit 235d2a6

File tree

3 files changed

+144
-102
lines changed

3 files changed

+144
-102
lines changed

cmake/cmake/modules/PHP/PkgConfigGenerator.cmake

Lines changed: 106 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@ Also there is a common issue with installation prefix not being applied when
99
using --prefix command line option at the installation phase:
1010
cmake --install <build-dir> --prefix <prefix>
1111
12-
TODO: This module will be refactored and changed further in the future.
13-
1412
The following function is exposed:
1513
1614
pkgconfig_generate_pc(
1715
<pc-template-file>
1816
<pc-file-output>
1917
TARGET <target>
18+
[INSTALL_DESTINATION <path>]
2019
[VARIABLES [<variable> <value>] [<variable_2>:BOOL <value_2>...] ...]
21-
SKIP_BOOL_NORMALIZATION
20+
[SKIP_BOOL_NORMALIZATION]
2221
)
2322
2423
Generate pkgconfig <pc-file-output> from the given pc <pc-template-file>
2524
template.
2625
2726
TARGET
2827
Name of the target for getting libraries.
28+
INSTALL_DESTINATION
29+
Path to the pkgconfig directory where generated .pc file will be installed
30+
to. Usually it is '${CMAKE_INSTALL_LIBDIR}/pkgconfig'. If not provided, .pc
31+
file will not be installed.
2932
VARIABLES
3033
Pairs of variable names and values. To pass booleans, add ':BOOL' to the
3134
variable name. For example:
@@ -35,6 +38,11 @@ pkgconfig_generate_pc(
3538
variable_name:BOOL "${variable_name}"
3639
)
3740
41+
The $<INSTALL_PREFIX> generator expression can be used in variable values,
42+
which is replaced with installation prefix either set via the
43+
CMAKE_INSTALL_PREFIX variable at the configuration phase, or the
44+
'cmake --install --prefix' option at the installation phase.
45+
3846
SKIP_BOOL_NORMALIZATION
3947
CMake booleans have values yes, no, true, false, on, off, 1, 0, they can
4048
even be case insensitive and so on. By default, all booleans (var:BOOL see
@@ -52,14 +60,79 @@ find_program(
5260
)
5361
mark_as_advanced(PKGCONFIG_OBJDUMP_EXECUTABLE)
5462

63+
# Parse given variables and create a list of options or variables for passing to
64+
# add_custom_command and configure_file().
65+
function(_pkgconfig_parse_variables variables)
66+
# Check for even number of keyword values.
67+
list(LENGTH variables length)
68+
math(EXPR modulus "${length} % 2")
69+
if(NOT modulus EQUAL 0)
70+
message(
71+
FATAL_ERROR
72+
"The keyword VARIABLES must be a list of pairs - variable-name and "
73+
"value (it must contain an even number of items)."
74+
)
75+
endif()
76+
77+
set(is_value FALSE)
78+
set(variables_options "")
79+
set(result_variables "")
80+
set(result_values "")
81+
foreach(variable IN LISTS variables)
82+
if(is_value)
83+
set(is_value FALSE)
84+
continue()
85+
endif()
86+
list(POP_FRONT variables var value)
87+
88+
# Normalize boolean values to either "yes" or "no".
89+
if(var MATCHES ".*:BOOL$" AND NOT parsed_SKIP_BOOL_NORMALIZATION)
90+
if(value)
91+
set(value "yes")
92+
else()
93+
set(value "no")
94+
endif()
95+
endif()
96+
97+
# Remove possible :<TYPE> part from the variable name.
98+
if(var MATCHES "(.*):BOOL$")
99+
set(var ${CMAKE_MATCH_1})
100+
endif()
101+
102+
list(APPEND result_variables ${var})
103+
list(APPEND result_values "${value}")
104+
105+
# Replace possible INSTALL_PREFIX in value for usage in add_custom_command,
106+
# in the result_values above the intact genex is left for enabling the
107+
# possible 'cmake --install --prefix ...' override.
108+
if(value MATCHES [[.*\$<INSTALL_PREFIX>.*]])
109+
string(
110+
REPLACE
111+
"$<INSTALL_PREFIX>"
112+
"${CMAKE_INSTALL_PREFIX}"
113+
value
114+
"${value}"
115+
)
116+
endif()
117+
118+
list(APPEND variables_options -D ${var}="${value}")
119+
120+
set(is_value TRUE)
121+
endforeach()
122+
123+
set(variables_options "${variables_options}" PARENT_SCOPE)
124+
set(result_variables "${result_variables}" PARENT_SCOPE)
125+
set(result_values "${result_values}" PARENT_SCOPE)
126+
endfunction()
127+
55128
function(pkgconfig_generate_pc)
56129
cmake_parse_arguments(
57130
PARSE_ARGV
58131
2
59-
parsed # prefix
60-
"SKIP_BOOL_NORMALIZATION" # options
61-
"TARGET" # one-value keywords
62-
"VARIABLES" # multi-value keywords
132+
parsed # prefix
133+
"SKIP_BOOL_NORMALIZATION" # options
134+
"TARGET;INSTALL_DESTINATION" # one-value keywords
135+
"VARIABLES" # multi-value keywords
63136
)
64137

65138
if(parsed_UNPARSED_ARGUMENTS)
@@ -106,7 +179,6 @@ function(pkgconfig_generate_pc)
106179
endif()
107180
endforeach()
108181
list(REMOVE_DUPLICATES libs)
109-
message(STATUS "Libs from link.txt: ${libs}")
110182
endif()
111183

112184
if(PKGCONFIG_OBJDUMP_EXECUTABLE)
@@ -127,8 +199,6 @@ function(pkgconfig_generate_pc)
127199
endif()
128200
endif()
129201
endforeach()
130-
131-
message(STATUS "Libraries from objdump: ${libraries}")
132202
endif()
133203

134204
list(JOIN libraries " " PHP_LIBS_PRIVATE)
@@ -141,45 +211,7 @@ function(pkgconfig_generate_pc)
141211
endif()
142212

143213
if(parsed_VARIABLES)
144-
set(variables "${parsed_VARIABLES}")
145-
146-
# Check for even number of keyword values.
147-
list(LENGTH variables length)
148-
math(EXPR modulus "${length} % 2")
149-
if(NOT modulus EQUAL 0)
150-
message(
151-
FATAL_ERROR
152-
"The keyword VARIABLES must be a list of pairs - variable-name and "
153-
"value (it must contain an even number of items)."
154-
)
155-
endif()
156-
157-
set(is_value FALSE)
158-
set(variables_options "")
159-
foreach(variable IN LISTS variables)
160-
if(is_value)
161-
set(is_value FALSE)
162-
continue()
163-
endif()
164-
list(POP_FRONT variables var value)
165-
166-
# Normalize boolean values to either "yes" or "no".
167-
if(var MATCHES ".*:BOOL$" AND NOT parsed_SKIP_BOOL_NORMALIZATION)
168-
if(value)
169-
set(value "yes")
170-
else()
171-
set(value "no")
172-
endif()
173-
endif()
174-
175-
# Remove possible :<TYPE> part from the variable name.
176-
if(var MATCHES "(.*):BOOL$")
177-
set(var ${CMAKE_MATCH_1})
178-
endif()
179-
180-
list(APPEND variables_options -D ${var}="${value}")
181-
set(is_value TRUE)
182-
endforeach()
214+
_pkgconfig_parse_variables("${parsed_VARIABLES}")
183215
endif()
184216

185217
cmake_path(GET template FILENAME filename)
@@ -198,4 +230,29 @@ function(pkgconfig_generate_pc)
198230
-P CMakeFiles/PkgConfigGeneratePc.cmake
199231
COMMENT "[PkgConfig] Generating pkg-config ${filename} file"
200232
)
233+
234+
if(parsed_INSTALL_DESTINATION)
235+
cmake_path(GET output FILENAME output_file)
236+
237+
install(CODE "
238+
set(result_variables ${result_variables})
239+
set(result_values \"${result_values}\")
240+
241+
foreach(var value IN ZIP_LISTS result_variables result_values)
242+
set(\${var} \"\${value}\")
243+
endforeach()
244+
245+
configure_file(
246+
${template}
247+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${output_file}
248+
@ONLY
249+
)
250+
")
251+
252+
install(
253+
FILES
254+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${output_file}
255+
DESTINATION ${parsed_INSTALL_DESTINATION}
256+
)
257+
endif()
201258
endfunction()

cmake/sapi/embed/CMakeLists.txt

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,25 @@ set_target_properties(
4242
)
4343

4444
# Configure pkgconf php-embed.pc metadata file.
45-
block()
46-
include(PHP/PkgConfigGenerator)
47-
48-
pkgconfig_generate_pc(
49-
php-embed.pc.in
50-
php-embed.pc
51-
TARGET php_embed
52-
VARIABLES
53-
prefix "${CMAKE_INSTALL_PREFIX}"
54-
exec_prefix "${CMAKE_INSTALL_PREFIX}"
55-
includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
56-
libdir "${CMAKE_INSTALL_FULL_LIBDIR}"
57-
PHP_VERSION "${PHP_VERSION}"
58-
PHP_VERSION_ID "${PHP_VERSION_ID}"
59-
PHP_EXTENSION_DIR "${PHP_EXTENSION_DIR}"
60-
PHP_CONFIG_FILE_SCAN_DIR "${PHP_CONFIG_FILE_SCAN_DIR}"
61-
PHP_CONFIG_FILE_PATH "${PHP_CONFIG_FILE_PATH}"
62-
PHP_DEBUG:BOOL "${PHP_DEBUG}"
63-
PHP_THREAD_SAFETY:BOOL "${PHP_THREAD_SAFETY}"
64-
)
65-
endblock()
45+
include(PHP/PkgConfigGenerator)
46+
pkgconfig_generate_pc(
47+
php-embed.pc.in
48+
php-embed.pc
49+
TARGET php_embed
50+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
51+
VARIABLES
52+
prefix "$<INSTALL_PREFIX>"
53+
exec_prefix "$<INSTALL_PREFIX>"
54+
includedir "$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}"
55+
libdir "$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}"
56+
PHP_VERSION "${PHP_VERSION}"
57+
PHP_VERSION_ID "${PHP_VERSION_ID}"
58+
PHP_EXTENSION_DIR "${PHP_EXTENSION_DIR}"
59+
PHP_CONFIG_FILE_SCAN_DIR "${PHP_CONFIG_FILE_SCAN_DIR}"
60+
PHP_CONFIG_FILE_PATH "${PHP_CONFIG_FILE_PATH}"
61+
PHP_DEBUG:BOOL "${PHP_DEBUG}"
62+
PHP_THREAD_SAFETY:BOOL "${PHP_THREAD_SAFETY}"
63+
)
6664

6765
install(
6866
TARGETS php_embed
@@ -73,9 +71,3 @@ install(
7371
FILE_SET HEADERS
7472
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sapi/embed
7573
)
76-
77-
install(
78-
FILES
79-
${CMAKE_CURRENT_BINARY_DIR}/php-embed.pc
80-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
81-
)

cmake/scripts/CMakeLists.txt

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,25 @@ block()
6262
endblock()
6363

6464
# Configure pkgconf php.pc metadata file.
65-
block()
66-
include(PHP/PkgConfigGenerator)
67-
pkgconfig_generate_pc(
68-
php.pc.in
69-
php.pc
70-
TARGET php_cli
71-
VARIABLES
72-
prefix "${CMAKE_INSTALL_PREFIX}"
73-
exec_prefix "${CMAKE_INSTALL_PREFIX}"
74-
includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
75-
libdir "${CMAKE_INSTALL_FULL_LIBDIR}"
76-
PHP_VERSION "${PHP_VERSION}"
77-
PHP_VERSION_ID "${PHP_VERSION_ID}"
78-
PHP_EXTENSION_DIR "${PHP_EXTENSION_DIR}"
79-
PHP_CONFIG_FILE_SCAN_DIR "${PHP_CONFIG_FILE_SCAN_DIR}"
80-
PHP_CONFIG_FILE_PATH "${PHP_CONFIG_FILE_PATH}"
81-
PHP_DEBUG:BOOL "${PHP_DEBUG}"
82-
PHP_THREAD_SAFETY:BOOL "${PHP_THREAD_SAFETY}"
83-
)
84-
endblock()
65+
include(PHP/PkgConfigGenerator)
66+
pkgconfig_generate_pc(
67+
php.pc.in
68+
php.pc
69+
TARGET php_cli
70+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
71+
VARIABLES
72+
prefix "$<INSTALL_PREFIX>"
73+
exec_prefix "$<INSTALL_PREFIX>"
74+
includedir "$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}"
75+
libdir "$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}"
76+
PHP_VERSION "${PHP_VERSION}"
77+
PHP_VERSION_ID "${PHP_VERSION_ID}"
78+
PHP_EXTENSION_DIR "${PHP_EXTENSION_DIR}"
79+
PHP_CONFIG_FILE_SCAN_DIR "${PHP_CONFIG_FILE_SCAN_DIR}"
80+
PHP_CONFIG_FILE_PATH "${PHP_CONFIG_FILE_PATH}"
81+
PHP_DEBUG:BOOL "${PHP_DEBUG}"
82+
PHP_THREAD_SAFETY:BOOL "${PHP_THREAD_SAFETY}"
83+
)
8584

8685
install(
8786
FILES
@@ -96,9 +95,3 @@ install(
9695
${CMAKE_CURRENT_BINARY_DIR}/phpize
9796
DESTINATION ${CMAKE_INSTALL_BINDIR}
9897
)
99-
100-
install(
101-
FILES
102-
${CMAKE_CURRENT_BINARY_DIR}/php.pc
103-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
104-
)

0 commit comments

Comments
 (0)