Skip to content

Commit 0e0c9f0

Browse files
committed
Add new PHP/Set module and fix various bugs
- Fixed PEAR tmp directory creation - Improved FPM build on Darwin, where some options can't be used - Replaced manual hacky dependent CACHE PATH variables replaced with the new php_set() function - Some cache variables in mysqli and pdo_mysql fixed few steps forward
1 parent b3296a7 commit 0e0c9f0

File tree

8 files changed

+198
-78
lines changed

8 files changed

+198
-78
lines changed

bin/check-cmake.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ function getProjectModules(): array
218218
'PHP/PkgConfigGenerator' => ['pkgconfig_generate_pc'],
219219
'PHP/SAPIs' => ['php_sapis_add'],
220220
'PHP/SearchLibraries' => ['php_search_libraries'],
221+
'PHP/Set' => ['php_set'],
221222
'PHP/SystemExtensions' => ['PHP::SystemExtensions'],
222223
];
223224
}

cmake/cmake/modules/PHP/Set.cmake

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#[=============================================================================[
2+
Set a CACHE variable that depends on a set of conditions.
3+
4+
In CMake there are 3 main ways to create non-internal cache variables that can
5+
be also customized using the `-D` command-line option, through CMake presets, or
6+
similar:
7+
* `option()`
8+
* `set(<variable> <value> CACHE <type> <docstring>)`
9+
* `cmake_dependent_option()`
10+
11+
Ideally, these are the recommended ways to set configuration variables. However,
12+
there are many cases where a `CACHE` variable of a type other than `BOOL`
13+
depends on certain conditions. Additionally, an edge-case issue with
14+
`cmake_dependent_option()` is that it sets a local variable if the conditions
15+
are not met. Local variables in such edge cases can be difficult to work with
16+
when using `add_subdirectory()`. In the parent scope, instead of the local
17+
variable with a forced value, the cached variable is still defined as
18+
`INTERNAL`, which can lead to bugs in the build process.
19+
20+
This module exposes the following function:
21+
22+
```cmake
23+
php_set(
24+
<variable>
25+
<default>
26+
CACHE <type>
27+
[STRINGS <string>...]
28+
[DOC <docstring>...]
29+
IF <condition>
30+
FORCED <forced>
31+
)
32+
```
33+
34+
It sets the given CACHE `<variable>` of `<type>` to a `<value>` if `<condition>`
35+
is met. Otherwise it sets the `<variable>` to `<default>` value and hides it in
36+
the GUI.
37+
38+
* The `CACHE` `<type>` can be `BOOL`, `FILEPATH`, `PATH`, or `STRING`.
39+
40+
* `STRINGS` is an optional list of items when `CACHE` `STRING` is used to create
41+
a list of supported options to pick in the GUI.
42+
43+
* `DOC` is a short variable help text visible in the GUIs. Multiple strings are
44+
joined together.
45+
46+
* `IF` behaves the same as the `<depends>` argument in
47+
`cmake_dependent_option()`. If conditions `<condition>` are met, the variable
48+
is set to `<default>` value. Otherwise, it is set to `<forced>` value and
49+
hidden in the GUIs. This supports both full condition sytanx and
50+
semicolon-separated list of conditions.
51+
52+
* `FORCED` is a value that is set when `IF <conditions>` are not met.
53+
#]=============================================================================]
54+
55+
include_guard(GLOBAL)
56+
57+
function(php_set)
58+
cmake_parse_arguments(
59+
PARSE_ARGV
60+
2
61+
parsed # prefix
62+
"" # options
63+
"CACHE;IF" # one-value keywords
64+
"STRINGS;DOC;FORCED" # multi-value keywords
65+
)
66+
67+
if(parsed_UNPARSED_ARGUMENTS)
68+
message(FATAL_ERROR "Bad arguments: ${parsed_UNPARSED_ARGUMENTS}")
69+
endif()
70+
71+
if(NOT parsed_CACHE)
72+
message(FATAL_ERROR "Missing CACHE type argument")
73+
elseif(NOT parsed_CACHE MATCHES "^(BOOL|FILEPATH|PATH|STRING)$")
74+
message(FATAL_ERROR "Unknown CACHE type argument: ${parsed_CACHE}")
75+
endif()
76+
77+
if(NOT parsed_IF)
78+
message(FATAL_ERROR "Missing IF argument with condition")
79+
endif()
80+
81+
if(NOT DEFINED parsed_FORCED)
82+
message(FATAL_ERROR "Missing FORCED argument")
83+
endif()
84+
85+
set(doc "")
86+
foreach(string ${parsed_DOC})
87+
string(APPEND doc "${string}")
88+
endforeach()
89+
90+
set(condition TRUE)
91+
foreach(d ${parsed_IF})
92+
cmake_language(EVAL CODE "
93+
if(${d})
94+
else()
95+
set(condition FALSE)
96+
endif()"
97+
)
98+
endforeach()
99+
100+
set(var "${ARGV0}")
101+
set(internal ___PHP_SET_${var})
102+
103+
if(NOT DEFINED ${internal} AND DEFINED ${var})
104+
set(${internal} "${${var}}" CACHE INTERNAL "Internal storage for ${var}")
105+
elseif(NOT DEFINED ${internal})
106+
set(${internal} "${ARGV1}" CACHE INTERNAL "Internal storage for ${var}")
107+
elseif(DEFINED ${internal} AND NOT ${internal}_FORCED)
108+
set(${internal} "${${var}}" CACHE INTERNAL "Internal storage for ${var}")
109+
endif()
110+
111+
if(condition)
112+
set(${var} "${${internal}}" CACHE ${parsed_CACHE} "${doc}" FORCE)
113+
if(parsed_CACHE STREQUAL "STRING" AND parsed_STRINGS)
114+
set_property(CACHE ${var} PROPERTY STRINGS ${parsed_STRINGS})
115+
endif()
116+
unset(${internal} CACHE)
117+
unset(${internal}_FORCED CACHE)
118+
else()
119+
set(${var} "${parsed_FORCED}" CACHE INTERNAL "${doc}")
120+
set(
121+
${internal}_FORCED
122+
TRUE
123+
CACHE INTERNAL
124+
"Internal marker that ${var} has a forced value."
125+
)
126+
endif()
127+
endfunction()

