Skip to content

Commit 04c8125

Browse files
committed
Refactor compiler inline keyword check
1 parent 7b967b2 commit 04c8125

File tree

4 files changed

+90
-100
lines changed

4 files changed

+90
-100
lines changed

cmake/cmake/ConfigureChecks.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ php_check_builtin(__builtin_ssubl_overflow PHP_HAVE_BUILTIN_SSUBL_OVERFLOW)
255255
php_check_builtin(__builtin_ssubll_overflow PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW)
256256
php_check_builtin(__builtin_usub_overflow PHP_HAVE_BUILTIN_USUB_OVERFLOW)
257257

258-
################################################################################
259-
# Check compiler characteristics.
260-
################################################################################
261-
262-
# Check compiler inline keyword.
263-
include(PHP/CheckInline)
264-
265258
################################################################################
266259
# Check functions.
267260
################################################################################
@@ -416,6 +409,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckFlushIo.cmake)
416409
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckFopencookie.cmake)
417410
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckGetaddrinfo.cmake)
418411
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckGethostbynameR.cmake)
412+
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckInline.cmake)
419413
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckIPv6.cmake)
420414
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckReentrantFunctions.cmake)
421415
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckWrite.cmake)

cmake/cmake/checks/CheckInline.cmake

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#[=============================================================================[
2+
Check if compiler supports 'inline', '__inline__', or '__inline' keyword.
3+
4+
The 'inline' keyword is part of the C99 standard and all decent compilers should
5+
have it. See also Autoconf's 'AC_C_INLINE' and 'AX_C99_INLINE' macros.
6+
7+
If compiler doesn't support any of the inline keywords, then an empty definition
8+
needs to be used so the code compiles as a workaround.
9+
10+
Result/cache variables:
11+
12+
* PHP_INLINE_KEYWORD_CODE - Header definition line that sets the compiler's
13+
'inline' keyword.
14+
#]=============================================================================]
15+
16+
include_guard(GLOBAL)
17+
18+
include(CheckSourceCompiles)
19+
include(CMakePushCheckState)
20+
21+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
22+
set(PHP_INLINE_KEYWORD_CODE "/* #undef inline */")
23+
return()
24+
endif()
25+
26+
function(_php_check_inline result)
27+
set(${result} "")
28+
29+
message(CHECK_START "Checking C compiler inline keyword")
30+
31+
foreach(keyword "inline" "__inline__" "__inline")
32+
cmake_push_check_state(RESET)
33+
set(CMAKE_REQUIRED_DEFINITIONS -Dinline=${keyword})
34+
set(CMAKE_REQUIRED_QUIET TRUE)
35+
36+
check_source_compiles(C [[
37+
#ifndef __cplusplus
38+
typedef int foo_t;
39+
static inline foo_t static_foo(void) { return 0; }
40+
inline foo_t foo(void) { return 0; }
41+
#endif
42+
43+
int main(void) { return 0; }
44+
]] PHP_HAS_${keyword})
45+
cmake_pop_check_state()
46+
47+
if(PHP_HAS_inline)
48+
message(CHECK_PASS "inline")
49+
50+
set(${result} "/* #undef inline */")
51+
52+
return(PROPAGATE ${result})
53+
endif()
54+
55+
if(PHP_HAS_${keyword})
56+
message(CHECK_PASS "${keyword}")
57+
58+
set(${result} "#define inline ${keyword}")
59+
60+
return(PROPAGATE ${result})
61+
endif()
62+
endforeach()
63+
64+
if(NOT ${result})
65+
message(CHECK_FAIL "not supported")
66+
message(WARNING "Compiler doesn't support the C99 standard inline keyword")
67+
68+
set(${result} "#define inline")
69+
70+
return(PROPAGATE ${result})
71+
endif()
72+
endfunction()
73+
74+
if(NOT DEFINED PHP_INLINE_KEYWORD_CODE)
75+
_php_check_inline(PHP_INLINE_KEYWORD_CODE)
76+
77+
set(
78+
PHP_INLINE_KEYWORD_CODE
79+
"${PHP_INLINE_KEYWORD_CODE}"
80+
CACHE INTERNAL
81+
"Compiler inline keyword definition."
82+
)
83+
endif()

cmake/cmake/modules/PHP/CheckInline.cmake

Lines changed: 0 additions & 87 deletions
This file was deleted.

cmake/main/cmake/php_config.h.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@
667667
/* Define to 1 when using musl libc. */
668668
#cmakedefine __MUSL__ 1
669669

670+
/* Define to '__inline__' or '__inline' if that's what the C compiler
671+
calls it, or to nothing if 'inline' is not supported under any name. */
672+
#ifndef __cplusplus
673+
@PHP_INLINE_KEYWORD_CODE@
674+
#endif
675+
670676
/*****************************************************************************
671677
PHP SAPIs configuration
672678
****************************************************************************/
@@ -695,12 +701,6 @@
695701
/* Define to 'int' if <sys/types.h> doesn't define. */
696702
# cmakedefine gid_t @gid_t@
697703

698-
/* Define to '__inline__' or '__inline' if that's what the C compiler
699-
calls it, or to nothing if 'inline' is not supported under any name. */
700-
# ifndef __cplusplus
701-
@INLINE_KEYWORD_DEFINITION@
702-
# endif
703-
704704
/* Define to 'int' if <sys/types.h> doesn't define. */
705705
# cmakedefine uid_t @uid_t@
706706

0 commit comments

Comments
 (0)