Skip to content

Commit 95646df

Browse files
committed
Add various improvements
- gethostbyname_r() checked with CMake native way and its sanity check fixed for modern compiler settings - sapi/apache2handler syncs moved further one step - FindApache module is now fully synced with upstream way - future refactorings might still be needed only to make it simpler and to find Apache custom build via Apache_ROOT variable a bit better - fixed CS - dmake check added in bin/init.sh script for very special cases to append the number of jobs in the build step
1 parent ebb0837 commit 95646df

File tree

6 files changed

+132
-88
lines changed

6 files changed

+132
-88
lines changed

bin/check-cmake/cmake-includes.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ modules="
8888
FindPackageMessage
8989
ProcessorCount
9090
91+
PHP/CheckFunctionAttribute
9192
PHP/PkgConfigGenerator
9293
PHP/SearchLibraries
9394
"
@@ -148,6 +149,7 @@ FindPackageHandleStandardArgs="
148149
FindPackageMessage="find_package_message"
149150
ProcessorCount="processorcount"
150151

152+
PHP_CheckFunctionAttribute="php_check_function_attribute"
151153
PHP_PkgConfigGenerator="pkgconfig_generate_pc"
152154
PHP_SearchLibraries="php_search_libraries"
153155

bin/init.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ if test -n "$generator"; then
218218
fi
219219

220220
# Check if make -j requires argument (Berkeley-based make implementations).
221-
if make -h 2>&1 | grep -q "\[-j max_jobs\]"; then
222-
# Linux has nproc, macOS and some BSD-based systems have sysctl.
221+
if make -h 2>&1 | grep -q "\[-j max_jobs\]" \
222+
|| make -h 2>&1 | grep "\-j dmake_max_jobs"; then
223+
# Linux, illumos has nproc, macOS and some BSD-based systems have sysctl.
223224
if command -v nproc > /dev/null; then
224225
jobs=$(nproc)
225226
elif command -v sysctl > /dev/null; then

cmake/cmake/modules/FindApache.cmake

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,26 @@ endif()
156156

157157
find_program(
158158
Apache_APR_CONFIG_EXECUTABLE
159-
NAMES apr-1-config apr-config
159+
NAMES apr-config apr-1-config
160160
PATHS ${_Apache_APR_BINDIR}
161161
DOC "Path to the apr library command-line tool for retrieving metainformation"
162162
)
163163
mark_as_advanced(Apache_APR_CONFIG_EXECUTABLE)
164164

