Skip to content

Commit 996b4ec

Browse files
committed
Use ExternalProject module
1 parent f430082 commit 996b4ec

File tree

12 files changed

+306
-262
lines changed

12 files changed

+306
-262
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
libcurl4-openssl-dev \
6464
libdb5.3++-dev \
6565
libenchant-2-dev \
66-
libpng-dev \
6766
libgmp-dev \
6867
libc-client-dev \
6968
libkrb5-dev \
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#[=============================================================================[
2+
# PHP/Package/PNG
3+
4+
Finds or downloads the PNG library:
5+
6+
```cmake
7+
include(PHP/Package/PNG)
8+
```
9+
10+
Wrapper for finding the `PNG` library.
11+
12+
Module first tries to find the `PNG` 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+
See: https://cmake.org/cmake/help/latest/module/FindPNG.html
17+
18+
## Examples
19+
20+
Basic usage:
21+
22+
```cmake
23+
include(PHP/Package/PNG)
24+
target_link_libraries(php_ext_foo PRIVATE PNG::PNG)
25+
```
26+
#]=============================================================================]
27+
28+
include(ExternalProject)
29+
include(FeatureSummary)
30+
31+
set_package_properties(
32+
PNG
33+
PROPERTIES
34+
URL "http://libpng.org"
35+
DESCRIPTION "Portable Network Graphics (PNG image format) library"
36+
)
37+
38+
# Minimum required version for the PNG dependency.
39+
set(PHP_PNG_MIN_VERSION 0.96) # for png_get_IHDR
40+
41+
# Download version when system dependency is not found.
42+
set(PHP_PNG_DOWNLOAD_VERSION 1.6.50)
43+
44+
find_package(PNG ${PHP_PNG_MIN_VERSION})
45+
46+
if(NOT PNG_FOUND)
47+
message(
48+
STATUS
49+
"PNG ${PHP_PNG_DOWNLOAD_VERSION} will be downloaded at build phase"
50+
)
51+
52+
include(PHP/Package/ZLIB)
53+
54+
set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
55+
56+
if(ZLIB_DOWNLOADED)
57+
ExternalProject_Get_Property(ZLIB INSTALL_DIR)
58+
list(APPEND options "-DCMAKE_PREFIX_PATH=${INSTALL_DIR}")
59+
endif()
60+
61+
list(APPEND options -DPNG_TESTS=OFF)
62+
63+
ExternalProject_Add(
64+
PNG
65+
STEP_TARGETS build install
66+
URL
67+
https://download.sourceforge.net/libpng/libpng-${PHP_PNG_DOWNLOAD_VERSION}.tar.gz
68+
CMAKE_ARGS ${options}
69+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/png-installation
70+
INSTALL_BYPRODUCTS <INSTALL_DIR>/lib/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
71+
)
72+
73+
add_dependencies(PNG ZLIB::ZLIB)
74+
75+
# Move dependency to PACKAGES_FOUND.
76+
block()
77+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
78+
list(REMOVE_ITEM packagesNotFound PNG)
79+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
80+
get_cmake_property(packagesFound PACKAGES_FOUND)
81+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND PNG)
82+
endblock()
83+
84+
ExternalProject_Get_Property(PNG INSTALL_DIR)
85+
86+
# Bypass issue with non-existing include directory for the imported target.
87+
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
88+
89+
add_library(PNG::PNG STATIC IMPORTED GLOBAL)
90+
set_target_properties(
91+
PNG::PNG
92+
PROPERTIES
93+
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}"
94+
INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include"
95+
)
96+
add_dependencies(PNG::PNG PNG-install)
97+
98+
# Mark package as found.
99+
set(PNG_FOUND TRUE)
100+
endif()
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#[=============================================================================[
2+
# PHP/Package/Zlib
3+
4+
Finds or downloads the zlib library:
5+
6+
```cmake
7+
include(PHP/Package/Zlib)
8+
```
9+
10+
This module is a wrapper for finding the `ZLIB` library. It first tries to find
11+
the `ZLIB` library on the system. If not successful it tries to download it from
12+
the upstream source with `ExternalProject` module and builds it together with
13+
the PHP build.
14+
15+
See: https://cmake.org/cmake/help/latest/module/FindZLIB.html
16+
17+
## Examples
18+
19+
Basic usage:
20+
21+
```cmake
22+
include(PHP/Package/ZLIB)
23+
target_link_libraries(php_ext_foo PRIVATE ZLIB::ZLIB)
24+
```
25+
#]=============================================================================]
26+
27+
include(FeatureSummary)
28+
include(ExternalProject)
29+
30+
set_package_properties(
31+
ZLIB
32+
PROPERTIES
33+
URL "https://zlib.net/"
34+
DESCRIPTION "Compression library"
35+
)
36+
37+
# Minimum required version for the zlib dependency.
38+
set(PHP_ZLIB_MIN_VERSION 1.2.0.4)
39+
40+
# Download version when system dependency is not found.
41+
set(PHP_ZLIB_DOWNLOAD_VERSION 1.3.1)
42+
43+
if(TARGET ZLIB::ZLIB)
44+
set(ZLIB_FOUND TRUE)
45+
get_property(ZLIB_DOWNLOADED GLOBAL PROPERTY _PHP_ZLIB_DOWNLOADED)
46+
return()
47+
endif()
48+
49+
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
50+
51+
if(NOT ZLIB_FOUND)
52+
message(
53+
STATUS
54+
"ZLIB ${PHP_ZLIB_DOWNLOAD_VERSION} will be downloaded at build phase"
55+
)
56+
57+
set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
58+
59+
if(PHP_ZLIB_DOWNLOAD_VERSION VERSION_LESS_EQUAL 1.3.1)
60+
list(APPEND options -DZLIB_BUILD_EXAMPLES=OFF)
61+
endif()
62+
63+
if(PHP_ZLIB_DOWNLOAD_VERSION VERSION_GREATER 1.3.1)
64+
list(APPEND options -DZLIB_BUILD_TESTING=OFF)
65+
endif()
66+
67+
ExternalProject_Add(
68+
ZLIB
69+
STEP_TARGETS build install
70+
URL
71+
https://github.com/madler/zlib/releases/download/v${PHP_ZLIB_DOWNLOAD_VERSION}/zlib-${PHP_ZLIB_DOWNLOAD_VERSION}.tar.gz
72+
CMAKE_ARGS ${options}
73+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/zlib-installation
74+
INSTALL_BYPRODUCTS <INSTALL_DIR>/lib/libz${CMAKE_STATIC_LIBRARY_SUFFIX}
75+
)
76+
77+
# Move dependency to PACKAGES_FOUND.
78+
block()
79+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
80+
list(REMOVE_ITEM packagesNotFound ZLIB)
81+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
82+
get_cmake_property(packagesFound PACKAGES_FOUND)
83+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ZLIB)
84+
endblock()
85+
86+
ExternalProject_Get_Property(ZLIB INSTALL_DIR)
87+
88+
# Bypass issue with non-existing include directory for the imported target.
89+
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
90+
91+
add_library(ZLIB::ZLIB STATIC IMPORTED GLOBAL)
92+
set_target_properties(
93+
ZLIB::ZLIB
94+
PROPERTIES
95+
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libz${CMAKE_STATIC_LIBRARY_SUFFIX}"
96+
INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include"
97+
)
98+
add_dependencies(ZLIB::ZLIB ZLIB-install)
99+
100+
# Mark package as found.
101+
set(ZLIB_FOUND TRUE)
102+
103+
define_property(
104+
GLOBAL
105+
PROPERTY _PHP_ZLIB_DOWNLOADED
106+
BRIEF_DOCS "Configuration header code with system extensions definitions"
107+
)
108+
109+
set_property(GLOBAL PROPERTY _PHP_ZLIB_DOWNLOADED TRUE)
110+
set(ZLIB_DOWNLOADED TRUE)
111+
endif()
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#[=============================================================================[
2+
# PHP/Package/libzip
3+
4+
Finds and downloads `libzip` library:
5+
6+
```cmake
7+
include(PHP/Package/libzip
8+
```
9+
10+
This module first tries to find the `libzip` library on the system. If not
11+
successful it tries to download it from the upstream source with
12+
`ExternalProject` module and build it together with the PHP build.
13+
14+
## Examples
15+
16+
Basic usage:
17+
18+
```cmake
19+
include(PHP/Package/libzip
20+
target_link_libraries(php_ext_foo PRIVATE libzip::libzip)
21+
```
22+
#]=============================================================================]
23+
24+
include(FeatureSummary)
25+
include(FetchContent)
26+
27+
set_package_properties(
28+
libzip
29+
PROPERTIES
30+
URL "https://libzip.org/"
31+
DESCRIPTION "Library for reading and writing ZIP compressed archives"
32+
)
33+
34+
# Minimum required version for the libzip dependency.
35+
set(PHP_libzip_MIN_VERSION 1.7.1)
36+
37+
# Download version when system dependency is not found.
38+
set(PHP_libzip_DOWNLOAD_VERSION 1.11.2)
39+
40+
find_package(libzip ${PHP_libzip_MIN_VERSION})
41+
42+
if(NOT libzip_FOUND)
43+
include(PHP/Package/ZLIB)
44+
45+
set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
46+
47+
if(ZLIB_DOWNLOADED)
48+
ExternalProject_Get_Property(ZLIB INSTALL_DIR)
49+
list(APPEND options "-DCMAKE_PREFIX_PATH=${INSTALL_DIR}")
50+
endif()
51+
52+
ExternalProject_Add(
53+
libzip
54+
STEP_TARGETS build install
55+
URL
56+
https://github.com/nih-at/libzip/releases/download/v${PHP_libzip_DOWNLOAD_VERSION}/libzip-${PHP_libzip_DOWNLOAD_VERSION}.tar.gz
57+
CMAKE_ARGS ${options}
58+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/libzip-installation
59+
INSTALL_BYPRODUCTS <INSTALL_DIR>/lib/libzip${CMAKE_STATIC_LIBRARY_SUFFIX}
60+
)
61+
62+
add_dependencies(libzip ZLIB::ZLIB)
63+
64+
# Move dependency to PACKAGES_FOUND.
65+
block()
66+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
67+
list(REMOVE_ITEM packagesNotFound libzip)
68+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
69+
get_cmake_property(packagesFound PACKAGES_FOUND)
70+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND libzip)
71+
endblock()
72+
73+
ExternalProject_Get_Property(libzip INSTALL_DIR)
74+
75+
# Bypass issue with non-existing include directory for the imported target.
76+
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
77+
78+
add_library(libzip::libzip STATIC IMPORTED GLOBAL)
79+
set_target_properties(
80+
libzip::libzip
81+
PROPERTIES
82+
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libzip${CMAKE_STATIC_LIBRARY_SUFFIX}"
83+
INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include"
84+
)
85+
add_dependencies(libzip::libzip libzip-install)
86+
87+
# Mark package as found.
88+
set(libzip_FOUND TRUE)
89+
endif()

cmake/cmake/modules/Packages/LibXml2.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ FetchContent_Declare(
5454
find_package(LibXml2 ${PHP_LIBXML2_MIN_VERSION})
5555

5656
if(NOT LibXml2_FOUND)
57-
include(Packages/ZLIB)
57+
include(PHP/Package/ZLIB)
5858

5959
set(FETCHCONTENT_QUIET NO)
6060
set(LIBXML2_WITH_PYTHON OFF)

0 commit comments

Comments
 (0)