|
| 1 | +#[=============================================================================[ |
| 2 | +# PHP/Package/Oniguruma |
| 3 | +
|
| 4 | +Finds or downloads the Oniguruma library: |
| 5 | +
|
| 6 | +```cmake |
| 7 | +include(PHP/Package/Oniguruma) |
| 8 | +``` |
| 9 | +
|
| 10 | +Wrapper for finding the `Oniguruma` library. |
| 11 | +
|
| 12 | +Module first tries to find the `Oniguruma` library on the system. If not |
| 13 | +successful it tries to download it from the upstream source with |
| 14 | +`ExternalProject` module and build it together with the PHP build. |
| 15 | +
|
| 16 | +## Examples |
| 17 | +
|
| 18 | +Basic usage: |
| 19 | +
|
| 20 | +```cmake |
| 21 | +include(PHP/Package/Oniguruma) |
| 22 | +target_link_libraries(php_ext_foo PRIVATE Oniguruma::Oniguruma) |
| 23 | +``` |
| 24 | +#]=============================================================================] |
| 25 | + |
| 26 | +include(ExternalProject) |
| 27 | +include(FeatureSummary) |
| 28 | + |
| 29 | +# Minimum required version for the Oniguruma dependency. |
| 30 | +#set(PHP_ONIGURUMA_MIN_VERSION ?.?.??) |
| 31 | + |
| 32 | +# Download version when system dependency is not found. |
| 33 | +set(PHP_ONIGURUMA_DOWNLOAD_VERSION 6.9.10) |
| 34 | + |
| 35 | +if(TARGET Oniguruma::Oniguruma) |
| 36 | + set(Oniguruma_FOUND TRUE) |
| 37 | + get_property(Oniguruma_DOWNLOADED GLOBAL PROPERTY _PHP_Oniguruma_DOWNLOADED) |
| 38 | + set(PHP_ONIG_KOI8 FALSE) |
| 39 | + return() |
| 40 | +endif() |
| 41 | + |
| 42 | +find_package(Oniguruma ${PHP_ONIGURUMA_MIN_VERSION}) |
| 43 | + |
| 44 | +if(NOT Oniguruma_FOUND) |
| 45 | + message( |
| 46 | + STATUS |
| 47 | + "Oniguruma ${PHP_ONIGURUMA_DOWNLOAD_VERSION} will be downloaded at build phase" |
| 48 | + ) |
| 49 | + |
| 50 | + set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>") |
| 51 | + |
| 52 | + list( |
| 53 | + APPEND |
| 54 | + options |
| 55 | + -DINSTALL_DOCUMENTATION=OFF |
| 56 | + -DBUILD_TEST=OFF |
| 57 | + -DBUILD_SHARED_LIBS=OFF |
| 58 | + ) |
| 59 | + |
| 60 | + ExternalProject_Add( |
| 61 | + Oniguruma |
| 62 | + STEP_TARGETS build install |
| 63 | + URL |
| 64 | + https://github.com/petk/oniguruma/archive/refs/tags/v${PHP_ONIGURUMA_DOWNLOAD_VERSION}.tar.gz |
| 65 | + CMAKE_ARGS ${options} |
| 66 | + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/oniguruma-installation |
| 67 | + INSTALL_BYPRODUCTS <INSTALL_DIR>/lib/libonig${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 68 | + ) |
| 69 | + |
| 70 | + # Move dependency to PACKAGES_FOUND. |
| 71 | + block() |
| 72 | + get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND) |
| 73 | + list(REMOVE_ITEM packagesNotFound Oniguruma) |
| 74 | + set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound) |
| 75 | + get_cmake_property(packagesFound PACKAGES_FOUND) |
| 76 | + set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND Oniguruma) |
| 77 | + endblock() |
| 78 | + |
| 79 | + ExternalProject_Get_Property(Oniguruma INSTALL_DIR) |
| 80 | + |
| 81 | + # Bypass issue with non-existing include directory for the imported target. |
| 82 | + file(MAKE_DIRECTORY ${INSTALL_DIR}/include) |
| 83 | + |
| 84 | + add_library(Oniguruma::Oniguruma STATIC IMPORTED GLOBAL) |
| 85 | + set_target_properties( |
| 86 | + Oniguruma::Oniguruma |
| 87 | + PROPERTIES |
| 88 | + IMPORTED_LOCATION "${INSTALL_DIR}/lib/libonig${CMAKE_STATIC_LIBRARY_SUFFIX}" |
| 89 | + INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include" |
| 90 | + ) |
| 91 | + add_dependencies(Oniguruma::Oniguruma Oniguruma-install) |
| 92 | + |
| 93 | + # Mark package as found. |
| 94 | + set(Oniguruma_FOUND TRUE) |
| 95 | + |
| 96 | + define_property( |
| 97 | + GLOBAL |
| 98 | + PROPERTY _PHP_Oniguruma_DOWNLOADED |
| 99 | + BRIEF_DOCS "Marker that Oniguruma library will be downloaded" |
| 100 | + ) |
| 101 | + |
| 102 | + set_property(GLOBAL PROPERTY _PHP_Oniguruma_DOWNLOADED TRUE) |
| 103 | + set(Oniguruma_DOWNLOADED TRUE) |
| 104 | + |
| 105 | + set(PHP_ONIG_KOI8 FALSE) |
| 106 | +endif() |
0 commit comments