diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 21e7d626..208a4acf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -114,7 +114,6 @@ jobs: libsasl2-dev \ libpq-dev \ libmm-dev \ - zlib1g-dev \ libdmalloc-dev \ dovecot-core \ dovecot-pop3d \ diff --git a/cmake/cmake/Configuration.cmake b/cmake/cmake/Configuration.cmake index 6b5023f3..2bc595d8 100644 --- a/cmake/cmake/Configuration.cmake +++ b/cmake/cmake/Configuration.cmake @@ -211,9 +211,6 @@ set(PHP_SQLITE_MIN_VERSION 3.7.7) # Minimum required version for the PostgreSQL dependency. set(PHP_POSTGRESQL_MIN_VERSION 9.1) -# Minimum required version for the zlib dependency. -set(PHP_ZLIB_MIN_VERSION 1.2.0.4) - # Minimum required version for the BZip2 dependency. set(PHP_BZIP2_MIN_VERSION 1.0.0) @@ -266,10 +263,3 @@ set_package_properties( URL "https://www.sqlite.org/" DESCRIPTION "SQL database engine library" ) - -set_package_properties( - ZLIB - PROPERTIES - URL "https://zlib.net/" - DESCRIPTION "Compression library" -) diff --git a/cmake/cmake/modules/Packages/LibXml2.cmake b/cmake/cmake/modules/Packages/LibXml2.cmake index 3177e918..772bd190 100644 --- a/cmake/cmake/modules/Packages/LibXml2.cmake +++ b/cmake/cmake/modules/Packages/LibXml2.cmake @@ -45,6 +45,8 @@ FetchContent_Declare( find_package(LibXml2 ${PHP_LIBXML2_MIN_VERSION}) if(NOT LibXml2_FOUND) + include(Packages/ZLIB) + set(FETCHCONTENT_QUIET NO) set(LIBXML2_WITH_PYTHON OFF) set(LIBXML2_WITH_LZMA OFF) diff --git a/cmake/cmake/modules/Packages/PNG.cmake b/cmake/cmake/modules/Packages/PNG.cmake new file mode 100644 index 00000000..a4f96fd3 --- /dev/null +++ b/cmake/cmake/modules/Packages/PNG.cmake @@ -0,0 +1,82 @@ +#[=============================================================================[ +Wrapper for finding the `PNG` library. + +Module first tries to find the `PNG` library on the system. If not +successful it tries to download it from the upstream source with `FetchContent` +module and build it together with the PHP build. + +See: https://cmake.org/cmake/help/latest/module/FindPNG.html + +The `FetchContent` CMake module does things differently compared to the +`find_package()` flow: +* By default, it uses `QUIET` in its `find_package()` call when calling the + `FetchContent_MakeAvailable()`; +* When using `FeatureSummary`, dependencies must be moved manually to + `PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property; + +TODO: Improve this. This is for now only initial `FetchContent` integration for +testing purposes and will be changed in the future. +#]=============================================================================] + +include(FeatureSummary) +include(FetchContent) + +set_package_properties( + PNG + PROPERTIES + URL "http://libpng.org" + DESCRIPTION "Portable Network Graphics (PNG image format) library" +) + +# Minimum required version for the PNG dependency. +#set(PHP_PNG_MIN_VERSION ?.?.??) + +# Download version when system dependency is not found. +set(PHP_PNG_DOWNLOAD_VERSION 1.6.44) + +FetchContent_Declare( + PNG + URL https://download.sourceforge.net/libpng/libpng-${PHP_PNG_DOWNLOAD_VERSION}.tar.gz + EXCLUDE_FROM_ALL + SYSTEM + FIND_PACKAGE_ARGS +) + +find_package(PNG ${PHP_PNG_MIN_VERSION}) + +if(NOT PNG_FOUND) + include(Packages/ZLIB) + + set(FETCHCONTENT_QUIET NO) + + # The above EXCLUDE_FROM_ALL was introduced in CMake 3.28. + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + FetchContent_MakeAvailable(PNG) + else() + FetchContent_GetProperties(PNG) + if(NOT PNG_POPULATED) + FetchContent_Populate(PNG) + + add_subdirectory( + ${PNG_SOURCE_DIR} + ${PNG_BINARY_DIR} + EXCLUDE_FROM_ALL + ) + endif() + endif() + + # Move dependency to PACKAGES_FOUND. + block() + get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND) + list(REMOVE_ITEM packagesNotFound PNG) + set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound) + get_cmake_property(packagesFound PACKAGES_FOUND) + set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND PNG) + endblock() + + # Mark package as found. + set(PNG_FOUND TRUE) + + # Clean used variables. + unset(FETCHCONTENT_QUIET) +endif() diff --git a/cmake/cmake/modules/Packages/ZLIB.cmake b/cmake/cmake/modules/Packages/ZLIB.cmake new file mode 100644 index 00000000..4bb1ba7e --- /dev/null +++ b/cmake/cmake/modules/Packages/ZLIB.cmake @@ -0,0 +1,90 @@ +#[=============================================================================[ +Wrapper for finding the `ZLIB` library. + +Module first tries to find the `ZLIB` library on the system. If not successful +it tries to download it from the upstream source with `FetchContent` module and +build it together with the PHP build. + +See: https://cmake.org/cmake/help/latest/module/FindZLIB.html + +The `FetchContent` CMake module does things differently compared to the +`find_package()` flow: +* By default, it uses `QUIET` in its `find_package()` call when calling the + `FetchContent_MakeAvailable()` +* When using `FeatureSummary`, dependencies must be moved manually to + `PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property + +TODO: Improve this. This is for now only initial `FetchContent` integration for +testing purposes and will be changed in the future. +#]=============================================================================] + +include(FeatureSummary) +include(FetchContent) + +set_package_properties( + ZLIB + PROPERTIES + URL "https://zlib.net/" + DESCRIPTION "Compression library" +) + +# Minimum required version for the zlib dependency. +set(PHP_ZLIB_MIN_VERSION 1.2.0.4) + +# Download version when system dependency is not found. +set(PHP_ZLIB_DOWNLOAD_VERSION 1.3.1) + +FetchContent_Declare( + ZLIB + URL https://github.com/madler/zlib/releases/download/v${PHP_ZLIB_DOWNLOAD_VERSION}/zlib-${PHP_ZLIB_DOWNLOAD_VERSION}.tar.gz + EXCLUDE_FROM_ALL + SYSTEM + FIND_PACKAGE_ARGS +) + +find_package(ZLIB ${PHP_ZLIB_MIN_VERSION}) + +if(NOT ZLIB_FOUND) + set(FETCHCONTENT_QUIET NO) + + # The above EXCLUDE_FROM_ALL was introduced in CMake 3.28. + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + FetchContent_MakeAvailable(ZLIB) + else() + FetchContent_GetProperties(ZLIB) + if(NOT ZLIB_POPULATED) + FetchContent_Populate(ZLIB) + + add_subdirectory( + ${zlib_SOURCE_DIR} + ${zlib_BINARY_DIR} + EXCLUDE_FROM_ALL + ) + endif() + endif() + + # Move dependency to PACKAGES_FOUND. + block() + get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND) + list(REMOVE_ITEM packagesNotFound ZLIB) + set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound) + get_cmake_property(packagesFound PACKAGES_FOUND) + set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ZLIB) + endblock() + + set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + add_library(ZLIB::ZLIB INTERFACE IMPORTED GLOBAL) + target_link_libraries(ZLIB::ZLIB INTERFACE zlibstatic) + target_include_directories( + zlibstatic + PUBLIC + $ + $ + ) + + # Mark package as found. + set(ZLIB_FOUND TRUE) + + # Clean used variables. + unset(FETCHCONTENT_QUIET) +endif() diff --git a/cmake/cmake/modules/Packages/libzip.cmake b/cmake/cmake/modules/Packages/libzip.cmake new file mode 100644 index 00000000..f6500141 --- /dev/null +++ b/cmake/cmake/modules/Packages/libzip.cmake @@ -0,0 +1,83 @@ +#[=============================================================================[ +Wrapper for finding the `libzip` library. + +Module first tries to find the `libzip` library on the system. If not +successful it tries to download it from the upstream source with `FetchContent` +module and build it together with the PHP build. + +The `FetchContent` CMake module does things differently compared to the +`find_package()` flow: +* By default, it uses `QUIET` in its `find_package()` call when calling the + `FetchContent_MakeAvailable()`; +* When using `FeatureSummary`, dependencies must be moved manually to + `PACKAGES_FOUND` from the `PACKAGES_NOT_FOUND` global property; + +TODO: Improve this. This is for now only initial `FetchContent` integration for +testing purposes and will be changed in the future. +#]=============================================================================] + +include(FeatureSummary) +include(FetchContent) + +set_package_properties( + libzip + PROPERTIES + URL "https://libzip.org/" + DESCRIPTION "Library for reading and writing ZIP compressed archives" +) + +# Minimum required version for the libzip dependency. +set(PHP_libzip_MIN_VERSION 1.7.1) + +# Download version when system dependency is not found. +set(PHP_libzip_DOWNLOAD_VERSION 1.11.2) + +FetchContent_Declare( + libzip + URL https://github.com/nih-at/libzip/releases/download/v${PHP_libzip_DOWNLOAD_VERSION}/libzip-${PHP_libzip_DOWNLOAD_VERSION}.tar.gz + EXCLUDE_FROM_ALL + SYSTEM + FIND_PACKAGE_ARGS +) + +find_package(libzip ${PHP_libzip_MIN_VERSION}) + +if(NOT libzip_FOUND) + include(Packages/ZLIB) + + set(FETCHCONTENT_QUIET NO) + + # The above EXCLUDE_FROM_ALL was introduced in CMake 3.28. + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + FetchContent_MakeAvailable(libzip) + else() + FetchContent_GetProperties(libzip) + if(NOT libzip_POPULATED) + FetchContent_Populate(libzip) + + add_subdirectory( + ${libzip_SOURCE_DIR} + ${libzip_BINARY_DIR} + EXCLUDE_FROM_ALL + ) + endif() + endif() + + # Move dependency to PACKAGES_FOUND. + block() + get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND) + list(REMOVE_ITEM packagesNotFound libzip) + set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound) + get_cmake_property(packagesFound PACKAGES_FOUND) + set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND libzip) + endblock() + + add_library(libzip::libzip INTERFACE IMPORTED GLOBAL) + target_link_libraries(libzip::libzip INTERFACE zip) + + # Mark package as found. + set(libzip_FOUND TRUE) + + # Clean used variables. + unset(FETCHCONTENT_QUIET) +endif() diff --git a/cmake/ext/gd/CMakeLists.txt b/cmake/ext/gd/CMakeLists.txt index e9f533d9..df4db144 100644 --- a/cmake/ext/gd/CMakeLists.txt +++ b/cmake/ext/gd/CMakeLists.txt @@ -319,7 +319,7 @@ if(NOT EXT_GD_EXTERNAL) ) endif() - find_package(ZLIB ${PHP_ZLIB_MIN_VERSION}) + include(Packages/ZLIB) set_package_properties( ZLIB PROPERTIES @@ -329,7 +329,7 @@ if(NOT EXT_GD_EXTERNAL) target_link_libraries(php_gd PRIVATE ZLIB::ZLIB) - find_package(PNG) + include(Packages/PNG) set_package_properties( PNG PROPERTIES diff --git a/cmake/ext/mysqlnd/CMakeLists.txt b/cmake/ext/mysqlnd/CMakeLists.txt index 6e004f82..203f98f2 100644 --- a/cmake/ext/mysqlnd/CMakeLists.txt +++ b/cmake/ext/mysqlnd/CMakeLists.txt @@ -168,7 +168,7 @@ target_link_libraries( ) if(EXT_MYSQLND_COMPRESSION) - find_package(ZLIB ${PHP_ZLIB_MIN_VERSION}) + include(Packages/ZLIB) set_package_properties( ZLIB PROPERTIES diff --git a/cmake/ext/zip/CMakeLists.txt b/cmake/ext/zip/CMakeLists.txt index cab6988a..1dfd4d54 100644 --- a/cmake/ext/zip/CMakeLists.txt +++ b/cmake/ext/zip/CMakeLists.txt @@ -65,7 +65,7 @@ target_sources( add_dependencies(php_zip php_pcre) -find_package(libzip 1.7.1) +include(Packages/libzip) set_package_properties( libzip PROPERTIES diff --git a/cmake/ext/zlib/CMakeLists.txt b/cmake/ext/zlib/CMakeLists.txt index 7f03a9a1..eee72731 100644 --- a/cmake/ext/zlib/CMakeLists.txt +++ b/cmake/ext/zlib/CMakeLists.txt @@ -67,7 +67,7 @@ target_sources( target_compile_definitions(php_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1) -find_package(ZLIB ${PHP_ZLIB_MIN_VERSION}) +include(Packages/ZLIB) set_package_properties( ZLIB PROPERTIES @@ -75,7 +75,7 @@ set_package_properties( PURPOSE "Necessary to enable the zlib extension." ) -target_link_libraries(php_zlib PRIVATE ZLIB::ZLIB) +target_link_libraries(php_zlib PUBLIC ZLIB::ZLIB) set(HAVE_ZLIB 1)