Skip to content

Commit

Permalink
build: Raise the minimum required CMake version to 3.14
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ctruta committed Sep 14, 2024
1 parent e3adc67 commit 0371e65
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# SPDX-License-Identifier: libpng-2.0

cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.14)

set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 8)
Expand All @@ -30,11 +30,6 @@ project(libpng
VERSION ${PNGLIB_VERSION}
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(GNUInstallDirs)

Expand Down Expand Up @@ -106,23 +101,22 @@ endif()
message(STATUS "Building for target architecture: ${PNG_TARGET_ARCHITECTURE}")

# Allow the users to specify a custom location of zlib.
# 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)
if(NOT PNG_BUILD_ZLIB)
find_package(ZLIB REQUIRED)
elseif(POLICY CMP0074)
# With CMake 3.12 and newer, this option is no longer necessary.
option(PNG_BUILD_ZLIB "[Deprecated; please use ZLIB_ROOT]" OFF)
if(PNG_BUILD_ZLIB)
if("x${ZLIB_ROOT}" STREQUAL "x")
message(DEPRECATION
"The option PNG_BUILD_ZLIB has been deprecated; please use ZLIB_ROOT instead")
message(SEND_ERROR
"The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
"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")
"The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
"using ZLIB_ROOT=\"${ZLIB_ROOT}\"")
endif()
endif()

find_package(ZLIB REQUIRED)

if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN)
find_library(M_LIBRARY m)
if(M_LIBRARY)
Expand Down

0 comments on commit 0371e65

Please sign in to comment.