Skip to content

Commit 8df1759

Browse files
committed
Add various improvements
- The getaddrinfo check simplified as there is no need to do check if source compiles. The main runnable test is also checking if it compiles correctly, unlike in Autotools. Besides, this removed check is causing failures due to wrong code. The hints variable (h) wasn't initialized on some configurations. - Few CS nits fixed - PHP/SearchLibraries now has optional target scope to match the upstream target_link_libraries usage when used in plain mode (without scope defined) - Python GitHub action updated to v5
1 parent dcfb804 commit 8df1759

File tree

16 files changed

+83
-87
lines changed

16 files changed

+83
-87
lines changed

.github/workflows/check-cmake.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fetch-depth: 2
1818

1919
- name: Setup Python
20-
uses: actions/setup-python@v4
20+
uses: actions/setup-python@v5
2121

2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2

cmake/cmake/modules/PHP/CheckFopencookie.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ include(CMakePushCheckState)
3030

3131
cmake_push_check_state(RESET)
3232
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
33-
check_symbol_exists(fopencookie "stdio.h" _have_fopencookie)
33+
check_symbol_exists(fopencookie "stdio.h" _HAVE_FOPENCOOKIE)
3434
cmake_pop_check_state()
3535

36-
if(NOT _have_fopencookie)
36+
if(NOT _HAVE_FOPENCOOKIE)
3737
return()
3838
endif()
3939

cmake/cmake/modules/PHP/CheckGetaddrinfo.cmake

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ IMPORTED target:
1818

1919
include_guard(GLOBAL)
2020

21-
include(CheckSourceCompiles)
2221
include(CheckSourceRuns)
2322
include(CMakePushCheckState)
2423
include(PHP/SearchLibraries)
@@ -60,72 +59,57 @@ cmake_push_check_state(RESET)
6059
set(CMAKE_REQUIRED_LIBRARIES PHP::CheckGetaddrinfoLibrary)
6160
endif()
6261

