[libpng16] build: Raise the minimum required CMake version to 3.14

Start using the features guaranteed to be available in CMake 3.14.
Specifically, use the ability of `find_package(ZLIB)` to pick up zlib
from the ZLIB_ROOT variable (if given).

This is a cherry-pick of commit 00343a761e41e56acaeb0517aec5325d3b951837
from branch 'libpng18'.
This commit is contained in:
Cosmin Truta 2024-09-14 23:44:45 +03:00
parent d3cf9b6e22
commit 642b5d81e3

View File

@ -15,7 +15,7 @@
# #
# SPDX-License-Identifier: libpng-2.0 # SPDX-License-Identifier: libpng-2.0
cmake_minimum_required(VERSION 3.6) cmake_minimum_required(VERSION 3.14)
set(PNGLIB_MAJOR 1) set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 6) set(PNGLIB_MINOR 6)
@ -30,11 +30,6 @@ 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)
@ -106,23 +101,22 @@ endif()
message(STATUS "Building for target architecture: ${PNG_TARGET_ARCHITECTURE}") message(STATUS "Building for target architecture: ${PNG_TARGET_ARCHITECTURE}")
# Allow the users to specify a custom location of zlib. # Allow the users to specify a custom location of zlib.
# This option is deprecated, and no longer needed with CMake 3.12 and newer. # With CMake 3.12 and newer, this option is no longer necessary.
# Under the CMake policy CMP0074, if zlib is being built alongside libpng as a option(PNG_BUILD_ZLIB "[Deprecated; please use ZLIB_ROOT]" OFF)
# subproject, its location can be passed on to CMake via the ZLIB_ROOT variable. if(PNG_BUILD_ZLIB)
option(PNG_BUILD_ZLIB "Custom zlib location, else find_package is used" OFF)
if(NOT PNG_BUILD_ZLIB)
find_package(ZLIB REQUIRED)
elseif(POLICY CMP0074)
if("x${ZLIB_ROOT}" STREQUAL "x") if("x${ZLIB_ROOT}" STREQUAL "x")
message(DEPRECATION message(SEND_ERROR
"The option PNG_BUILD_ZLIB has been deprecated; please use ZLIB_ROOT instead") "The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
"please use ZLIB_ROOT instead")
else() else()
message(SEND_ERROR message(SEND_ERROR
"The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} and " "The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
"the variable ZLIB_ROOT=\"${ZLIB_ROOT}\" are mutually exclusive") "using ZLIB_ROOT=\"${ZLIB_ROOT}\"")
endif() endif()
endif() endif()
find_package(ZLIB REQUIRED)
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)
find_library(M_LIBRARY m) find_library(M_LIBRARY m)
if(M_LIBRARY) if(M_LIBRARY)