Skip to content

Commit 33604dd

Browse files
committed
Add ZLIB with FetchContent
1 parent f0bb453 commit 33604dd

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
@@ -114,7 +114,6 @@ jobs:
114114
libsasl2-dev \
115115
libpq-dev \
116116
libmm-dev \
117-
zlib1g-dev \
118117
libdmalloc-dev \
119118
dovecot-core \
120119
dovecot-pop3d \

cmake/cmake/Configuration.cmake

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

214-
# Minimum required version for the zlib dependency.
215-
set(PHP_ZLIB_MIN_VERSION 1.2.0.4)
216-
217214
# Minimum required version for the BZip2 dependency.
218215
set(PHP_BZIP2_MIN_VERSION 1.0.0)
219216

@@ -266,10 +263,3 @@ set_package_properties(
266263
URL "https://www.sqlite.org/"
267264
DESCRIPTION "SQL database engine library"
268265
)
269-
270-
set_package_properties(
271-
ZLIB
272-
PROPERTIES
273-
URL "https://zlib.net/"
274-
DESCRIPTION "Compression library"
275-
)

cmake/cmake/modules/Packages/LibXml2.cmake

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

4747
if(NOT LibXml2_FOUND)
48+
include(Packages/ZLIB)
49+
4850
set(FETCHCONTENT_QUIET NO)
4951
set(LIBXML2_WITH_PYTHON OFF)
5052
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
@@ -319,7 +319,7 @@ if(NOT EXT_GD_EXTERNAL)
319319
)
320320
endif()
321321

322-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
322+
include(Packages/ZLIB)
323323
set_package_properties(
324324
ZLIB
325325
PROPERTIES
@@ -329,7 +329,7 @@ if(NOT EXT_GD_EXTERNAL)
329329

330330
target_link_libraries(php_gd PRIVATE ZLIB::ZLIB)
331331

332-
find_package(PNG)
332+
include(Packages/PNG)
333333
set_package_properties(
334334
PNG
335335
PROPERTIES

cmake/ext/mysqlnd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ target_link_libraries(
168168
)
169169

170170
if(EXT_MYSQLND_COMPRESSION)
171-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
171+
include(Packages/ZLIB)
172172
set_package_properties(
173173
ZLIB
174174
PROPERTIES

cmake/ext/zip/CMakeLists.txt

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

6666
add_dependencies(php_zip php_pcre)
6767

68-
find_package(libzip 1.7.1)
68+
include(Packages/libzip)
6969
set_package_properties(
7070
libzip
7171
PROPERTIES

cmake/ext/zlib/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ target_sources(
6767

6868
target_compile_definitions(php_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
6969

70-
find_package(ZLIB ${PHP_ZLIB_MIN_VERSION})
70+
include(Packages/ZLIB)
7171
set_package_properties(
7272
ZLIB
7373
PROPERTIES
7474
TYPE REQUIRED
7575
PURPOSE "Necessary to enable the zlib extension."
7676
)
7777

78-
target_link_libraries(php_zlib PRIVATE ZLIB::ZLIB)
78+
target_link_libraries(php_zlib PUBLIC ZLIB::ZLIB)
7979

8080
set(HAVE_ZLIB 1)
8181

0 commit comments

Comments
 (0)