1
0
mirror of https://github.com/glennrp/libpng.git synced 2025-08-07 13:22:57 +03:00
Files
libpng/scripts/cmake/PNGCheckLibconf.cmake
Cosmin Truta 23bdc7a6c4 build: Add the CMake build option PNG_LIBCONF_HEADER
Running the pnglibconf scripts (script/*.awk) is not always possible.
An AWK interpreter is not always guaranteed to be available; and even
if it is, there are limitations when making cross-platform libpng
builds, especially when the differences between the host platform and
the target platform are significant. For example:
 * Building for the Windows (MinGW) target on a Unix development host;
 * Building for the iOS target on a macOS development host;
 * Building for the Android target on any development host.

In such scenarios, a preconfigured (i.e. prebuilt) pnglibconf.h file,
either taken from the libpng source tree or provided by the user who
wants to make a custom libpng build, becomes a necessity.

In this commit we introduce the build option `PNG_LIBCONF_HEADER` in
order to address this specific use case.

We also specify a version range (3.14...4.0) for the minimum required
CMake program, to future-proof the CMake build for just a little bit
longer.

Signed-off-by: Cosmin Truta <ctruta@gmail.com>
2025-04-28 20:44:53 +03:00

46 lines
1.5 KiB
CMake

# PNGConfig.cmake
# Utility functions for configuring and building libpng
# Copyright (c) 2025 Cosmin Truta
#
# Use, modification and distribution are subject to
# the same licensing terms and conditions as libpng.
# Please see the copyright notice in png.h or visit
# http://libpng.org/pub/png/src/libpng-LICENSE.txt
#
# SPDX-License-Identifier: libpng-2.0
# Check libconf file (pnglibconf.h.* or *.dfa):
# png_check_libconf([HEADER <file>] [DFA_XTRA <file>])
function(png_check_libconf)
set(options)
set(oneValueArgs HEADER DFA_XTRA)
set(multiValueArgs)
cmake_parse_arguments(_CHK "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(_CHK_HEADER AND _CHK_DFA_XTRA)
message(FATAL_ERROR "png_check_libconf: Mutually-exclusive arguments: HEADER and DFA_XTRA")
endif()
if(_CHK_HEADER)
if(EXISTS "${_CHK_HEADER}")
if("x${_CHK_HEADER}" STREQUAL "x${PNG_LIBCONF_HEADER_PREBUILT}")
message(STATUS "Using standard libconf header: ${_CHK_HEADER}")
else()
message(STATUS "Using custom libconf header: ${_CHK_HEADER}")
endif()
else()
message(SEND_ERROR "Could not find libconf header: ${_CHK_HEADER}")
endif()
else()
if("x${_CHK_DFA_XTRA}" STREQUAL "x")
message(STATUS "Creating standard configuration")
elseif(EXISTS "${_CHK_DFA_XTRA}")
message(STATUS "Creating custom configuration with DFA_XTRA file: ${_CHK_DFA_XTRA}")
else()
message(SEND_ERROR "Could not find DFA_XTRA file: ${_CHK_DFA_XTRA}")
endif()
endif()
endfunction()