Skip to content

Commit c3b32df

Browse files
committed
Replace CheckPrototypeDefinition with CheckSourceCompiles
This module might cause issues on strictly configured compilers: https://gitlab.kitware.com/cmake/cmake/-/issues/27310 Instead of complicating checks, a compilation check can be performed instead.
1 parent fb6c58e commit c3b32df

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

cmake/cmake/checks/CheckGethostbynameR.cmake

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See also:
2121
https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
2222
#]=============================================================================]
2323

24-
include(CheckPrototypeDefinition)
24+
include(CheckSourceCompiles)
2525
include(CMakePushCheckState)
2626
include(PHP/SearchLibraries)
2727

@@ -61,44 +61,53 @@ function(_php_check_gethostbyname_r)
6161
set(CMAKE_REQUIRED_QUIET TRUE)
6262

6363
# Check for 6 arguments signature.
64-
check_prototype_definition(
65-
gethostbyname_r
66-
"int gethostbyname_r(const char *name, struct hostent *ret, char *buf, \
67-
size_t buflen, struct hostent **result, int *h_errnop)"
68-
"0"
69-
netdb.h
70-
PHP_HAVE_FUNC_GETHOSTBYNAME_R_6
71-
)
64+
check_source_compiles(C [[
65+
#include <netdb.h>
66+
int gethostbyname_r(
67+
const char *name,
68+
struct hostent *ret,
69+
char *buf,
70+
size_t buflen,
71+
struct hostent **result,
72+
int *h_errnop
73+
);
74+
int main(void) { return 0; }
75+
]] PHP_HAVE_FUNC_GETHOSTBYNAME_R_6)
76+
7277
if(PHP_HAVE_FUNC_GETHOSTBYNAME_R_6)
7378
cmake_pop_check_state()
7479
message(CHECK_PASS "six")
7580
return()
7681
endif()
7782

7883
# Check for 5 arguments signature.
79-
check_prototype_definition(
80-
gethostbyname_r
81-
"struct hostent *gethostbyname_r(const char *name, struct hostent *result, \
82-
char *buffer, int buflen, int *h_errnop)"
83-
"0"
84-
netdb.h
85-
PHP_HAVE_FUNC_GETHOSTBYNAME_R_5
86-
)
84+
check_source_compiles(C [[
85+
#include <netdb.h>
86+
struct hostent *gethostbyname_r(
87+
const char *name,
88+
struct hostent *result,
89+
char *buffer,
90+
int buflen,
91+
int *h_errnop
92+
);
93+
int main(void) { return 0; }
94+
]] PHP_HAVE_FUNC_GETHOSTBYNAME_R_5)
8795
if(PHP_HAVE_FUNC_GETHOSTBYNAME_R_5)
8896
cmake_pop_check_state()
8997
message(CHECK_PASS "five")
9098
return()
9199
endif()
92100

93101
# Check for 3 arguments signature.
94-
check_prototype_definition(
95-
gethostbyname_r
96-
"int gethostbyname_r(const char *name, struct hostent *htent, \
97-
struct hostent_data *data)"
98-
"0"
99-
netdb.h
100-
PHP_HAVE_FUNC_GETHOSTBYNAME_R_3
101-
)
102+
check_source_compiles(C [[
103+
#include <netdb.h>
104+
int gethostbyname_r(
105+
const char *name,
106+
struct hostent *htent,
107+
struct hostent_data *data
108+
);
109+
int main(void) { return 0; }
110+
]] PHP_HAVE_FUNC_GETHOSTBYNAME_R_3)
102111
if(PHP_HAVE_FUNC_GETHOSTBYNAME_R_3)
103112
cmake_pop_check_state()
104113
message(CHECK_PASS "three")

cmake/ext/iconv/CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ project(
2828
LANGUAGES C
2929
)
3030

31-
include(CheckPrototypeDefinition)
31+
include(CheckSourceCompiles)
3232
include(CheckSourceRuns)
3333
include(CheckSymbolExists)
3434
include(CMakeDependentOption)
@@ -288,14 +288,17 @@ if(TARGET Iconv::Iconv)
288288
cmake_push_check_state(RESET)
289289
set(CMAKE_REQUIRED_LIBRARIES Iconv::Iconv)
290290

291-
check_prototype_definition(
292-
iconv
293-
"size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, \
294-
size_t *dstleft)"
295-
"0"
296-
"iconv.h"
297-
PHP_EXT_ICONV_CONST
298-
)
291+
check_source_compiles(C [[
292+
#include <iconv.h>
293+
size_t iconv(
294+
iconv_t cd,
295+
const char **src,
296+
size_t *srcleft,
297+
char **dst,
298+
size_t *dstleft
299+
);
300+
int main(void) { return 0; }
301+
]] PHP_EXT_ICONV_CONST)
299302
cmake_pop_check_state()
300303

301304
if(PHP_EXT_ICONV_CONST)

cmake/ext/posix/cmake/CheckTtynameR.cmake

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ On modern systems a simpler check is sufficient in the future:
1010
check_symbol_exists(ttyname_r unistd.h <result-var>)
1111
#]=============================================================================]
1212

13-
include(CheckPrototypeDefinition)
13+
include(CheckSourceCompiles)
1414
include(CheckSourceRuns)
1515
include(CMakePushCheckState)
1616
include(PHP/SystemExtensions)
@@ -41,13 +41,11 @@ function(_php_ext_posix_check_ttyname_r result)
4141
# - _DARWIN_C_SOURCE on older Mac OS X 10.4
4242
set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
4343

44-
check_prototype_definition(
45-
ttyname_r
46-
"int ttyname_r(int fd, char *buf, size_t buflen)"
47-
"0"
48-
"unistd.h"
49-
PHP_EXT_POSIX_HAVE_TTYNAME_R_SYMBOL
50-
)
44+
check_source_compiles(C [[
45+
#include <unistd.h>
46+
int ttyname_r(int fd, char *buf, size_t buflen);
47+
int main(void) { return 0; }
48+
]] PHP_EXT_POSIX_HAVE_TTYNAME_R_SYMBOL)
5149

5250
if(NOT PHP_EXT_POSIX_HAVE_TTYNAME_R_SYMBOL)
5351
message(CHECK_FAIL "no (non-standard declaration)")

0 commit comments

Comments
 (0)