|
| 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() |
0 commit comments