cmake/cmake/platforms/Darwin.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,4 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
4141
$<$<IN_LIST:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>:LINKER:-undefined,dynamic_lookup>
4242
)
4343
endif()
44-
45-
# Help Darwin systems a bit, because these are not available there.
46-
set(SAPI_FPM_SYSTEMD OFF)
47-
set(SAPI_FPM_ACL OFF)
48-
set(SAPI_FPM_APPARMOR OFF)
49-
set(SAPI_FPM_SELINUX OFF)
5044
endif()

cmake/ext/mysqli/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include(CMakeDependentOption)
22
include(FeatureSummary)
3+
include(PHP/Set)
34

45
option(EXT_MYSQLI "Enable the mysqli extension" OFF)
56

@@ -25,24 +26,23 @@ cmake_dependent_option(
2526
[[(EXT_MYSQLI OR EXT_PDO_MYSQL) AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"]]
2627
OFF
2728
)
29+
mark_as_advanced(EXT_MYSQL_SOCKET)
2830

29-
if((EXT_MYSQLI OR EXT_PDO_MYSQL) AND EXT_MYSQL_SOCKET)
30-
set(
31-
EXT_MYSQL_SOCKET_PATH ""
32-
CACHE FILEPATH
33-
"mysqli/pdo_mysql: Specify path to the MySQL Unix socket pointer location. \
34-
If unspecified, default locations are searched."
35-
)
36-
# Change from INTERNAL type to show variable on consecutive configuration run.
37-
set_property(CACHE EXT_MYSQL_SOCKET_PATH PROPERTY TYPE FILEPATH)
38-
elseif(DEFINED EXT_MYSQL_SOCKET_PATH)
39-
# Hide variable.
40-
set_property(CACHE EXT_MYSQL_SOCKET_PATH PROPERTY TYPE INTERNAL)
31+
php_set(
32+
EXT_MYSQL_SOCKET_PATH
33+
""
34+
CACHE FILEPATH
35+
DOC
36+
"mysqli/pdo_mysql: Specify path to the MySQL Unix socket pointer location. "
37+
"If unspecified, default locations are searched."
38+
IF [[(EXT_MYSQLI OR EXT_PDO_MYSQL) AND EXT_MYSQL_SOCKET]]
39+
FORCED ""
40+
)
41+
mark_as_advanced(EXT_MYSQL_SOCKET_PATH)
42+
if(NOT EXT_MYSQL_SOCKET_PATH)
4143
unset(PHP_MYSQL_UNIX_SOCK_ADDR CACHE)
4244
endif()
4345

44-
mark_as_advanced(EXT_MYSQL_SOCKET EXT_MYSQL_SOCKET_PATH)
45-
4646
if(NOT EXT_MYSQLI)
4747
return()
4848
endif()

cmake/ext/pdo_mysql/CMakeLists.txt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
include(CMakeDependentOption)
44
include(FeatureSummary)
5+
include(PHP/Set)
56

67
cmake_dependent_option(
78
EXT_PDO_MYSQL
@@ -26,23 +27,18 @@ cmake_dependent_option(
2627
)
2728

2829
# Driver selection option.
29-
if(EXT_PDO_MYSQL)
30-
set(
31-
EXT_PDO_MYSQL_DRIVER "mysqlnd"
32-
CACHE STRING "Select MySQL driver: mysqlnd (MySQL Native Driver, \
33-
recommended) or mysql (system MySQL)"
34-
)
35-
set_property(
36-
CACHE EXT_PDO_MYSQL_DRIVER
37-
PROPERTY STRINGS "mysqlnd" "mysql"
38-
)
39-
mark_as_advanced(EXT_PDO_MYSQL_DRIVER)
40-
# Change from INTERNAL type to show variable on consecutive configuration run.
41-
set_property(CACHE EXT_PDO_MYSQL_DRIVER PROPERTY TYPE STRING)
42-
elseif(DEFINED EXT_PDO_MYSQL_DRIVER)
43-
# Hide variable.
44-
set_property(CACHE EXT_PDO_MYSQL_DRIVER PROPERTY TYPE INTERNAL)
45-
endif()
30+
php_set(
31+
EXT_PDO_MYSQL_DRIVER
32+
"mysqlnd"
33+
CACHE STRING
34+
STRINGS "mysqlnd" "mysql"
35+
DOC
36+
"Select MySQL driver: mysqlnd (MySQL Native Driver, recommended) or mysql "
37+
"(system MySQL)"
38+
IF EXT_PDO_MYSQL
39+
FORCED ""
40+
)
41+
mark_as_advanced(EXT_PDO_MYSQL_DRIVER)
4642

4743
if(NOT EXT_PDO_MYSQL)
4844
return()
@@ -100,7 +96,12 @@ endif()
10096
if(NOT EXT_PDO_MYSQL_DRIVER STREQUAL "mysql")
10197
add_dependencies(php_pdo_mysql php_mysqlnd)
10298

103-
set(PDO_USE_MYSQLND 1 CACHE INTERNAL "Whether pdo_mysql uses mysqlnd")
99+
# TODO: Is there a better way here?
100+
set(PDO_USE_MYSQLND TRUE)
101+
get_directory_property(hasParent PARENT_DIRECTORY)
102+
if(hasParent)
103+
set(PDO_USE_MYSQLND ${PDO_USE_MYSQLND} PARENT_SCOPE)
104+
endif()
104105
else()
105106
find_package(MySQL COMPONENTS Lib OPTIONAL_COMPONENTS Socket)
106107
set_package_properties(MySQL PROPERTIES

cmake/pear/CMakeLists.txt

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include(FeatureSummary)
22
include(PHP/Install)
3+
include(PHP/Set)
34

45
option(PHP_PEAR "Install PEAR" OFF)
56

@@ -9,53 +10,45 @@ add_feature_info(
910
"PHP Extension and Application Repository package manager"
1011
)
1112

12-
if(PHP_PEAR)
13-
set(
14-
PHP_PEAR_DIR "${CMAKE_INSTALL_DATADIR}/pear"
15-
CACHE FILEPATH
16-
"The PEAR installation directory. CMAKE_INSTALL_PREFIX is automatically\
17-
prepended when given as relative path. Default: DATADIR/pear"
18-
)
19-
# Change from INTERNAL type to show variable on consecutive configuration run.
20-
set_property(CACHE PHP_PEAR_DIR PROPERTY TYPE FILEPATH)
21-
elseif(DEFINED PHP_PEAR_DIR)
22-
# Hide variable.
23-
set_property(CACHE PHP_PEAR_DIR PROPERTY TYPE INTERNAL)
24-
endif()
13+
php_set(
14+
PHP_PEAR_DIR
15+
"${CMAKE_INSTALL_DATADIR}/pear"
16+
CACHE PATH
17+
DOC
18+
"The PEAR installation directory. CMAKE_INSTALL_PREFIX is automatically "
19+
"prepended when given as relative path. Default: DATADIR/pear"
20+
IF PHP_PEAR
21+
FORCED ""
22+
)
2523
mark_as_advanced(PHP_PEAR_DIR)
2624

2725
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2826
set(tmpDir "temp/pear")
2927
else()
3028
set(tmpDir "tmp/pear")
3129
endif()
32-
if(PHP_PEAR)
33-
set(
34-
PHP_PEAR_TEMP_DIR "${tmpDir}"
35-
CACHE FILEPATH
36-
"The PEAR temporary directory where PEAR writes temporary files, such as\
37-
cache, downloaded packages artifacts and similar. Pass it as a relative\
38-
path inside the top level system directory, which will be automatically\
39-
prepended. If given as an absolute path, top level directory is not\
40-
prepended. Relative path is added to the top root system directory (/ on\
41-
*nix, or c:/ on Windows). Default: ${tmpDir}."
42-
)
43-
# Change from INTERNAL type to show variable on consecutive configuration run.
44-
set_property(CACHE PHP_PEAR_TEMP_DIR PROPERTY TYPE FILEPATH)
45-
elseif(DEFINED PHP_PEAR_TEMP_DIR)
46-
# Hide variable.
47-
set_property(CACHE PHP_PEAR_TEMP_DIR PROPERTY TYPE INTERNAL)
48-
endif()
30+
php_set(
31+
PHP_PEAR_TEMP_DIR
32+
"${tmpDir}"
33+
CACHE PATH
34+
DOC
35+
"The PEAR temporary directory where PEAR writes temporary files, such as "
36+
"cache, downloaded packages artifacts and similar. Pass it as a relative "
37+
"path inside the top level system directory, which will be automatically "
38+
"prepended. If given as an absolute path, top level directory is not "
39+
"prepended. Relative path is added to the top root system directory (/ on "
40+
"*nix, or c:/ on Windows). Default: ${tmpDir}."
41+
IF PHP_PEAR
42+
FORCED ""
43+
)
4944
mark_as_advanced(PHP_PEAR_TEMP_DIR)
5045

5146
message(CHECK_START "Checking for PEAR")
52-
5347
if(NOT PHP_PEAR)
5448
message(CHECK_FAIL "no")
5549
return()
56-
else()
57-
message(CHECK_PASS "yes")
5850
endif()
51+
message(CHECK_PASS "yes")
5952

6053
message(
6154
DEPRECATION

cmake/pear/InstallPear.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ set(ENV{PHP_PEAR_SYSCONF_DIR} ${phpPearInstallSysconfDir})
120120
# Set the PHP extensions directory.
121121
set(ENV{PHP_PEAR_EXTENSION_DIR} "${phpExtensionDir}")
122122

123-
# Set PEAR temporary directory for the DESTDIR and system top level directory.
124-
php_pear_path_with_destdir(${PHP_PEAR_TEMP_DIR} phpPearStageTempDir)
125-
126123
if(IS_ABSOLUTE ${PHP_PEAR_TEMP_DIR})
127124
cmake_path(SET phpPearTempDir NORMALIZE "${PHP_PEAR_TEMP_DIR}")
128125
else()
@@ -133,6 +130,9 @@ else()
133130
endif()
134131
endif()
135132

133+
# Set PEAR temporary directory for the DESTDIR and system top level directory.
134+
php_pear_path_with_destdir(${phpPearTempDir} phpPearStageTempDir)
135+
136136
file(
137137
MAKE_DIRECTORY
138138
${phpPearInstallStageDir}

cmake/sapi/fpm/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ cmake_dependent_option(
4949
SAPI_FPM_SYSTEMD
5050
"Enable the systemd integration"
5151
OFF
52-
"SAPI_FPM"
52+
# Darwin systems don't have systemd.
53+
[[SAPI_FPM AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin"]]
5354
OFF
5455
)
5556

@@ -63,7 +64,8 @@ cmake_dependent_option(
6364
SAPI_FPM_ACL
6465
"Use POSIX Access Control Lists"
6566
OFF
66-
"SAPI_FPM"
67+
# Darwin systems don't have ACL.
68+
[[SAPI_FPM AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin"]]
6769
OFF
6870
)
6971

@@ -77,7 +79,8 @@ cmake_dependent_option(
7779
SAPI_FPM_APPARMOR
7880
"Enable the AppArmor confinement through libapparmor"
7981
OFF
80-
"SAPI_FPM"
82+
# Darwin systems don't have AppArmor.
83+
[[SAPI_FPM AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin"]]
8184
OFF
8285
)
8386

@@ -91,7 +94,8 @@ cmake_dependent_option(
9194
SAPI_FPM_SELINUX
9295
"Enable the SELinux policy library support"
9396
OFF
94-
"SAPI_FPM"
97+
# Darwin systems don't have SELinux.
98+
[[SAPI_FPM AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin"]]
9599
OFF
96100
)
97101

0 commit comments

Comments
 (0)