cmake: Enable policy CMP0074 for ZLIB_ROOT; deprecate PNG_BUILD_ZLIB

Although the minimum required CMake version is 3.6, this policy will
only have effect under CMake 3.12 or newer.

Reported-by: Jacob Harding <54728054+jacobharding@users.noreply.github.com>
This commit is contained in:
Cosmin Truta 2023-12-20 19:12:42 +02:00
parent 2fff013a69
commit 85f866dea3

View File

@ -48,6 +48,11 @@ project(libpng
VERSION ${PNGLIB_VERSION} VERSION ${PNGLIB_VERSION}
LANGUAGES C ASM) LANGUAGES C ASM)
if(POLICY CMP0074)
# Allow find_package() to use the ZLIB_ROOT variable, if available.
cmake_policy(SET CMP0074 NEW)
endif()
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
include(GNUInstallDirs) include(GNUInstallDirs)
@ -94,11 +99,23 @@ endif()
option(PNG_DEBUG "Enable debug output" OFF) option(PNG_DEBUG "Enable debug output" OFF)
option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON) option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
# Allow the users to specify a location of zlib. # Allow the users to specify a custom location of zlib.
# Useful if zlib is being built alongside this as a sub-project. # This option is deprecated, and no longer needed with CMake 3.12 and newer.
# Under the CMake policy CMP0074, if zlib is being built alongside libpng as a
# subproject, its location can be passed on to CMake via the ZLIB_ROOT variable.
option(PNG_BUILD_ZLIB "Custom zlib location, else find_package is used" OFF) option(PNG_BUILD_ZLIB "Custom zlib location, else find_package is used" OFF)
if(NOT PNG_BUILD_ZLIB) if(NOT PNG_BUILD_ZLIB)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
elseif(POLICY CMP0074)
# TODO: Remove the policy check if CMake version 3.12 or greater becomes the minimum required.
if("x${ZLIB_ROOT}" STREQUAL "x")
message(DEPRECATION
"The option PNG_BUILD_ZLIB has been deprecated; please use ZLIB_ROOT instead")
else()
message(SEND_ERROR
"The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} and "
"the variable ZLIB_ROOT=\"${ZLIB_ROOT}\" are mutually exclusive")
endif()
endif() endif()
if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN) if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN)