Skip to content

Commit 5181ddd

Browse files
committed
Download Oniguruma
1 parent a9be8e0 commit 5181ddd

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,11 @@ jobs:
7878
firebird-dev \
7979
libsodium-dev \
8080
libicu-dev \
81-
libzip-dev \
8281
aspell \
8382
libaspell-dev \
8483
libavif-dev \
8584
libwebp-dev \
8685
libxpm-dev \
87-
libonig-dev \
8886
libtidy-dev \
8987
libargon2-dev \
9088
libxslt1-dev \
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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()

cmake/cmake/modules/PHP/Package/ZLIB.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if(NOT ZLIB_FOUND)
103103
define_property(
104104
GLOBAL
105105
PROPERTY _PHP_ZLIB_DOWNLOADED
106-
BRIEF_DOCS "Configuration header code with system extensions definitions"
106+
BRIEF_DOCS "Marker that zlib library will be downloaded"
107107
)
108108

109109
set_property(GLOBAL PROPERTY _PHP_ZLIB_DOWNLOADED TRUE)

cmake/ext/mbstring/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libmbfl/config.h "\n" [[
130130
################################################################################
131131

132132
if(PHP_EXT_MBSTRING_MBREGEX)
133-
find_package(Oniguruma)
133+
include(PHP/Package/Oniguruma)
134134
set_package_properties(
135135
Oniguruma
136136
PROPERTIES

0 commit comments

Comments
 (0)