165+
block()
166+
if(NOT Apache_APR_CONFIG_EXECUTABLE AND Apache_APXS_EXECUTABLE)
167+
execute_process(
168+
COMMAND "${Apache_APXS_EXECUTABLE}" -q APR_CONFIG
169+
OUTPUT_VARIABLE path
170+
OUTPUT_STRIP_TRAILING_WHITESPACE
171+
ERROR_QUIET
172+
)
173+
if(IS_EXECUTABLE ${path})
174+
set_property(CACHE Apache_APR_CONFIG_EXECUTABLE PROPERTY VALUE ${path})
175+
endif()
176+
endif()
177+
endblock()
178+
165179
if(Apache_APR_CONFIG_EXECUTABLE)
166180
execute_process(
167181
COMMAND "${Apache_APR_CONFIG_EXECUTABLE}" --cppflags
@@ -191,6 +205,7 @@ find_path(
191205
PATHS
192206
${PC_Apache_APR_INCLUDE_DIRS}
193207
${_Apache_APR_INCLUDE_DIR}
208+
${_Apache_APU_INCLUDE_DIR}
194209
PATH_SUFFIXES apr-1
195210
DOC "Directory containing apr library headers"
196211
)
@@ -217,12 +232,35 @@ endif()
217232

218233
find_program(
219234
Apache_APU_CONFIG_EXECUTABLE
220-
NAMES apu-1-config apu-config
235+
NAMES apu-config apu-1-config
221236
PATHS ${_Apache_APU_BINDIR}
222237
DOC "Path to the Apache Portable Runtime Utilities config command-line tool"
223238
)
224239
mark_as_advanced(Apache_APU_CONFIG_EXECUTABLE)
225240

241+
block()
242+
if(NOT Apache_APU_CONFIG_EXECUTABLE AND Apache_APXS_EXECUTABLE)
243+
execute_process(
244+
COMMAND "${Apache_APXS_EXECUTABLE}" -q APU_CONFIG
245+
OUTPUT_VARIABLE path
246+
OUTPUT_STRIP_TRAILING_WHITESPACE
247+
ERROR_QUIET
248+
)
249+
if(IS_EXECUTABLE ${path})
250+
set_property(CACHE Apache_APU_CONFIG_EXECUTABLE PROPERTY VALUE ${path})
251+
endif()
252+
endif()
253+
endblock()
254+
255+
if(Apache_APU_CONFIG_EXECUTABLE)
256+
execute_process(
257+
COMMAND "${Apache_APU_CONFIG_EXECUTABLE}" --includedir
258+
OUTPUT_VARIABLE _Apache_APU_INCLUDE_DIR
259+
OUTPUT_STRIP_TRAILING_WHITESPACE
260+
ERROR_QUIET
261+
)
262+
endif()
263+
226264
################################################################################
227265
# Apache.
228266
################################################################################

cmake/cmake/modules/FindPHPSystem.cmake

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,21 @@ set(_reason "")
3232

3333
find_program(
3434
PHPSystem_EXECUTABLE
35-
NAMES php php7 php74 php7.4 php8 php81 php8.1 php82 php8.2 php83 php8.3 php84
36-
php8.4
35+
NAMES
36+
php
37+
php8.4
38+
php84
39+
php8.3
40+
php83
41+
php8.2
42+
php82
43+
php8.1
44+
php81
45+
php8
46+
php7.4
47+
php74
48+
php7
49+
3750
DOC "Path to the PHP executable"
3851
)
3952

Lines changed: 66 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,103 @@
11
#[=============================================================================[
2-
Check which gethostbyname_r() function should be used.
2+
Check gethostbyname_r().
33
4-
The gethostbyname_r() function has different signatures on different systems.
4+
The non-standard gethostbyname_r() function has different signatures across
5+
systems:
56
6-
See https://github.com/autoconf-archive/autoconf-archive/blob/master/m4/ax_func_which_gethostbyname_r.m4
7+
* Linux, BSD: 6 arguments
8+
* Solaris, illumos: 5 arguments
9+
* AIX, HP-UX: 3 arguments
10+
* Haiku: network library has it for internal purposes, not intended for usage
11+
from the system headers.
12+
13+
See also:
14+
https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
715
816
Cache variables:
917
1018
HAVE_GETHOSTBYNAME_R
1119
Whether gethostbyname_r() is available.
12-
HAVE_FUNC_GETHOSTBYNAME_R_3
13-
Whether function has 3 arguments.
14-
HAVE_FUNC_GETHOSTBYNAME_R_5
15-
Whether function has 5 arguments.
1620
HAVE_FUNC_GETHOSTBYNAME_R_6
17-
Whether function has 6 arguments.
21+
Whether gethostbyname_r() has 6 arguments.
22+
HAVE_FUNC_GETHOSTBYNAME_R_5
23+
Whether gethostbyname_r() has 5 arguments.
24+
HAVE_FUNC_GETHOSTBYNAME_R_3
25+
Whether gethostbyname_r() has 3 arguments.
1826
]=============================================================================]#
1927

2028
include_guard(GLOBAL)
2129

22-
include(CheckSourceCompiles)
30+
include(CheckPrototypeDefinition)
31+
include(CheckSymbolExists)
2332
include(CMakePushCheckState)
2433

25-
message(CHECK_START "Checking how many arguments gethostbyname_r() takes")
26-
27-
cmake_push_check_state(RESET)
28-
set(CMAKE_REQUIRED_QUIET TRUE)
34+
function(_php_check_gethostbyname_r)
35+
message(CHECK_START "Checking number of gethostbyname_r() arguments")
2936

30-
# Sanity check with 1 argument signature.
31-
check_source_compiles(C [[
32-
#include <netdb.h>
33-
34-
int main(void) {
35-
char *name = "www.gnu.org";
36-
(void)gethostbyname_r(name);
37-
38-
return 0;
39-
}
40-
]] _have_one_argument)
41-
42-
if(_have_one_argument)
43-
cmake_pop_check_state()
44-
message(CHECK_FAIL "can't tell")
45-
message(WARNING "Cannot find function declaration in netdb.h")
37+
# Check whether gethostname_r() is available.
38+
check_symbol_exists(gethostbyname_r netdb.h _HAVE_GETHOSTBYNAME_R)
39+
if(NOT _HAVE_GETHOSTBYNAME_R)
40+
message(CHECK_FAIL "not found")
4641
return()
4742
endif()
4843

