|
| 1 | +#[=============================================================================[ |
| 2 | +Check whether to enable Zend max execution timers. |
| 3 | +
|
| 4 | +## Cache variables |
| 5 | +
|
| 6 | +* [`ZEND_MAX_EXECUTION_TIMERS`](/docs/cmake/ZEND_MAX_EXECUTION_TIMERS.md) |
| 7 | +
|
| 8 | +* `HAVE_TIMER_CREATE` |
| 9 | +
|
| 10 | + Whether the system has `timer_create()`. |
| 11 | +
|
| 12 | +## Result variables |
| 13 | +
|
| 14 | +* `ZEND_MAX_EXECUTION_TIMERS` |
| 15 | +
|
| 16 | + A regular variable based on the cache variable and thread safety to be able to |
| 17 | + run consecutive configuration runs. When `ZEND_MAX_EXECUTION_TIMERS` cache |
| 18 | + variable is set to 'auto', regular variable default value is set to the |
| 19 | + `PHP_THREAD_SAFETY` value. |
| 20 | +
|
| 21 | +## INTERFACE IMPORTED library |
| 22 | +
|
| 23 | +* `Zend::MaxExecutionTimers` |
| 24 | +
|
| 25 | + Includes possible additional library to be linked for using `timer_create()` |
| 26 | + and a compile definition. |
| 27 | +#]=============================================================================] |
| 28 | + |
| 29 | +include_guard(GLOBAL) |
| 30 | + |
| 31 | +message(CHECK_START "Checking whether to enable Zend max execution timers") |
| 32 | + |
| 33 | +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 34 | + message(CHECK_FAIL "no") |
| 35 | + return() |
| 36 | +endif() |
| 37 | + |
| 38 | +include(PHP/SearchLibraries) |
| 39 | +include(FeatureSummary) |
| 40 | + |
| 41 | +set( |
| 42 | + ZEND_MAX_EXECUTION_TIMERS "auto" |
| 43 | + CACHE STRING "Enable Zend max execution timers" |
| 44 | +) |
| 45 | +mark_as_advanced(ZEND_MAX_EXECUTION_TIMERS) |
| 46 | +set_property( |
| 47 | + CACHE ZEND_MAX_EXECUTION_TIMERS |
| 48 | + PROPERTY STRINGS "auto" "ON" "OFF" |
| 49 | +) |
| 50 | + |
| 51 | +# Set a regular variable based on the cache variable. |
| 52 | +if(ZEND_MAX_EXECUTION_TIMERS STREQUAL "auto") |
| 53 | + set(ZEND_MAX_EXECUTION_TIMERS "${PHP_THREAD_SAFETY}") |
| 54 | +else() |
| 55 | + set(ZEND_MAX_EXECUTION_TIMERS "${ZEND_MAX_EXECUTION_TIMERS}") |
| 56 | +endif() |
| 57 | + |
| 58 | +if(ZEND_MAX_EXECUTION_TIMERS AND CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 59 | + php_search_libraries( |
| 60 | + timer_create |
| 61 | + HAVE_TIMER_CREATE |
| 62 | + HEADERS time.h |
| 63 | + LIBRARIES |
| 64 | + rt # Solaris <= 10, older Linux |
| 65 | + LIBRARY_VARIABLE libraryForTimerCreate |
| 66 | + ) |
| 67 | + |
| 68 | + if(NOT HAVE_TIMER_CREATE) |
| 69 | + set(ZEND_MAX_EXECUTION_TIMERS OFF) |
| 70 | + endif() |
| 71 | +else() |
| 72 | + set(ZEND_MAX_EXECUTION_TIMERS OFF) |
| 73 | +endif() |
| 74 | + |
| 75 | +if(ZEND_MAX_EXECUTION_TIMERS) |
| 76 | + message(CHECK_PASS "yes") |
| 77 | +else() |
| 78 | + message(CHECK_FAIL "no") |
| 79 | +endif() |
| 80 | + |
| 81 | +add_feature_info( |
| 82 | + "Zend max execution timers" |
| 83 | + ZEND_MAX_EXECUTION_TIMERS |
| 84 | + "enhanced timeout and signal handling" |
| 85 | +) |
| 86 | + |
| 87 | +# Set the result variable also in the PARENT_SCOPE, to make it available for the |
| 88 | +# parent project PHP in its configuration headers. This module is included in |
| 89 | +# the Zend engine which is added with add_subdirectory() in the PHP project. |
| 90 | +if(NOT PROJECT_IS_TOP_LEVEL) |
| 91 | + set(ZEND_MAX_EXECUTION_TIMERS ${ZEND_MAX_EXECUTION_TIMERS} PARENT_SCOPE) |
| 92 | +endif() |
| 93 | + |
| 94 | +add_library(Zend::MaxExecutionTimers INTERFACE IMPORTED) |
| 95 | +if(libraryForTimerCreate) |
| 96 | + target_link_libraries( |
| 97 | + Zend::MaxExecutionTimers |
| 98 | + INTERFACE |
| 99 | + ${libraryForTimerCreate} |
| 100 | + ) |
| 101 | +endif() |
| 102 | + |
| 103 | +# The configuration header with ZEND_MAX_EXECUTION_TIMERS might not be included |
| 104 | +# in some source files, therefore also compilation definitions is added. |
| 105 | +if(ZEND_MAX_EXECUTION_TIMERS) |
| 106 | + target_compile_definitions( |
| 107 | + Zend::MaxExecutionTimers |
| 108 | + INTERFACE |
| 109 | + ZEND_MAX_EXECUTION_TIMERS |
| 110 | + ) |
| 111 | +endif() |
0 commit comments