63-
check_source_compiles(C [[
62+
if(
63+
NOT DEFINED HAVE_GETADDRINFO_EXITCODE
64+
AND CMAKE_CROSSCOMPILING
65+
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
66+
AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
67+
)
68+
set(HAVE_GETADDRINFO_EXITCODE 0)
69+
endif()
70+
71+
check_source_runs(C [[
6472
#include <netdb.h>
73+
#include <sys/types.h>
74+
#include <string.h>
75+
#include <stdlib.h>
76+
#ifndef AF_INET
77+
# include <sys/socket.h>
78+
#endif
6579

6680
int main(void)
6781
{
68-
struct addrinfo *g,h;
69-
g = &h;
70-
getaddrinfo("", "", g, &g);
82+
struct addrinfo *ai, *pai, hints;
7183

72-
return 0;
73-
}
74-
]] _have_getaddrinfo)
75-
76-
if(_have_getaddrinfo)
77-
if(
78-
NOT DEFINED HAVE_GETADDRINFO_EXITCODE
79-
AND CMAKE_CROSSCOMPILING
80-
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
81-
AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
82-
)
83-
set(HAVE_GETADDRINFO_EXITCODE 0)
84-
endif()
85-
86-
check_source_runs(C [[
87-
#include <netdb.h>
88-
#include <sys/types.h>
89-
#include <string.h>
90-
#include <stdlib.h>
91-
#ifndef AF_INET
92-
# include <sys/socket.h>
93-
#endif
94-
95-
int main(void)
96-
{
97-
struct addrinfo *ai, *pai, hints;
98-
99-
memset(&hints, 0, sizeof(hints));
100-
hints.ai_flags = AI_NUMERICHOST;
101-
102-
if (getaddrinfo("127.0.0.1", 0, &hints, &ai) < 0) {
103-
return 1;
104-
}
84+
memset(&hints, 0, sizeof(hints));
85+
hints.ai_flags = AI_NUMERICHOST;
10586

106-
if (ai == 0) {
87+
if (getaddrinfo("127.0.0.1", 0, &hints, &ai) < 0) {
88+
return 1;
89+
}
90+
91+
if (ai == 0) {
92+
return 1;
93+
}
94+
95+
pai = ai;
96+
97+
while (pai) {
98+
if (pai->ai_family != AF_INET) {
99+
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
107100
return 1;
108101
}
109-
110-
pai = ai;
111-
112-
while (pai) {
113-
if (pai->ai_family != AF_INET) {
114-
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
115-
return 1;
116-
}
117-
if (pai->ai_addr->sa_family != AF_INET) {
118-
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
119-
return 1;
120-
}
121-
pai = pai->ai_next;
102+
if (pai->ai_addr->sa_family != AF_INET) {
103+
/* 127.0.0.1/NUMERICHOST should only resolve ONE way */
104+
return 1;
122105
}
123-
freeaddrinfo(ai);
124-
125-
return 0;
106+
pai = pai->ai_next;
126107
}
127-
]] HAVE_GETADDRINFO)
128-
endif()
108+
freeaddrinfo(ai);
109+
110+
return 0;
111+
}
112+
]] HAVE_GETADDRINFO)
129113
cmake_pop_check_state()
130114

131115
if(HAVE_GETADDRINFO)

cmake/cmake/modules/PHP/SearchLibraries.cmake

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ php_search_libraries(
2828
[LIBRARIES <library>...]
2929
[VARIABLE <variable>]
3030
[LIBRARY_VARIABLE <library_variable>]
31-
[TARGET <target> <PRIVATE|PUBLIC|INTERFACE>]
31+
[TARGET <target> [<PRIVATE|PUBLIC|INTERFACE>]]
3232
[RECHECK_HEADERS]
3333
)
3434
```
@@ -68,11 +68,11 @@ If `<variable>` is given, check result is stored in an internal cache variable.
6868
* `TARGET`
6969
7070
If the `TARGET` is given, the resulting library is linked to a given
71-
`<target>` with the scope of `PRIVATE`, `PUBLIC`, or `INTERFACE`. It is
71+
`<target>` with the scope of `PRIVATE`, `PUBLIC`, or `INTERFACE`. Behavior is
7272
homogeneous to:
7373
7474
```cmake
75-
target_link_libraries(<target> PRIVATE|PUBLIC|INTERFACE <library>)
75+
target_link_libraries(<target> [PRIVATE|PUBLIC|INTERFACE] <library>)
7676
```
7777
7878
* `RECHECK_HEADERS`
@@ -85,11 +85,21 @@ If `<variable>` is given, check result is stored in an internal cache variable.
8585
checked elsewhere in the application using the `check_header_include()`. In
8686
most cases this won't be needed.
8787
88-
For example:
88+
## Basic usage
89+
90+
In the following example, the library containing `dlopen` is linked to
91+
`php_configuration` target with the `INTERFACE` scope when needed to use the
92+
`dlopen` symbol. Cache variable `HAVE_LIBDL` is set if `dlopen` is found either
93+
in the default system libraries or in one of the libraries set in the
94+
`CMAKE_DL_LIBS` variable.
8995
9096
```cmake
97+
# CMakeLists.txt
98+
99+
# Include the module
91100
include(PHP/SearchLibraries)
92101
102+
# Search and link library containing dlopen and dlclose .
93103
php_search_libraries(
94104
dlopen
95105
HEADERS dlfcn.h
@@ -108,9 +118,10 @@ https://cmake.org/cmake/help/latest/module/CheckSymbolExists.html
108118
* `CMAKE_REQUIRED_INCLUDES`
109119
* `CMAKE_REQUIRED_LINK_OPTIONS`
110120
* `CMAKE_REQUIRED_LIBRARIES`
121+
* `CMAKE_REQUIRED_LINK_DIRECTORIES`
111122
* `CMAKE_REQUIRED_QUIET`
112123
113-
Caveats:
124+
## Caveats
114125
115126
* If symbol declaration is missing in its belonging headers, it won't be found
116127
with this module. There are still rare cases of such functions on some systems
@@ -207,20 +218,18 @@ function(php_search_libraries)
207218
# Validate optional TARGET.
208219
if(parsed_TARGET)
209220
list(GET parsed_TARGET 0 target)
210-
list(GET parsed_TARGET 1 targetScope)
211221

212222
if(NOT TARGET ${target})
213223
message(FATAL_ERROR "Bad TARGET arguments: ${target} is not a target")
214224
endif()
215225

216-
if(NOT targetScope)
217-
message(
218-
FATAL_ERROR
219-
"Bad TARGET arguments: Target scope PRIVATE|PUBLIC|INTERFACE is missing"
220-
)
226+
list(LENGTH parsed_TARGET length)
227+
set(targetScope)
228+
if(length GREATER 1)
229+
list(GET parsed_TARGET 1 targetScope)
221230
endif()
222231

223-
if(NOT targetScope MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$")
232+
if(targetScope AND NOT targetScope MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$")
224233
message(
225234
FATAL_ERROR
226235
"Bad TARGET arguments: ${targetScope} is not a target scope. Use one "

cmake/cmake/modules/PHP/Set.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ php_set(
103103
include(PHP/Set)
104104
php_set(
105105
VAR
106-
CHOICES auto on off
106+
CHOICES auto ON OFF
107107
DOC "Variable with default value set to the first list item"
108108
)
109109
message(STATUS "VAR=${VAR}")
@@ -124,7 +124,7 @@ php_set(
124124
```cmake
125125
php_set(
126126
VAR
127-
CHOICES auto on off
127+
CHOICES auto ON OFF
128128
CHOICES_OPTIONAL
129129
DOC
130130
"Variable with optional predefined choices where its value can be also "

cmake/cmake/modules/PHP/Stubs.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ block()
123123
CONTENT "${content}"
124124
)
125125

126+
set(targetOptions)
126127
if(NOT PHPSystem_EXECUTABLE)
127128
set(targetOptions ALL DEPENDS ${targets})
128129
endif()

cmake/ext/date/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include(FeatureSummary)
1818

1919
add_feature_info(
2020
"ext/date"
21-
ON
21+
TRUE
2222
"date and time"
2323
)
2424

cmake/ext/hash/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ include(PHP/CheckCompilerFlag)
2626

2727
add_feature_info(
2828
"ext/hash"
29-
ON
29+
TRUE
3030
"HASH message digest framework"
3131
)
3232

cmake/ext/json/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include(FeatureSummary)
1616

1717
add_feature_info(
1818
"ext/json"
19-
ON
19+
TRUE
2020
"JavaScript Object Notation"
2121
)
2222

cmake/ext/pcre/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ include(PHP/CheckCompilerFlag)
3737

3838
add_feature_info(
3939
"ext/pcre"
40-
ON
40+
TRUE
4141
"Perl-compatible regular expressions"
4242
)
4343

0 commit comments

Comments
 (0)