4944
# Check for 6 arguments signature.
50-
check_source_compiles(C [[
51-
#include <netdb.h>
52-
53-
int main(void) {
54-
char *name = "www.gnu.org";
55-
struct hostent ret, *retp;
56-
char buf[1024];
57-
int buflen = 1024;
58-
int my_h_errno;
59-
(void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno);
60-
61-
return 0;
62-
}
63-
]] HAVE_FUNC_GETHOSTBYNAME_R_6)
45+
check_prototype_definition(
46+
gethostbyname_r
47+
"int gethostbyname_r(const char *name, struct hostent *ret, char *buf, \
48+
size_t buflen, struct hostent **result, int *h_errnop)"
49+
"0"
50+
netdb.h
51+
HAVE_FUNC_GETHOSTBYNAME_R_6
52+
)
53+
if(HAVE_FUNC_GETHOSTBYNAME_R_6)
54+
message(CHECK_PASS "six")
55+
return()
56+
endif()
6457

6558
# Check for 5 arguments signature.
66-
if(NOT HAVE_FUNC_GETHOSTBYNAME_R_6)
67-
check_source_compiles(C [[
68-
#include <netdb.h>
69-
70-
int main(void) {
71-
char *name = "www.gnu.org";
72-
struct hostent ret;
73-
char buf[1024];
74-
int buflen = 1024;
75-
int my_h_errno;
76-
(void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno);
77-
78-
return 0;
79-
}
80-
]] HAVE_FUNC_GETHOSTBYNAME_R_5)
59+
check_prototype_definition(
60+
gethostbyname_r
61+
"struct hostent *gethostbyname_r(const char *name, struct hostent *result, \
62+
char *buffer, int buflen, int *h_errnop)"
63+
"0"
64+
netdb.h
65+
HAVE_FUNC_GETHOSTBYNAME_R_5
66+
)
67+
if(HAVE_FUNC_GETHOSTBYNAME_R_5)
68+
message(CHECK_PASS "five")
69+
return()
8170
endif()
8271

8372
# Check for 3 arguments signature.
84-
if(NOT HAVE_FUNC_GETHOSTBYNAME_R_6 AND NOT HAVE_FUNC_GETHOSTBYNAME_R_5)
85-
check_source_compiles(C [[
86-
#include <netdb.h>
73+
check_prototype_definition(
74+
gethostbyname_r
75+
"int gethostbyname_r(const char *name, struct hostent *htent, \
76+
struct hostent_data *data)"
77+
"0"
78+
netdb.h
79+
HAVE_FUNC_GETHOSTBYNAME_R_3
80+
)
81+
if(HAVE_FUNC_GETHOSTBYNAME_R_3)
82+
message(CHECK_PASS "three")
83+
return()
84+
endif()
8785

88-
int main(void) {
89-
char *name = "www.gnu.org";
90-
struct hostent ret;
91-
struct hostent_data data;
92-
(void)gethostbyname_r(name, &ret, &data);
86+
message(CHECK_FAIL "unknown")
87+
endfunction()
9388

94-
return 0;
95-
}
96-
]] HAVE_FUNC_GETHOSTBYNAME_R_3)
97-
endif()
89+
cmake_push_check_state(RESET)
90+
set(CMAKE_REQUIRED_QUIET TRUE)
91+
_php_check_gethostbyname_r()
9892
cmake_pop_check_state()
9993

10094
if(
101-
HAVE_FUNC_GETHOSTBYNAME_R_3
95+
HAVE_FUNC_GETHOSTBYNAME_R_6
10296
OR HAVE_FUNC_GETHOSTBYNAME_R_5
103-
OR HAVE_FUNC_GETHOSTBYNAME_R_6
97+
OR HAVE_FUNC_GETHOSTBYNAME_R_3
10498
)
10599
set(
106100
HAVE_GETHOSTBYNAME_R 1
107101
CACHE INTERNAL "Define to 1 if you have some form of gethostbyname_r()."
108102
)
109103
endif()
110-
111-
if(HAVE_FUNC_GETHOSTBYNAME_R_3)
112-
message(CHECK_PASS "three")
113-
elseif(HAVE_FUNC_GETHOSTBYNAME_R_5)
114-
message(CHECK_PASS "five")
115-
elseif(HAVE_FUNC_GETHOSTBYNAME_R_6)
116-
message(CHECK_PASS "six")
117-
else()
118-
message(CHECK_FAIL "can't tell")
119-
endif()

cmake/sapi/apache2handler/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ set_target_properties(
4343
OUTPUT_NAME apache
4444
)
4545

46+
target_compile_definitions(
47+
php_apache2handler
48+
PRIVATE
49+
ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
50+
)
51+
4652
find_package(Apache 2.0.44)
4753
set_package_properties(
4854
Apache

0 commit comments

Comments
 (0)