Skip to content

Commit c6a7af3

Browse files
committed
Add ZLIB with FetchContent
1 parent 35a152b commit c6a7af3

File tree

10 files changed

+263
-17
lines changed

10 files changed

+263
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ jobs:
107107
libsasl2-dev \
108108
libpq-dev \
109109
libmm-dev \
110-
zlib1g-dev \
111110
libdmalloc-dev \
112111
dovecot-core \
113112
dovecot-pop3d \

cmake/cmake/Configuration.cmake

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ set(PHP_SQLITE_MIN_VERSION 3.7.7)
205205
# Minimum required version for the PostgreSQL dependency.
206206
set(PHP_POSTGRESQL_MIN_VERSION 9.1)
207207

208-
# Minimum required version for the zlib dependency.
209-
set(PHP_ZLIB_MIN_VERSION 1.2.0.4)
210-
211208
# Additional metadata for external packages to avoid duplication.
212209
set_package_properties(
213210
BZip2
@@ -251,13 +248,6 @@ set_package_properties(
251248
DESCRIPTION "SQL database engine library"
252249
)
253250

254-
set_package_properties(
255-
ZLIB
256-
PROPERTIES
257-
URL "https://zlib.net/"
258-
DESCRIPTION "Compression library"
259-
)
260-
261251
# Set base directory for ExternalProject CMake module.
262252
set_directory_properties(
263253
PROPERTIES EP_BASE ${PHP_BINARY_DIR}/CMakeFiles/PHP/ExternalProject

cmake/cmake/modules/Packages/LibXml2.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ FetchContent_Declare(
5454
find_package(LibXml2 ${PHP_LIBXML2_MIN_VERSION})
5555

5656
if(NOT LibXml2_FOUND)
57+
include(Packages/ZLIB)
58+
5759
set(FETCHCONTENT_QUIET NO)
5860
set(LIBXML2_WITH_PYTHON OFF)
5961
set(LIBXML2_WITH_LZMA OFF)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#[=============================================================================[
2+
Wrapper for finding the `PNG` library.
3+
4+
Module first tries to find the `PNG` library on the system. If not
5+
successful it tries to download it from the upstream source with `FetchContent`
6+
module and build it together with the PHP build.
7+
8+
See: https://cmake.org/cmake/help/latest/module/FindPNG.html
9+
10+
The `FetchContent` CMake module does things differently compared to the
11+
`find_package()` flow:
12+
* By default, it uses `QUIET` in its `find_package()` call when calling the
13+
`FetchContent_MakeAvailable()`;
14+
* When using `FeatureSummary`, dependencies must be moved manually to
15+
`PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property;
16+
17+
TODO: Improve this. This is for now only initial `FetchContent` integration for
18+
testing purposes and will be changed in the future.
19+
#]=============================================================================]
20+
21+
include(FeatureSummary)
22+
include(FetchContent)
23+
24+
set_package_properties(
25+
PNG
26+
PROPERTIES
27+
URL "http://libpng.org"
28+
DESCRIPTION "Portable Network Graphics (PNG image format) library"
29+
)
30+
31+
# Minimum required version for the PNG dependency.
32+
#set(PHP_PNG_MIN_VERSION ?.?.??)
33+
34+
# Download version when system dependency is not found.
35+
set(PHP_PNG_DOWNLOAD_VERSION 1.6.44)
36+
37+
FetchContent_Declare(
38+
PNG
39+
URL https://download.sourceforge.net/libpng/libpng-${PHP_PNG_DOWNLOAD_VERSION}.tar.gz
40+
EXCLUDE_FROM_ALL
41+
SYSTEM
42+
FIND_PACKAGE_ARGS
43+
)
44+
45+
find_package(PNG ${PHP_PNG_MIN_VERSION})
46+
47+
if(NOT PNG_FOUND)
48+
include(Packages/ZLIB)
49+
50+
set(FETCHCONTENT_QUIET NO)
51+
52+
# The above EXCLUDE_FROM_ALL was introduced in CMake 3.28.
53+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
54+
FetchContent_MakeAvailable(PNG)
55+
else()
56+
FetchContent_GetProperties(PNG)
57+
if(NOT PNG_POPULATED)
58+
FetchContent_Populate(PNG)
59+
60+
add_subdirectory(
61+
${PNG_SOURCE_DIR}
62+
${PNG_BINARY_DIR}
63+
EXCLUDE_FROM_ALL
64+
)
65+
endif()
66+
endif()
67+
68+
# Move dependency to PACKAGES_FOUND.
69+
block()
70+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
71+
list(REMOVE_ITEM packagesNotFound PNG)
72+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
73+
get_cmake_property(packagesFound PACKAGES_FOUND)
74+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND PNG)
75+
endblock()
76+
77+
# Mark package as found.
78+
set(PNG_FOUND TRUE)
79+
80+
# Clean used variables.
81+
unset(FETCHCONTENT_QUIET)
82+
endif()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#[=============================================================================[
2+
Wrapper for finding the `ZLIB` library.
3+
4+
Module first tries to find the `ZLIB` library on the system. If not successful
5+
it tries to download it from the upstream source with `FetchContent` module and
6+
build it together with the PHP build.
7+
8+
See: https://cmake.org/cmake/help/latest/module/FindZLIB.html
9+
10+
The `FetchContent` CMake module does things differently compared to the
11+
`find_package()` flow:
12+
* By default, it uses `QUIET` in its `find_package()` call when calling the
13+
`FetchContent_MakeAvailable()`
14+
* When using `FeatureSummary`, dependencies must be moved manually to
15+
`PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property
16+
17+
TODO: Improve this. This is for now only initial `FetchContent` integration for
18+
testing purposes and will be changed in the future.
19+
#]=============================================================================]
20+
21+
include(FeatureSummary)
22+
include(FetchContent)
23+
24+
set_package_properties(
25+
ZLIB
26+
PROPERTIES
27+
URL "https://zlib.net/"
28+
DESCRIPTION "Compression library"
29+
)
30+
31+
# Minimum required version for the zlib dependency.
32+
set(PHP_ZLIB_MIN_VERSION 1.2.0.4)
33+
34+
# Download version when system dependency is not found.
35+
set(PHP_ZLIB_DOWNLOAD_VERSION 1.3.1)
36+
37+
FetchContent_Declare(
38+
ZLIB
39+
URL https://github.com/madler/zlib/releases/download/v${PHP_ZLIB_DOWNLOAD_VERSION}/zlib-${PHP_ZLIB_DOWNLOAD_VERSION}.tar.gz
40+
EXCLUDE_FROM_ALL
41+
SYSTEM
42+
FIND_PACKAGE_ARGS
43+
)
44+
45+
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
46+
47+
if(NOT ZLIB_FOUND)
48+
set(FETCHCONTENT_QUIET NO)
49+
50+
# The above EXCLUDE_FROM_ALL was introduced in CMake 3.28.
51+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
52+
FetchContent_MakeAvailable(ZLIB)
53+
else()
54+
FetchContent_GetProperties(ZLIB)
55+
if(NOT ZLIB_POPULATED)
56+
FetchContent_Populate(ZLIB)
57+
58+
add_subdirectory(
59+
${zlib_SOURCE_DIR}
60+
${zlib_BINARY_DIR}
61+
EXCLUDE_FROM_ALL
62+
)
63+
endif()
64+
endif()
65+
66+
# Move dependency to PACKAGES_FOUND.
67+
block()
68+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
69+
list(REMOVE_ITEM packagesNotFound ZLIB)
70+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
71+
get_cmake_property(packagesFound PACKAGES_FOUND)
72+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ZLIB)
73+
endblock()
74+
75+
set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
76+
add_library(ZLIB::ZLIB INTERFACE IMPORTED GLOBAL)
77+
target_link_libraries(ZLIB::ZLIB INTERFACE zlibstatic)
78+
target_include_directories(
79+
zlibstatic
80+
PUBLIC
81+
$<BUILD_INTERFACE:${zlib_BINARY_DIR}>
82+
$<INSTALL_INTERFACE:include>
83+
)
84+
85+
# Mark package as found.
86+
set(ZLIB_FOUND TRUE)
87+
88+
# Clean used variables.
89+
unset(FETCHCONTENT_QUIET)
90+
endif()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#[=============================================================================[
2+
Wrapper for finding the `libzip` library.
3+
4+
Module first tries to find the `libzip` library on the system. If not
5+
successful it tries to download it from the upstream source with `FetchContent`
6+
module and build it together with the PHP build.
7+
8+
The `FetchContent` CMake module does things differently compared to the
9+
`find_package()` flow:
10+
* By default, it uses `QUIET` in its `find_package()` call when calling the
11+
`FetchContent_MakeAvailable()`;
12+
* When using `FeatureSummary`, dependencies must be moved manually to
13+
`PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property;
14+
15+
TODO: Improve this. This is for now only initial `FetchContent` integration for
16+
testing purposes and will be changed in the future.
17+
#]=============================================================================]
18+
19+
include(FeatureSummary)
20+
include(FetchContent)
21+
22+
set_package_properties(
23+
libzip
24+
PROPERTIES
25+
URL "https://libzip.org/"
26+
DESCRIPTION "Library for reading and writing ZIP compressed archives"
27+
)
28+
29+
# Minimum required version for the libzip dependency.
30+
set(PHP_libzip_MIN_VERSION 1.7.1)
31+
32+
# Download version when system dependency is not found.
33+
set(PHP_libzip_DOWNLOAD_VERSION 1.11.2)
34+
35+
FetchContent_Declare(
36+
libzip
37+
URL https://github.com/nih-at/libzip/releases/download/v${PHP_libzip_DOWNLOAD_VERSION}/libzip-${PHP_libzip_DOWNLOAD_VERSION}.tar.gz
38+
EXCLUDE_FROM_ALL
39+
SYSTEM
40+
FIND_PACKAGE_ARGS
41+
)
42+
43+
find_package(libzip ${PHP_libzip_MIN_VERSION})
44+
45+
if(NOT libzip_FOUND)
46+
include(Packages/ZLIB)
47+
48+
set(FETCHCONTENT_QUIET NO)
49+
50+
# The above EXCLUDE_FROM_ALL was introduced in CMake 3.28.
51+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
52+
FetchContent_MakeAvailable(libzip)
53+
else()
54+
FetchContent_GetProperties(libzip)
55+
if(NOT libzip_POPULATED)
56+
FetchContent_Populate(libzip)
57+
58+
add_subdirectory(
59+
${libzip_SOURCE_DIR}
60+
${libzip_BINARY_DIR}
61+
EXCLUDE_FROM_ALL
62+
)
63+
endif()
64+
endif()
65+
66+
# Move dependency to PACKAGES_FOUND.
67+
block()
68+
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
69+
list(REMOVE_ITEM packagesNotFound libzip)
70+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
71+
get_cmake_property(packagesFound PACKAGES_FOUND)
72+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND libzip)
73+
endblock()
74+
75+
add_library(libzip::libzip INTERFACE IMPORTED GLOBAL)
76+
target_link_libraries(libzip::libzip INTERFACE zip)
77+
78+
# Mark package as found.
79+
set(libzip_FOUND TRUE)
80+
81+
# Clean used variables.
82+
unset(FETCHCONTENT_QUIET)
83+
endif()

cmake/ext/gd/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ if(NOT PHP_EXT_GD_EXTERNAL)
316316
)
317317
endif()
318318

319-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
319+
include(Packages/ZLIB)
320320
set_package_properties(
321321
ZLIB
322322
PROPERTIES
@@ -326,7 +326,7 @@ if(NOT PHP_EXT_GD_EXTERNAL)
326326

327327
target_link_libraries(php_ext_gd PRIVATE ZLIB::ZLIB)
328328

329-
find_package(PNG)
329+
include(Packages/PNG)
330330
set_package_properties(
331331
PNG
332332
PROPERTIES

cmake/ext/mysqlnd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ target_link_libraries(
170170
)
171171

172172
if(PHP_EXT_MYSQLND_COMPRESSION)
173-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
173+
include(Packages/ZLIB)
174174
set_package_properties(
175175
ZLIB
176176
PROPERTIES

cmake/ext/zip/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ target_sources(
6868

6969
add_dependencies(php_ext_zip php_ext_pcre)
7070

71-
find_package(libzip 1.7.1)
71+
include(Packages/libzip)
7272
set_package_properties(
7373
libzip
7474
PROPERTIES

cmake/ext/zlib/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ endif()
7777

7878
target_compile_definitions(php_ext_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
7979

80-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
80+
include(Packages/ZLIB)
8181
set_package_properties(
8282
ZLIB
8383
PROPERTIES
8484
TYPE REQUIRED
8585
PURPOSE "Necessary to enable the zlib extension."
8686
)
8787

88-
target_link_libraries(php_ext_zlib PRIVATE ZLIB::ZLIB)
88+
target_link_libraries(php_ext_zlib PUBLIC ZLIB::ZLIB)
8989

9090
set(HAVE_ZLIB TRUE)
9191

0 commit comments

Comments
 (0)