15bec5421Sopenharmony_cidiff --git a/CMakeLists.txt b/CMakeLists.txt
25bec5421Sopenharmony_ciindex 8652564b6..639554ad8 100644
35bec5421Sopenharmony_ci--- a/CMakeLists.txt
45bec5421Sopenharmony_ci+++ b/CMakeLists.txt
55bec5421Sopenharmony_ci@@ -1,1040 +1,26 @@
65bec5421Sopenharmony_ci-# CMakeLists.txt
75bec5421Sopenharmony_ci-
85bec5421Sopenharmony_ci-# Copyright (c) 2018-2022 Cosmin Truta
95bec5421Sopenharmony_ci-# Copyright (c) 2007,2009-2018 Glenn Randers-Pehrson
105bec5421Sopenharmony_ci-# Written by Christian Ehrlicher, 2007
115bec5421Sopenharmony_ci-# Revised by Roger Lowman, 2009-2010
125bec5421Sopenharmony_ci-# Revised by Clifford Yapp, 2011-2012,2017
135bec5421Sopenharmony_ci-# Revised by Roger Leigh, 2016
145bec5421Sopenharmony_ci-# Revised by Andreas Franek, 2016
155bec5421Sopenharmony_ci-# Revised by Sam Serrels, 2017
165bec5421Sopenharmony_ci-# Revised by Vadim Barkov, 2017
175bec5421Sopenharmony_ci-# Revised by Vicky Pfau, 2018
185bec5421Sopenharmony_ci-# Revised by Cameron Cawley, 2018,2021
195bec5421Sopenharmony_ci-# Revised by Kyle Bentley, 2018
205bec5421Sopenharmony_ci-# Revised by David Callu, 2020
215bec5421Sopenharmony_ci-# Revised by Steve Robinson, 2020
225bec5421Sopenharmony_ci-# Revised by Simon Hausmann, 2020
235bec5421Sopenharmony_ci-# Revised by Alex Gaynor, 2020
245bec5421Sopenharmony_ci-# Revised by Owen Rudge, 2020
255bec5421Sopenharmony_ci-# Revised by Gleb Mazovetskiy, 2021
265bec5421Sopenharmony_ci-# Revised by Christopher Sean Morrison, 2022
275bec5421Sopenharmony_ci-
285bec5421Sopenharmony_ci-# This code is released under the libpng license.
295bec5421Sopenharmony_ci-# For conditions of distribution and use, see the disclaimer
305bec5421Sopenharmony_ci-# and license in png.h
315bec5421Sopenharmony_ci-
325bec5421Sopenharmony_ci-cmake_minimum_required(VERSION 3.1)
335bec5421Sopenharmony_ci-cmake_policy(VERSION 3.1)
345bec5421Sopenharmony_ci-
355bec5421Sopenharmony_ci-project(libpng C ASM)
365bec5421Sopenharmony_ci-enable_testing()
375bec5421Sopenharmony_ci-
385bec5421Sopenharmony_ci-set(PNGLIB_MAJOR 1)
395bec5421Sopenharmony_ci-set(PNGLIB_MINOR 6)
405bec5421Sopenharmony_ci-set(PNGLIB_REVISION 38)
415bec5421Sopenharmony_ci-set(PNGLIB_SUBREVISION 0)
425bec5421Sopenharmony_ci-#set(PNGLIB_SUBREVISION "git")
435bec5421Sopenharmony_ci-set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
445bec5421Sopenharmony_ci-set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_REVISION})
455bec5421Sopenharmony_ci-set(PNGLIB_SHARED_SOVERSION ${PNGLIB_MAJOR}${PNGLIB_MINOR})
465bec5421Sopenharmony_ci-set(PNGLIB_SHARED_VERSION ${PNGLIB_SHARED_SOVERSION}.${PNGLIB_REVISION}.${PNGLIB_SUBREVISION})
475bec5421Sopenharmony_ci-
485bec5421Sopenharmony_ci-include(GNUInstallDirs)
495bec5421Sopenharmony_ci-
505bec5421Sopenharmony_ci-# Allow users to specify location of zlib.
515bec5421Sopenharmony_ci-# Useful if zlib is being built alongside this as a sub-project.
525bec5421Sopenharmony_ci-option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF)
535bec5421Sopenharmony_ci-
545bec5421Sopenharmony_ci-if(NOT PNG_BUILD_ZLIB)
555bec5421Sopenharmony_ci-  find_package(ZLIB REQUIRED)
565bec5421Sopenharmony_ci-  include_directories(${ZLIB_INCLUDE_DIRS})
575bec5421Sopenharmony_ci-endif()
585bec5421Sopenharmony_ci-
595bec5421Sopenharmony_ci-if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN)
605bec5421Sopenharmony_ci-  find_library(M_LIBRARY m)
615bec5421Sopenharmony_ci-  if(NOT M_LIBRARY)
625bec5421Sopenharmony_ci-    set(M_LIBRARY "")
635bec5421Sopenharmony_ci-  endif()
645bec5421Sopenharmony_ci-else()
655bec5421Sopenharmony_ci-  # libm is not needed and/or not available.
665bec5421Sopenharmony_ci-  set(M_LIBRARY "")
675bec5421Sopenharmony_ci-endif()
685bec5421Sopenharmony_ci-
695bec5421Sopenharmony_ci-# Public CMake configuration variables.
705bec5421Sopenharmony_ci-option(PNG_SHARED "Build shared lib" ON)
715bec5421Sopenharmony_ci-option(PNG_STATIC "Build static lib" ON)
725bec5421Sopenharmony_ci-option(PNG_EXECUTABLES "Build libpng executables" ON)
735bec5421Sopenharmony_ci-option(PNG_TESTS "Build libpng tests" ON)
745bec5421Sopenharmony_ci-
755bec5421Sopenharmony_ci-# Many more configuration options could be added here.
765bec5421Sopenharmony_ci-option(PNG_FRAMEWORK "Build OS X framework" OFF)
775bec5421Sopenharmony_ci-option(PNG_DEBUG "Build with debug output" OFF)
785bec5421Sopenharmony_ci-option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
795bec5421Sopenharmony_ci-
805bec5421Sopenharmony_ci-set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names")
815bec5421Sopenharmony_ci-set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings")
825bec5421Sopenharmony_ci-
835bec5421Sopenharmony_ci-# CMake currently sets CMAKE_SYSTEM_PROCESSOR to one of x86_64 or arm64 on macOS,
845bec5421Sopenharmony_ci-# based upon the OS architecture, not the target architecture. As such, we need
855bec5421Sopenharmony_ci-# to check CMAKE_OSX_ARCHITECTURES to identify which hardware-specific flags to
865bec5421Sopenharmony_ci-# enable. Note that this will fail if you attempt to build a universal binary in
875bec5421Sopenharmony_ci-# a single CMake invocation.
885bec5421Sopenharmony_ci-if (APPLE AND CMAKE_OSX_ARCHITECTURES)
895bec5421Sopenharmony_ci-  set(TARGET_ARCH ${CMAKE_OSX_ARCHITECTURES})
905bec5421Sopenharmony_ci-else()
915bec5421Sopenharmony_ci-  set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
925bec5421Sopenharmony_ci-endif()
935bec5421Sopenharmony_ci-
945bec5421Sopenharmony_ci-if(PNG_HARDWARE_OPTIMIZATIONS)
955bec5421Sopenharmony_ci-
965bec5421Sopenharmony_ci-# Set definitions and sources for ARM.
975bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^arm" OR
985bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^aarch64")
995bec5421Sopenharmony_ci-  if(TARGET_ARCH MATCHES "^arm64" OR
1005bec5421Sopenharmony_ci-     TARGET_ARCH MATCHES "^aarch64")
1015bec5421Sopenharmony_ci-    set(PNG_ARM_NEON_POSSIBLE_VALUES on off)
1025bec5421Sopenharmony_ci-    set(PNG_ARM_NEON "on"
1035bec5421Sopenharmony_ci-        CACHE STRING "Enable ARM NEON optimizations: on|off; on is default")
1045bec5421Sopenharmony_ci-  else()
1055bec5421Sopenharmony_ci-    set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
1065bec5421Sopenharmony_ci-    set(PNG_ARM_NEON "check"
1075bec5421Sopenharmony_ci-        CACHE STRING "Enable ARM NEON optimizations: check|on|off; check is default")
1085bec5421Sopenharmony_ci-  endif()
1095bec5421Sopenharmony_ci-  set_property(CACHE PNG_ARM_NEON
1105bec5421Sopenharmony_ci-               PROPERTY STRINGS ${PNG_ARM_NEON_POSSIBLE_VALUES})
1115bec5421Sopenharmony_ci-  list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
1125bec5421Sopenharmony_ci-  if(index EQUAL -1)
1135bec5421Sopenharmony_ci-    message(FATAL_ERROR "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
1145bec5421Sopenharmony_ci-  elseif(NOT ${PNG_ARM_NEON} STREQUAL "off")
1155bec5421Sopenharmony_ci-    set(libpng_arm_sources
1165bec5421Sopenharmony_ci-        arm/arm_init.c
1175bec5421Sopenharmony_ci-        arm/filter_neon.S
1185bec5421Sopenharmony_ci-        arm/filter_neon_intrinsics.c
1195bec5421Sopenharmony_ci-        arm/palette_neon_intrinsics.c)
1205bec5421Sopenharmony_ci-    if(${PNG_ARM_NEON} STREQUAL "on")
1215bec5421Sopenharmony_ci-      add_definitions(-DPNG_ARM_NEON_OPT=2)
1225bec5421Sopenharmony_ci-    elseif(${PNG_ARM_NEON} STREQUAL "check")
1235bec5421Sopenharmony_ci-      add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
1245bec5421Sopenharmony_ci-    endif()
1255bec5421Sopenharmony_ci-  else()
1265bec5421Sopenharmony_ci-    add_definitions(-DPNG_ARM_NEON_OPT=0)
1275bec5421Sopenharmony_ci-  endif()
1285bec5421Sopenharmony_ci-endif()
1295bec5421Sopenharmony_ci-
1305bec5421Sopenharmony_ci-# Set definitions and sources for PowerPC.
1315bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^powerpc*" OR
1325bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^ppc64*")
1335bec5421Sopenharmony_ci-  set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off)
1345bec5421Sopenharmony_ci-  set(PNG_POWERPC_VSX "on"
1355bec5421Sopenharmony_ci-      CACHE STRING "Enable POWERPC VSX optimizations: on|off; on is default")
1365bec5421Sopenharmony_ci-  set_property(CACHE PNG_POWERPC_VSX
1375bec5421Sopenharmony_ci-               PROPERTY STRINGS ${PNG_POWERPC_VSX_POSSIBLE_VALUES})
1385bec5421Sopenharmony_ci-  list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index)
1395bec5421Sopenharmony_ci-  if(index EQUAL -1)
1405bec5421Sopenharmony_ci-    message(FATAL_ERROR "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]")
1415bec5421Sopenharmony_ci-  elseif(NOT ${PNG_POWERPC_VSX} STREQUAL "off")
1425bec5421Sopenharmony_ci-    set(libpng_powerpc_sources
1435bec5421Sopenharmony_ci-        powerpc/powerpc_init.c
1445bec5421Sopenharmony_ci-        powerpc/filter_vsx_intrinsics.c)
1455bec5421Sopenharmony_ci-    if(${PNG_POWERPC_VSX} STREQUAL "on")
1465bec5421Sopenharmony_ci-      add_definitions(-DPNG_POWERPC_VSX_OPT=2)
1475bec5421Sopenharmony_ci-    endif()
1485bec5421Sopenharmony_ci-  else()
1495bec5421Sopenharmony_ci-    add_definitions(-DPNG_POWERPC_VSX_OPT=0)
1505bec5421Sopenharmony_ci-  endif()
1515bec5421Sopenharmony_ci-endif()
1525bec5421Sopenharmony_ci-
1535bec5421Sopenharmony_ci-# Set definitions and sources for Intel.
1545bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^i?86" OR
1555bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^x86_64*")
1565bec5421Sopenharmony_ci-  set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
1575bec5421Sopenharmony_ci-  set(PNG_INTEL_SSE "on"
1585bec5421Sopenharmony_ci-      CACHE STRING "Enable INTEL_SSE optimizations: on|off; on is default")
1595bec5421Sopenharmony_ci-  set_property(CACHE PNG_INTEL_SSE
1605bec5421Sopenharmony_ci-               PROPERTY STRINGS ${PNG_INTEL_SSE_POSSIBLE_VALUES})
1615bec5421Sopenharmony_ci-  list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index)
1625bec5421Sopenharmony_ci-  if(index EQUAL -1)
1635bec5421Sopenharmony_ci-    message(FATAL_ERROR "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]")
1645bec5421Sopenharmony_ci-  elseif(NOT ${PNG_INTEL_SSE} STREQUAL "off")
1655bec5421Sopenharmony_ci-    set(libpng_intel_sources
1665bec5421Sopenharmony_ci-        intel/intel_init.c
1675bec5421Sopenharmony_ci-        intel/filter_sse2_intrinsics.c)
1685bec5421Sopenharmony_ci-    if(${PNG_INTEL_SSE} STREQUAL "on")
1695bec5421Sopenharmony_ci-      add_definitions(-DPNG_INTEL_SSE_OPT=1)
1705bec5421Sopenharmony_ci-    endif()
1715bec5421Sopenharmony_ci-  else()
1725bec5421Sopenharmony_ci-    add_definitions(-DPNG_INTEL_SSE_OPT=0)
1735bec5421Sopenharmony_ci-  endif()
1745bec5421Sopenharmony_ci-endif()
1755bec5421Sopenharmony_ci-
1765bec5421Sopenharmony_ci-# Set definitions and sources for MIPS.
1775bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "mipsel*" OR
1785bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "mips64el*")
1795bec5421Sopenharmony_ci-  set(PNG_MIPS_MSA_POSSIBLE_VALUES on off)
1805bec5421Sopenharmony_ci-  set(PNG_MIPS_MSA "on"
1815bec5421Sopenharmony_ci-      CACHE STRING "Enable MIPS_MSA optimizations: on|off; on is default")
1825bec5421Sopenharmony_ci-  set_property(CACHE PNG_MIPS_MSA
1835bec5421Sopenharmony_ci-               PROPERTY STRINGS ${PNG_MIPS_MSA_POSSIBLE_VALUES})
1845bec5421Sopenharmony_ci-  list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index)
1855bec5421Sopenharmony_ci-  if(index EQUAL -1)
1865bec5421Sopenharmony_ci-    message(FATAL_ERROR "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]")
1875bec5421Sopenharmony_ci-  elseif(NOT ${PNG_MIPS_MSA} STREQUAL "off")
1885bec5421Sopenharmony_ci-    set(libpng_mips_sources
1895bec5421Sopenharmony_ci-        mips/mips_init.c
1905bec5421Sopenharmony_ci-        mips/filter_msa_intrinsics.c)
1915bec5421Sopenharmony_ci-    if(${PNG_MIPS_MSA} STREQUAL "on")
1925bec5421Sopenharmony_ci-      add_definitions(-DPNG_MIPS_MSA_OPT=2)
1935bec5421Sopenharmony_ci-    endif()
1945bec5421Sopenharmony_ci-  else()
1955bec5421Sopenharmony_ci-    add_definitions(-DPNG_MIPS_MSA_OPT=0)
1965bec5421Sopenharmony_ci-  endif()
1975bec5421Sopenharmony_ci-endif()
1985bec5421Sopenharmony_ci-
1995bec5421Sopenharmony_ci-else(PNG_HARDWARE_OPTIMIZATIONS)
2005bec5421Sopenharmony_ci-
2015bec5421Sopenharmony_ci-# Set definitions and sources for ARM.
2025bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^arm" OR
2035bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^aarch64")
2045bec5421Sopenharmony_ci-  add_definitions(-DPNG_ARM_NEON_OPT=0)
2055bec5421Sopenharmony_ci-endif()
2065bec5421Sopenharmony_ci-
2075bec5421Sopenharmony_ci-# Set definitions and sources for PowerPC.
2085bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^powerpc*" OR
2095bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^ppc64*")
2105bec5421Sopenharmony_ci-  add_definitions(-DPNG_POWERPC_VSX_OPT=0)
2115bec5421Sopenharmony_ci-endif()
2125bec5421Sopenharmony_ci-
2135bec5421Sopenharmony_ci-# Set definitions and sources for Intel.
2145bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "^i?86" OR
2155bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "^x86_64*")
2165bec5421Sopenharmony_ci-  add_definitions(-DPNG_INTEL_SSE_OPT=0)
2175bec5421Sopenharmony_ci-endif()
2185bec5421Sopenharmony_ci-
2195bec5421Sopenharmony_ci-# Set definitions and sources for MIPS.
2205bec5421Sopenharmony_ci-if(TARGET_ARCH MATCHES "mipsel*" OR
2215bec5421Sopenharmony_ci-   TARGET_ARCH MATCHES "mips64el*")
2225bec5421Sopenharmony_ci-  add_definitions(-DPNG_MIPS_MSA_OPT=0)
2235bec5421Sopenharmony_ci-endif()
2245bec5421Sopenharmony_ci-
2255bec5421Sopenharmony_ci-endif(PNG_HARDWARE_OPTIMIZATIONS)
2265bec5421Sopenharmony_ci-
2275bec5421Sopenharmony_ci-# Set PNG_LIB_NAME.
2285bec5421Sopenharmony_ci-set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
2295bec5421Sopenharmony_ci-
2305bec5421Sopenharmony_ci-# Distinguish between debug and release builds.
2315bec5421Sopenharmony_ci-set(CMAKE_DEBUG_POSTFIX "d")
2325bec5421Sopenharmony_ci-
2335bec5421Sopenharmony_ci-include(CheckCSourceCompiles)
2345bec5421Sopenharmony_ci-option(ld-version-script "Enable linker version script" ON)
2355bec5421Sopenharmony_ci-if(ld-version-script AND NOT ANDROID AND NOT APPLE)
2365bec5421Sopenharmony_ci-  # Check if LD supports linker scripts.
2375bec5421Sopenharmony_ci-  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "
2385bec5421Sopenharmony_ci-VERS_1 {
2395bec5421Sopenharmony_ci-        global: sym;
2405bec5421Sopenharmony_ci-        local: *;
2415bec5421Sopenharmony_ci-};
2425bec5421Sopenharmony_ci-
2435bec5421Sopenharmony_ci-VERS_2 {
2445bec5421Sopenharmony_ci-        global: sym2;
2455bec5421Sopenharmony_ci-                main;
2465bec5421Sopenharmony_ci-} VERS_1;
2475bec5421Sopenharmony_ci-")
2485bec5421Sopenharmony_ci-  set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
2495bec5421Sopenharmony_ci-  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
2505bec5421Sopenharmony_ci-  check_c_source_compiles("void sym(void) {}
2515bec5421Sopenharmony_ci-void sym2(void) {}
2525bec5421Sopenharmony_ci-int main(void) {return 0;}
2535bec5421Sopenharmony_ci-" HAVE_LD_VERSION_SCRIPT)
2545bec5421Sopenharmony_ci-  if(NOT HAVE_LD_VERSION_SCRIPT)
2555bec5421Sopenharmony_ci-    set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
2565bec5421Sopenharmony_ci-  check_c_source_compiles("void sym(void) {}
2575bec5421Sopenharmony_ci-void sym2(void) {}
2585bec5421Sopenharmony_ci-int main(void) {return 0;}
2595bec5421Sopenharmony_ci-" HAVE_SOLARIS_LD_VERSION_SCRIPT)
2605bec5421Sopenharmony_ci-  endif()
2615bec5421Sopenharmony_ci-  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
2625bec5421Sopenharmony_ci-  file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
2635bec5421Sopenharmony_ci-endif()
2645bec5421Sopenharmony_ci-
2655bec5421Sopenharmony_ci-# Find symbol prefix.  Likely obsolete and unnecessary with recent
2665bec5421Sopenharmony_ci-# toolchains (it's not done in many other projects).
2675bec5421Sopenharmony_ci-function(symbol_prefix)
2685bec5421Sopenharmony_ci-  set(SYMBOL_PREFIX)
2695bec5421Sopenharmony_ci-
2705bec5421Sopenharmony_ci-  execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E" "-"
2715bec5421Sopenharmony_ci-                  INPUT_FILE /dev/null
2725bec5421Sopenharmony_ci-                  OUTPUT_VARIABLE OUT
2735bec5421Sopenharmony_ci-                  RESULT_VARIABLE STATUS)
2745bec5421Sopenharmony_ci-
2755bec5421Sopenharmony_ci-  if(CPP_FAIL)
2765bec5421Sopenharmony_ci-    message(WARNING "Failed to run the C preprocessor")
2775bec5421Sopenharmony_ci-  endif()
2785bec5421Sopenharmony_ci-
2795bec5421Sopenharmony_ci-  string(REPLACE "\n" ";" OUT "${OUT}")
2805bec5421Sopenharmony_ci-  foreach(line ${OUT})
2815bec5421Sopenharmony_ci-    string(REGEX MATCH "^PREFIX=" found_match "${line}")
2825bec5421Sopenharmony_ci-    if(found_match)
2835bec5421Sopenharmony_ci-      string(REGEX REPLACE "^PREFIX=(.*\)" "\\1" prefix "${line}")
2845bec5421Sopenharmony_ci-      string(REGEX MATCH "__USER_LABEL_PREFIX__" found_match "${prefix}")
2855bec5421Sopenharmony_ci-      if(found_match)
2865bec5421Sopenharmony_ci-        string(REGEX REPLACE "(.*)__USER_LABEL_PREFIX__(.*)" "\\1\\2" prefix "${prefix}")
2875bec5421Sopenharmony_ci-      endif()
2885bec5421Sopenharmony_ci-      set(SYMBOL_PREFIX "${prefix}")
2895bec5421Sopenharmony_ci-    endif()
2905bec5421Sopenharmony_ci-  endforeach()
2915bec5421Sopenharmony_ci-
2925bec5421Sopenharmony_ci-  message(STATUS "Symbol prefix: ${SYMBOL_PREFIX}")
2935bec5421Sopenharmony_ci-  set(SYMBOL_PREFIX "${SYMBOL_PREFIX}" PARENT_SCOPE)
2945bec5421Sopenharmony_ci-endfunction()
2955bec5421Sopenharmony_ci-
2965bec5421Sopenharmony_ci-if(UNIX)
2975bec5421Sopenharmony_ci-  symbol_prefix()
2985bec5421Sopenharmony_ci-endif()
2995bec5421Sopenharmony_ci-
3005bec5421Sopenharmony_ci-find_program(AWK NAMES gawk awk)
3015bec5421Sopenharmony_ci-
3025bec5421Sopenharmony_ci-include_directories(${CMAKE_CURRENT_BINARY_DIR})
3035bec5421Sopenharmony_ci-
3045bec5421Sopenharmony_ci-if(NOT AWK OR ANDROID OR IOS)
3055bec5421Sopenharmony_ci-  # No awk available to generate sources; use pre-built pnglibconf.h
3065bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
3075bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
3085bec5421Sopenharmony_ci-  add_custom_target(genfiles) # Dummy
3095bec5421Sopenharmony_ci-else()
3105bec5421Sopenharmony_ci-  # Copy the awk scripts, converting their line endings to Unix (LF)
3115bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk
3125bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk
3135bec5421Sopenharmony_ci-                 @ONLY
3145bec5421Sopenharmony_ci-                 NEWLINE_STYLE LF)
3155bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk
3165bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk
3175bec5421Sopenharmony_ci-                 @ONLY
3185bec5421Sopenharmony_ci-                 NEWLINE_STYLE LF)
3195bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/dfn.awk
3205bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/scripts/dfn.awk
3215bec5421Sopenharmony_ci-                 @ONLY
3225bec5421Sopenharmony_ci-                 NEWLINE_STYLE LF)
3235bec5421Sopenharmony_ci-
3245bec5421Sopenharmony_ci-  # Generate .chk from .out with awk:
3255bec5421Sopenharmony_ci-  # generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
3265bec5421Sopenharmony_ci-  include(CMakeParseArguments)
3275bec5421Sopenharmony_ci-  function(generate_chk)
3285bec5421Sopenharmony_ci-    set(options)
3295bec5421Sopenharmony_ci-    set(oneValueArgs INPUT OUTPUT)
3305bec5421Sopenharmony_ci-    set(multiValueArgs DEPENDS)
3315bec5421Sopenharmony_ci-    cmake_parse_arguments(_GC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3325bec5421Sopenharmony_ci-    if(NOT _GC_INPUT)
3335bec5421Sopenharmony_ci-      message(FATAL_ERROR "generate_chk: Missing INPUT argument")
3345bec5421Sopenharmony_ci-    endif()
3355bec5421Sopenharmony_ci-    if(NOT _GC_OUTPUT)
3365bec5421Sopenharmony_ci-      message(FATAL_ERROR "generate_chk: Missing OUTPUT argument")
3375bec5421Sopenharmony_ci-    endif()
3385bec5421Sopenharmony_ci-
3395bec5421Sopenharmony_ci-    add_custom_command(OUTPUT "${_GC_OUTPUT}"
3405bec5421Sopenharmony_ci-                       COMMAND "${CMAKE_COMMAND}"
3415bec5421Sopenharmony_ci-                               "-DINPUT=${_GC_INPUT}"
3425bec5421Sopenharmony_ci-                               "-DOUTPUT=${_GC_OUTPUT}"
3435bec5421Sopenharmony_ci-                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake"
3445bec5421Sopenharmony_ci-                       DEPENDS "${_GC_INPUT}" ${_GC_DEPENDS}
3455bec5421Sopenharmony_ci-                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
3465bec5421Sopenharmony_ci-  endfunction()
3475bec5421Sopenharmony_ci-
3485bec5421Sopenharmony_ci-  # Generate .out from .c with awk
3495bec5421Sopenharmony_ci-  # generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
3505bec5421Sopenharmony_ci-  function(generate_out)
3515bec5421Sopenharmony_ci-    set(options)
3525bec5421Sopenharmony_ci-    set(oneValueArgs INPUT OUTPUT)
3535bec5421Sopenharmony_ci-    set(multiValueArgs DEPENDS)
3545bec5421Sopenharmony_ci-    cmake_parse_arguments(_GO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3555bec5421Sopenharmony_ci-    if(NOT _GO_INPUT)
3565bec5421Sopenharmony_ci-      message(FATAL_ERROR "generate_out: Missing INPUT argument")
3575bec5421Sopenharmony_ci-    endif()
3585bec5421Sopenharmony_ci-    if(NOT _GO_OUTPUT)
3595bec5421Sopenharmony_ci-      message(FATAL_ERROR "generate_out: Missing OUTPUT argument")
3605bec5421Sopenharmony_ci-    endif()
3615bec5421Sopenharmony_ci-
3625bec5421Sopenharmony_ci-    add_custom_command(OUTPUT "${_GO_OUTPUT}"
3635bec5421Sopenharmony_ci-                       COMMAND "${CMAKE_COMMAND}"
3645bec5421Sopenharmony_ci-                               "-DINPUT=${_GO_INPUT}"
3655bec5421Sopenharmony_ci-                               "-DOUTPUT=${_GO_OUTPUT}"
3665bec5421Sopenharmony_ci-                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake"
3675bec5421Sopenharmony_ci-                       DEPENDS "${_GO_INPUT}" ${_GO_DEPENDS}
3685bec5421Sopenharmony_ci-                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
3695bec5421Sopenharmony_ci-  endfunction()
3705bec5421Sopenharmony_ci-
3715bec5421Sopenharmony_ci-  # Generate specific source file with awk
3725bec5421Sopenharmony_ci-  # generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]])
3735bec5421Sopenharmony_ci-  function(generate_source)
3745bec5421Sopenharmony_ci-    set(options)
3755bec5421Sopenharmony_ci-    set(oneValueArgs OUTPUT)
3765bec5421Sopenharmony_ci-    set(multiValueArgs DEPENDS)
3775bec5421Sopenharmony_ci-    cmake_parse_arguments(_GSO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3785bec5421Sopenharmony_ci-    if(NOT _GSO_OUTPUT)
3795bec5421Sopenharmony_ci-      message(FATAL_ERROR "generate_source: Missing OUTPUT argument")
3805bec5421Sopenharmony_ci-    endif()
3815bec5421Sopenharmony_ci-
3825bec5421Sopenharmony_ci-    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}"
3835bec5421Sopenharmony_ci-                       COMMAND "${CMAKE_COMMAND}"
3845bec5421Sopenharmony_ci-                               "-DOUTPUT=${_GSO_OUTPUT}"
3855bec5421Sopenharmony_ci-                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
3865bec5421Sopenharmony_ci-                       DEPENDS ${_GSO_DEPENDS}
3875bec5421Sopenharmony_ci-                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
3885bec5421Sopenharmony_ci-  endfunction()
3895bec5421Sopenharmony_ci-
3905bec5421Sopenharmony_ci-  # Copy file
3915bec5421Sopenharmony_ci-  # generate_copy(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
3925bec5421Sopenharmony_ci-  function(generate_copy)
3935bec5421Sopenharmony_ci-    set(options)
3945bec5421Sopenharmony_ci-    set(oneValueArgs INPUT OUTPUT)
3955bec5421Sopenharmony_ci-    set(multiValueArgs DEPENDS)
3965bec5421Sopenharmony_ci-    cmake_parse_arguments(_GCO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3975bec5421Sopenharmony_ci-    add_custom_command(OUTPUT "${_GCO_OUTPUT}"
3985bec5421Sopenharmony_ci-                       COMMAND "${CMAKE_COMMAND}"
3995bec5421Sopenharmony_ci-                               -E remove "${_GCO_OUTPUT}"
4005bec5421Sopenharmony_ci-                       COMMAND "${CMAKE_COMMAND}"
4015bec5421Sopenharmony_ci-                               -E copy "${_GCO_INPUT}" "${_GCO_OUTPUT}"
4025bec5421Sopenharmony_ci-                       DEPENDS "${source}" ${_GCO_DEPENDS})
4035bec5421Sopenharmony_ci-  endfunction()
4045bec5421Sopenharmony_ci-
4055bec5421Sopenharmony_ci-  # Generate scripts/pnglibconf.h
4065bec5421Sopenharmony_ci-  generate_source(OUTPUT "scripts/pnglibconf.c"
4075bec5421Sopenharmony_ci-                  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
4085bec5421Sopenharmony_ci-                          "${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
4095bec5421Sopenharmony_ci-                          "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
4105bec5421Sopenharmony_ci-  add_custom_target(scripts_pnglibconf_c DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c")
4115bec5421Sopenharmony_ci-
4125bec5421Sopenharmony_ci-  # Generate pnglibconf.c
4135bec5421Sopenharmony_ci-  generate_source(OUTPUT "pnglibconf.c"
4145bec5421Sopenharmony_ci-                  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
4155bec5421Sopenharmony_ci-                          "${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
4165bec5421Sopenharmony_ci-                          "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
4175bec5421Sopenharmony_ci-  add_custom_target(pnglibconf_c DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c")
4185bec5421Sopenharmony_ci-
4195bec5421Sopenharmony_ci-  if(PNG_PREFIX)
4205bec5421Sopenharmony_ci-    set(PNGLIBCONF_H_EXTRA_DEPENDS
4215bec5421Sopenharmony_ci-        "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
4225bec5421Sopenharmony_ci-        "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst")
4235bec5421Sopenharmony_ci-    set(PNGPREFIX_H_EXTRA_DEPENDS
4245bec5421Sopenharmony_ci-        "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
4255bec5421Sopenharmony_ci-  endif()
4265bec5421Sopenharmony_ci-
4275bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
4285bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
4295bec5421Sopenharmony_ci-               DEPENDS pnglibconf_c)
4305bec5421Sopenharmony_ci-  add_custom_target(pnglibconf_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")
4315bec5421Sopenharmony_ci-
4325bec5421Sopenharmony_ci-  # Generate pnglibconf.h
4335bec5421Sopenharmony_ci-  generate_source(OUTPUT "pnglibconf.h"
4345bec5421Sopenharmony_ci-                  DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out
4355bec5421Sopenharmony_ci-                          ${PNGLIBCONF_H_EXTRA_DEPENDS})
4365bec5421Sopenharmony_ci-  add_custom_target(pnglibconf_h DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")
4375bec5421Sopenharmony_ci-
4385bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c"
4395bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
4405bec5421Sopenharmony_ci-               DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
4415bec5421Sopenharmony_ci-  add_custom_target(scripts_intprefix_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
4425bec5421Sopenharmony_ci-
4435bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c"
4445bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
4455bec5421Sopenharmony_ci-               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
4465bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
4475bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out)
4485bec5421Sopenharmony_ci-  add_custom_target(scripts_prefix_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out")
4495bec5421Sopenharmony_ci-
4505bec5421Sopenharmony_ci-  # Generate pngprefix.h
4515bec5421Sopenharmony_ci-  generate_source(OUTPUT "pngprefix.h"
4525bec5421Sopenharmony_ci-                  DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS})
4535bec5421Sopenharmony_ci-  add_custom_target(pngprefix_h DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
4545bec5421Sopenharmony_ci-
4555bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c"
4565bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
4575bec5421Sopenharmony_ci-               DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
4585bec5421Sopenharmony_ci-  add_custom_target(scripts_sym_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out")
4595bec5421Sopenharmony_ci-
4605bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c"
4615bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
4625bec5421Sopenharmony_ci-               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
4635bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
4645bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt")
4655bec5421Sopenharmony_ci-  add_custom_target(scripts_symbols_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out")
4665bec5421Sopenharmony_ci-
4675bec5421Sopenharmony_ci-  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c"
4685bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
4695bec5421Sopenharmony_ci-               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
4705bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
4715bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
4725bec5421Sopenharmony_ci-  add_custom_target(scripts_vers_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out")
4735bec5421Sopenharmony_ci-
4745bec5421Sopenharmony_ci-  generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
4755bec5421Sopenharmony_ci-               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
4765bec5421Sopenharmony_ci-               DEPENDS scripts_symbols_out
4775bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk"
4785bec5421Sopenharmony_ci-                       "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def")
4795bec5421Sopenharmony_ci-
4805bec5421Sopenharmony_ci-  add_custom_target(scripts_symbols_chk
4815bec5421Sopenharmony_ci-                    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk")
4825bec5421Sopenharmony_ci-
4835bec5421Sopenharmony_ci-  generate_copy(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
4845bec5421Sopenharmony_ci-                OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym"
4855bec5421Sopenharmony_ci-                DEPENDS scripts_sym_out)
4865bec5421Sopenharmony_ci-  generate_copy(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
4875bec5421Sopenharmony_ci-                OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers"
4885bec5421Sopenharmony_ci-                DEPENDS scripts_vers_out)
4895bec5421Sopenharmony_ci-
4905bec5421Sopenharmony_ci-  add_custom_target(genvers
4915bec5421Sopenharmony_ci-                    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")
4925bec5421Sopenharmony_ci-  add_custom_target(gensym
4935bec5421Sopenharmony_ci-                    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")
4945bec5421Sopenharmony_ci-
4955bec5421Sopenharmony_ci-  add_custom_target("genprebuilt"
4965bec5421Sopenharmony_ci-                    COMMAND "${CMAKE_COMMAND}"
4975bec5421Sopenharmony_ci-                            "-DOUTPUT=scripts/pnglibconf.h.prebuilt"
4985bec5421Sopenharmony_ci-                            -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
4995bec5421Sopenharmony_ci-                    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
5005bec5421Sopenharmony_ci-
5015bec5421Sopenharmony_ci-  # A single target handles generation of all generated files.
5025bec5421Sopenharmony_ci-  add_custom_target(genfiles
5035bec5421Sopenharmony_ci-                    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym" gensym
5045bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers" genvers
5055bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" pnglibconf_c
5065bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h
5075bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out
5085bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h" pngprefix_h
5095bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" scripts_intprefix_out
5105bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c" scripts_pnglibconf_c
5115bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" scripts_prefix_out
5125bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" scripts_sym_out
5135bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" scripts_symbols_chk
5145bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" scripts_symbols_out
5155bec5421Sopenharmony_ci-                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" scripts_vers_out)
5165bec5421Sopenharmony_ci-endif(NOT AWK OR ANDROID OR IOS)
5175bec5421Sopenharmony_ci-
5185bec5421Sopenharmony_ci-# List the source code files.
5195bec5421Sopenharmony_ci-set(libpng_public_hdrs
5205bec5421Sopenharmony_ci-    png.h
5215bec5421Sopenharmony_ci-    pngconf.h
5225bec5421Sopenharmony_ci-    "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
5235bec5421Sopenharmony_ci-)
5245bec5421Sopenharmony_ci-set(libpng_private_hdrs
5255bec5421Sopenharmony_ci-    pngpriv.h
5265bec5421Sopenharmony_ci-    pngdebug.h
5275bec5421Sopenharmony_ci-    pnginfo.h
5285bec5421Sopenharmony_ci-    pngstruct.h
5295bec5421Sopenharmony_ci-)
5305bec5421Sopenharmony_ci-if(AWK AND NOT ANDROID AND NOT IOS)
5315bec5421Sopenharmony_ci-  list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
5325bec5421Sopenharmony_ci-endif()
5335bec5421Sopenharmony_ci-set(libpng_sources
5345bec5421Sopenharmony_ci-    ${libpng_public_hdrs}
5355bec5421Sopenharmony_ci-    ${libpng_private_hdrs}
5365bec5421Sopenharmony_ci-    png.c
5375bec5421Sopenharmony_ci-    pngerror.c
5385bec5421Sopenharmony_ci-    pngget.c
5395bec5421Sopenharmony_ci-    pngmem.c
5405bec5421Sopenharmony_ci-    pngpread.c
5415bec5421Sopenharmony_ci-    pngread.c
5425bec5421Sopenharmony_ci-    pngrio.c
5435bec5421Sopenharmony_ci-    pngrtran.c
5445bec5421Sopenharmony_ci-    pngrutil.c
5455bec5421Sopenharmony_ci-    pngset.c
5465bec5421Sopenharmony_ci-    pngtrans.c
5475bec5421Sopenharmony_ci-    pngwio.c
5485bec5421Sopenharmony_ci-    pngwrite.c
5495bec5421Sopenharmony_ci-    pngwtran.c
5505bec5421Sopenharmony_ci-    pngwutil.c
5515bec5421Sopenharmony_ci-    ${libpng_arm_sources}
5525bec5421Sopenharmony_ci-    ${libpng_intel_sources}
5535bec5421Sopenharmony_ci-    ${libpng_mips_sources}
5545bec5421Sopenharmony_ci-    ${libpng_powerpc_sources}
5555bec5421Sopenharmony_ci-)
5565bec5421Sopenharmony_ci-set(pngtest_sources
5575bec5421Sopenharmony_ci-    pngtest.c
5585bec5421Sopenharmony_ci-)
5595bec5421Sopenharmony_ci-set(pngvalid_sources
5605bec5421Sopenharmony_ci-    contrib/libtests/pngvalid.c
5615bec5421Sopenharmony_ci-)
5625bec5421Sopenharmony_ci-set(pngstest_sources
5635bec5421Sopenharmony_ci-    contrib/libtests/pngstest.c
5645bec5421Sopenharmony_ci-)
5655bec5421Sopenharmony_ci-set(pngunknown_sources
5665bec5421Sopenharmony_ci-    contrib/libtests/pngunknown.c
5675bec5421Sopenharmony_ci-)
5685bec5421Sopenharmony_ci-set(pngimage_sources
5695bec5421Sopenharmony_ci-    contrib/libtests/pngimage.c
5705bec5421Sopenharmony_ci-)
5715bec5421Sopenharmony_ci-set(pngfix_sources
5725bec5421Sopenharmony_ci-    contrib/tools/pngfix.c
5735bec5421Sopenharmony_ci-)
5745bec5421Sopenharmony_ci-set(png_fix_itxt_sources
5755bec5421Sopenharmony_ci-    contrib/tools/png-fix-itxt.c
5765bec5421Sopenharmony_ci-)
5775bec5421Sopenharmony_ci-
5785bec5421Sopenharmony_ci-if(MSVC)
5795bec5421Sopenharmony_ci-  add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
5805bec5421Sopenharmony_ci-endif()
5815bec5421Sopenharmony_ci-
5825bec5421Sopenharmony_ci-if(PNG_DEBUG)
5835bec5421Sopenharmony_ci-  add_definitions(-DPNG_DEBUG)
5845bec5421Sopenharmony_ci-endif()
5855bec5421Sopenharmony_ci-
5865bec5421Sopenharmony_ci-# Now build our target.
5875bec5421Sopenharmony_ci-include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIRS})
5885bec5421Sopenharmony_ci-
5895bec5421Sopenharmony_ci-unset(PNG_LIB_TARGETS)
5905bec5421Sopenharmony_ci-
5915bec5421Sopenharmony_ci-if(PNG_SHARED)
5925bec5421Sopenharmony_ci-  add_library(png SHARED ${libpng_sources})
5935bec5421Sopenharmony_ci-  set(PNG_LIB_TARGETS png)
5945bec5421Sopenharmony_ci-  set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME})
5955bec5421Sopenharmony_ci-  add_dependencies(png genfiles)
5965bec5421Sopenharmony_ci-  if(MSVC)
5975bec5421Sopenharmony_ci-    # MVC does not append 'lib'. Do it here, to have consistent name.
5985bec5421Sopenharmony_ci-    set_target_properties(png PROPERTIES PREFIX "lib")
5995bec5421Sopenharmony_ci-    set_target_properties(png PROPERTIES IMPORT_PREFIX "lib")
6005bec5421Sopenharmony_ci-  endif()
6015bec5421Sopenharmony_ci-  target_link_libraries(png ${ZLIB_LIBRARIES} ${M_LIBRARY})
6025bec5421Sopenharmony_ci-
6035bec5421Sopenharmony_ci-  if(UNIX AND AWK)
6045bec5421Sopenharmony_ci-    if(HAVE_LD_VERSION_SCRIPT)
6055bec5421Sopenharmony_ci-      set_target_properties(png PROPERTIES
6065bec5421Sopenharmony_ci-                            LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
6075bec5421Sopenharmony_ci-    elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)
6085bec5421Sopenharmony_ci-      set_target_properties(png PROPERTIES
6095bec5421Sopenharmony_ci-                            LINK_FLAGS "-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
6105bec5421Sopenharmony_ci-    endif()
6115bec5421Sopenharmony_ci-  endif()
6125bec5421Sopenharmony_ci-endif()
6135bec5421Sopenharmony_ci-
6145bec5421Sopenharmony_ci-if(PNG_STATIC)
6155bec5421Sopenharmony_ci-  # does not work without changing name
6165bec5421Sopenharmony_ci-  set(PNG_LIB_NAME_STATIC png_static)
6175bec5421Sopenharmony_ci-  add_library(png_static STATIC ${libpng_sources})
6185bec5421Sopenharmony_ci-  add_dependencies(png_static genfiles)
6195bec5421Sopenharmony_ci-  # MSVC doesn't use a different file extension for shared vs. static
6205bec5421Sopenharmony_ci-  # libs. We are able to change OUTPUT_NAME to remove the _static
6215bec5421Sopenharmony_ci-  # for all other platforms.
6225bec5421Sopenharmony_ci-  if(NOT MSVC)
6235bec5421Sopenharmony_ci-    set_target_properties(png_static PROPERTIES
6245bec5421Sopenharmony_ci-                          OUTPUT_NAME "${PNG_LIB_NAME}"
6255bec5421Sopenharmony_ci-                          CLEAN_DIRECT_OUTPUT 1)
6265bec5421Sopenharmony_ci-  else()
6275bec5421Sopenharmony_ci-    set_target_properties(png_static PROPERTIES
6285bec5421Sopenharmony_ci-                          OUTPUT_NAME "${PNG_LIB_NAME}_static"
6295bec5421Sopenharmony_ci-                          CLEAN_DIRECT_OUTPUT 1)
6305bec5421Sopenharmony_ci-  endif()
6315bec5421Sopenharmony_ci-  list(APPEND PNG_LIB_TARGETS png_static)
6325bec5421Sopenharmony_ci-  if(MSVC)
6335bec5421Sopenharmony_ci-    # MSVC does not append 'lib'. Do it here, to have consistent name.
6345bec5421Sopenharmony_ci-    set_target_properties(png_static PROPERTIES PREFIX "lib")
6355bec5421Sopenharmony_ci-  endif()
6365bec5421Sopenharmony_ci-  target_link_libraries(png_static ${ZLIB_LIBRARIES} ${M_LIBRARY})
6375bec5421Sopenharmony_ci-endif()
6385bec5421Sopenharmony_ci-
6395bec5421Sopenharmony_ci-if(PNG_FRAMEWORK)
6405bec5421Sopenharmony_ci-  set(PNG_LIB_NAME_FRAMEWORK png_framework)
6415bec5421Sopenharmony_ci-  add_library(png_framework SHARED ${libpng_sources})
6425bec5421Sopenharmony_ci-  add_dependencies(png_framework genfiles)
6435bec5421Sopenharmony_ci-  list(APPEND PNG_LIB_TARGETS png_framework)
6445bec5421Sopenharmony_ci-  set_target_properties(png_framework PROPERTIES
6455bec5421Sopenharmony_ci-                        FRAMEWORK TRUE
6465bec5421Sopenharmony_ci-                        FRAMEWORK_VERSION ${PNGLIB_VERSION}
6475bec5421Sopenharmony_ci-                        MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
6485bec5421Sopenharmony_ci-                        MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}
6495bec5421Sopenharmony_ci-                        MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng
6505bec5421Sopenharmony_ci-                        XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
6515bec5421Sopenharmony_ci-                        PUBLIC_HEADER "${libpng_public_hdrs}"
6525bec5421Sopenharmony_ci-                        OUTPUT_NAME png)
6535bec5421Sopenharmony_ci-  target_link_libraries(png_framework ${ZLIB_LIBRARIES} ${M_LIBRARY})
6545bec5421Sopenharmony_ci-endif()
6555bec5421Sopenharmony_ci-
6565bec5421Sopenharmony_ci-if(NOT PNG_LIB_TARGETS)
6575bec5421Sopenharmony_ci-  message(SEND_ERROR "No library variant selected to build. "
6585bec5421Sopenharmony_ci-                     "Please enable at least one of the following options: "
6595bec5421Sopenharmony_ci-                     "PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK")
6605bec5421Sopenharmony_ci-endif()
6615bec5421Sopenharmony_ci-
6625bec5421Sopenharmony_ci-if(PNG_SHARED AND WIN32)
6635bec5421Sopenharmony_ci-  set_target_properties(png PROPERTIES
6645bec5421Sopenharmony_ci-                        DEFINE_SYMBOL PNG_BUILD_DLL)
6655bec5421Sopenharmony_ci-endif()
6665bec5421Sopenharmony_ci-
6675bec5421Sopenharmony_ci-function(png_add_test)
6685bec5421Sopenharmony_ci-  set(options)
6695bec5421Sopenharmony_ci-  set(oneValueArgs NAME COMMAND)
6705bec5421Sopenharmony_ci-  set(multiValueArgs OPTIONS FILES)
6715bec5421Sopenharmony_ci-  cmake_parse_arguments(_PAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
6725bec5421Sopenharmony_ci-
6735bec5421Sopenharmony_ci-  if(NOT _PAT_NAME)
6745bec5421Sopenharmony_ci-    message(FATAL_ERROR "png_add_test: Missing NAME argument")
6755bec5421Sopenharmony_ci-  endif()
6765bec5421Sopenharmony_ci-  if(NOT _PAT_COMMAND)
6775bec5421Sopenharmony_ci-    message(FATAL_ERROR "png_add_test: Missing COMMAND argument")
6785bec5421Sopenharmony_ci-  endif()
6795bec5421Sopenharmony_ci-
6805bec5421Sopenharmony_ci-  set(TEST_OPTIONS "${_PAT_OPTIONS}")
6815bec5421Sopenharmony_ci-  set(TEST_FILES "${_PAT_FILES}")
6825bec5421Sopenharmony_ci-
6835bec5421Sopenharmony_ci-  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scripts/test.cmake.in"
6845bec5421Sopenharmony_ci-                 "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake"
6855bec5421Sopenharmony_ci-                 @ONLY)
6865bec5421Sopenharmony_ci-  add_test(NAME "${_PAT_NAME}"
6875bec5421Sopenharmony_ci-           COMMAND "${CMAKE_COMMAND}"
6885bec5421Sopenharmony_ci-                   "-DLIBPNG=$<TARGET_FILE:png>"
6895bec5421Sopenharmony_ci-                   "-DTEST_COMMAND=$<TARGET_FILE:${_PAT_COMMAND}>"
6905bec5421Sopenharmony_ci-                   -P "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake")
6915bec5421Sopenharmony_ci-endfunction()
6925bec5421Sopenharmony_ci-
6935bec5421Sopenharmony_ci-if(PNG_TESTS AND PNG_SHARED)
6945bec5421Sopenharmony_ci-  # Find test PNG files by globbing, but sort lists to ensure
6955bec5421Sopenharmony_ci-  # consistency between different filesystems.
6965bec5421Sopenharmony_ci-  file(GLOB PNGSUITE_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png")
6975bec5421Sopenharmony_ci-  list(SORT PNGSUITE_PNGS)
6985bec5421Sopenharmony_ci-  file(GLOB TEST_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png")
6995bec5421Sopenharmony_ci-  list(SORT TEST_PNGS)
7005bec5421Sopenharmony_ci-
7015bec5421Sopenharmony_ci-  set(PNGTEST_PNG "${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png")
7025bec5421Sopenharmony_ci-
7035bec5421Sopenharmony_ci-  add_executable(pngtest ${pngtest_sources})
7045bec5421Sopenharmony_ci-  target_link_libraries(pngtest png)
7055bec5421Sopenharmony_ci-
7065bec5421Sopenharmony_ci-  png_add_test(NAME pngtest
7075bec5421Sopenharmony_ci-               COMMAND pngtest
7085bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
7095bec5421Sopenharmony_ci-
7105bec5421Sopenharmony_ci-  add_executable(pngvalid ${pngvalid_sources})
7115bec5421Sopenharmony_ci-  target_link_libraries(pngvalid png)
7125bec5421Sopenharmony_ci-
7135bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-16-to-8
7145bec5421Sopenharmony_ci-               COMMAND pngvalid
7155bec5421Sopenharmony_ci-               OPTIONS --gamma-16-to-8)
7165bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-alpha-mode
7175bec5421Sopenharmony_ci-               COMMAND pngvalid
7185bec5421Sopenharmony_ci-               OPTIONS --gamma-alpha-mode)
7195bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-background
7205bec5421Sopenharmony_ci-               COMMAND pngvalid
7215bec5421Sopenharmony_ci-               OPTIONS --gamma-background)
7225bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-expand16-alpha-mode
7235bec5421Sopenharmony_ci-               COMMAND pngvalid
7245bec5421Sopenharmony_ci-               OPTIONS --gamma-alpha-mode --expand16)
7255bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-expand16-background
7265bec5421Sopenharmony_ci-               COMMAND pngvalid
7275bec5421Sopenharmony_ci-               OPTIONS --gamma-background --expand16)
7285bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-expand16-transform
7295bec5421Sopenharmony_ci-               COMMAND pngvalid
7305bec5421Sopenharmony_ci-               OPTIONS --gamma-transform --expand16)
7315bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-sbit
7325bec5421Sopenharmony_ci-               COMMAND pngvalid
7335bec5421Sopenharmony_ci-               OPTIONS --gamma-sbit)
7345bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-threshold
7355bec5421Sopenharmony_ci-               COMMAND pngvalid
7365bec5421Sopenharmony_ci-               OPTIONS --gamma-threshold)
7375bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-gamma-transform
7385bec5421Sopenharmony_ci-               COMMAND pngvalid
7395bec5421Sopenharmony_ci-               OPTIONS --gamma-transform)
7405bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-progressive-interlace-standard
7415bec5421Sopenharmony_ci-               COMMAND pngvalid
7425bec5421Sopenharmony_ci-               OPTIONS --standard --progressive-read --interlace)
7435bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-progressive-size
7445bec5421Sopenharmony_ci-               COMMAND pngvalid
7455bec5421Sopenharmony_ci-               OPTIONS --size --progressive-read)
7465bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-progressive-standard
7475bec5421Sopenharmony_ci-               COMMAND pngvalid
7485bec5421Sopenharmony_ci-               OPTIONS --standard --progressive-read)
7495bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-standard
7505bec5421Sopenharmony_ci-               COMMAND pngvalid
7515bec5421Sopenharmony_ci-               OPTIONS --standard)
7525bec5421Sopenharmony_ci-  png_add_test(NAME pngvalid-transform
7535bec5421Sopenharmony_ci-               COMMAND pngvalid
7545bec5421Sopenharmony_ci-               OPTIONS --transform)
7555bec5421Sopenharmony_ci-
7565bec5421Sopenharmony_ci-  add_executable(pngstest ${pngstest_sources})
7575bec5421Sopenharmony_ci-  target_link_libraries(pngstest png)
7585bec5421Sopenharmony_ci-
7595bec5421Sopenharmony_ci-  foreach(gamma_type 1.8 linear none sRGB)
7605bec5421Sopenharmony_ci-    foreach(alpha_type none alpha)
7615bec5421Sopenharmony_ci-      set(PNGSTEST_FILES)
7625bec5421Sopenharmony_ci-      foreach(test_png ${TEST_PNGS})
7635bec5421Sopenharmony_ci-        string(REGEX MATCH ".*-linear[-.].*" TEST_PNG_LINEAR "${test_png}")
7645bec5421Sopenharmony_ci-        string(REGEX MATCH ".*-sRGB[-.].*" TEST_PNG_SRGB "${test_png}")
7655bec5421Sopenharmony_ci-        string(REGEX MATCH ".*-1.8[-.].*" TEST_PNG_G18 "${test_png}")
7665bec5421Sopenharmony_ci-        string(REGEX MATCH ".*-alpha-.*" TEST_PNG_ALPHA "${test_png}")
7675bec5421Sopenharmony_ci-
7685bec5421Sopenharmony_ci-        set(TEST_PNG_VALID TRUE)
7695bec5421Sopenharmony_ci-
7705bec5421Sopenharmony_ci-        if(TEST_PNG_ALPHA)
7715bec5421Sopenharmony_ci-          if(NOT "${alpha_type}" STREQUAL "alpha")
7725bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7735bec5421Sopenharmony_ci-          endif()
7745bec5421Sopenharmony_ci-        else()
7755bec5421Sopenharmony_ci-          if("${alpha_type}" STREQUAL "alpha")
7765bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7775bec5421Sopenharmony_ci-          endif()
7785bec5421Sopenharmony_ci-        endif()
7795bec5421Sopenharmony_ci-
7805bec5421Sopenharmony_ci-        if(TEST_PNG_LINEAR)
7815bec5421Sopenharmony_ci-          if(NOT "${gamma_type}" STREQUAL "linear")
7825bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7835bec5421Sopenharmony_ci-          endif()
7845bec5421Sopenharmony_ci-        elseif(TEST_PNG_SRGB)
7855bec5421Sopenharmony_ci-          if(NOT "${gamma_type}" STREQUAL "sRGB")
7865bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7875bec5421Sopenharmony_ci-          endif()
7885bec5421Sopenharmony_ci-        elseif(TEST_PNG_G18)
7895bec5421Sopenharmony_ci-          if(NOT "${gamma_type}" STREQUAL "1.8")
7905bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7915bec5421Sopenharmony_ci-          endif()
7925bec5421Sopenharmony_ci-        else()
7935bec5421Sopenharmony_ci-          if(NOT "${gamma_type}" STREQUAL "none")
7945bec5421Sopenharmony_ci-            set(TEST_PNG_VALID FALSE)
7955bec5421Sopenharmony_ci-          endif()
7965bec5421Sopenharmony_ci-        endif()
7975bec5421Sopenharmony_ci-
7985bec5421Sopenharmony_ci-        if(TEST_PNG_VALID)
7995bec5421Sopenharmony_ci-          list(APPEND PNGSTEST_FILES "${test_png}")
8005bec5421Sopenharmony_ci-        endif()
8015bec5421Sopenharmony_ci-      endforeach()
8025bec5421Sopenharmony_ci-      # Should already be sorted, but sort anyway to be certain.
8035bec5421Sopenharmony_ci-      list(SORT PNGSTEST_FILES)
8045bec5421Sopenharmony_ci-      png_add_test(NAME pngstest-${gamma_type}-${alpha_type}
8055bec5421Sopenharmony_ci-                   COMMAND pngstest
8065bec5421Sopenharmony_ci-                   OPTIONS --tmpfile "${gamma_type}-${alpha_type}-" --log
8075bec5421Sopenharmony_ci-                   FILES ${PNGSTEST_FILES})
8085bec5421Sopenharmony_ci-    endforeach()
8095bec5421Sopenharmony_ci-  endforeach()
8105bec5421Sopenharmony_ci-
8115bec5421Sopenharmony_ci-  add_executable(pngunknown ${pngunknown_sources})
8125bec5421Sopenharmony_ci-  target_link_libraries(pngunknown png)
8135bec5421Sopenharmony_ci-
8145bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-discard
8155bec5421Sopenharmony_ci-               COMMAND pngunknown
8165bec5421Sopenharmony_ci-               OPTIONS --strict default=discard
8175bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8185bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-IDAT
8195bec5421Sopenharmony_ci-               COMMAND pngunknown
8205bec5421Sopenharmony_ci-               OPTIONS --strict default=discard IDAT=save
8215bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8225bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-if-safe
8235bec5421Sopenharmony_ci-               COMMAND pngunknown
8245bec5421Sopenharmony_ci-               OPTIONS --strict default=if-safe
8255bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8265bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-sAPI
8275bec5421Sopenharmony_ci-               COMMAND pngunknown
8285bec5421Sopenharmony_ci-               OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save
8295bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8305bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-save
8315bec5421Sopenharmony_ci-               COMMAND pngunknown
8325bec5421Sopenharmony_ci-               OPTIONS --strict default=save
8335bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8345bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-sTER
8355bec5421Sopenharmony_ci-               COMMAND pngunknown
8365bec5421Sopenharmony_ci-               OPTIONS --strict sTER=if-safe
8375bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8385bec5421Sopenharmony_ci-  png_add_test(NAME pngunknown-vpAg
8395bec5421Sopenharmony_ci-               COMMAND pngunknown
8405bec5421Sopenharmony_ci-               OPTIONS --strict vpAg=if-safe
8415bec5421Sopenharmony_ci-               FILES "${PNGTEST_PNG}")
8425bec5421Sopenharmony_ci-
8435bec5421Sopenharmony_ci-  add_executable(pngimage ${pngimage_sources})
8445bec5421Sopenharmony_ci-  target_link_libraries(pngimage png)
8455bec5421Sopenharmony_ci-
8465bec5421Sopenharmony_ci-  png_add_test(NAME pngimage-quick
8475bec5421Sopenharmony_ci-               COMMAND pngimage
8485bec5421Sopenharmony_ci-               OPTIONS --list-combos --log
8495bec5421Sopenharmony_ci-               FILES ${PNGSUITE_PNGS})
8505bec5421Sopenharmony_ci-  png_add_test(NAME pngimage-full
8515bec5421Sopenharmony_ci-               COMMAND pngimage
8525bec5421Sopenharmony_ci-               OPTIONS --exhaustive --list-combos --log
8535bec5421Sopenharmony_ci-               FILES ${PNGSUITE_PNGS})
8545bec5421Sopenharmony_ci-endif()
8555bec5421Sopenharmony_ci-
8565bec5421Sopenharmony_ci-if(PNG_SHARED AND PNG_EXECUTABLES)
8575bec5421Sopenharmony_ci-  add_executable(pngfix ${pngfix_sources})
8585bec5421Sopenharmony_ci-  target_link_libraries(pngfix png)
8595bec5421Sopenharmony_ci-  set(PNG_BIN_TARGETS pngfix)
8605bec5421Sopenharmony_ci-
8615bec5421Sopenharmony_ci-  add_executable(png-fix-itxt ${png_fix_itxt_sources})
8625bec5421Sopenharmony_ci-  target_link_libraries(png-fix-itxt ${ZLIB_LIBRARIES} ${M_LIBRARY})
8635bec5421Sopenharmony_ci-  list(APPEND PNG_BIN_TARGETS png-fix-itxt)
8645bec5421Sopenharmony_ci-endif()
8655bec5421Sopenharmony_ci-
8665bec5421Sopenharmony_ci-# Creates a symlink from src to dest (if possible), or, alternatively,
8675bec5421Sopenharmony_ci-# copies src to dest if different.
8685bec5421Sopenharmony_ci-include(CMakeParseArguments)
8695bec5421Sopenharmony_ci-function(create_symlink DEST_FILE)
8705bec5421Sopenharmony_ci-  cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
8715bec5421Sopenharmony_ci-
8725bec5421Sopenharmony_ci-  if(NOT S_TARGET AND NOT S_FILE)
8735bec5421Sopenharmony_ci-    message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
8745bec5421Sopenharmony_ci-  endif()
8755bec5421Sopenharmony_ci-
8765bec5421Sopenharmony_ci-  if(S_TARGET AND S_FILE)
8775bec5421Sopenharmony_ci-    message(FATAL_ERROR "create_symlink: "
8785bec5421Sopenharmony_ci-                        "Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; "
8795bec5421Sopenharmony_ci-                        "can only have one")
8805bec5421Sopenharmony_ci-  endif()
8815bec5421Sopenharmony_ci-
8825bec5421Sopenharmony_ci-  if(S_FILE)
8835bec5421Sopenharmony_ci-    # If we don't need to symlink something that's coming from a build target,
8845bec5421Sopenharmony_ci-    # we can go ahead and symlink/copy at configure time.
8855bec5421Sopenharmony_ci-    if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
8865bec5421Sopenharmony_ci-      execute_process(COMMAND "${CMAKE_COMMAND}"
8875bec5421Sopenharmony_ci-                              -E copy_if_different
8885bec5421Sopenharmony_ci-                              ${S_FILE} ${DEST_FILE}
8895bec5421Sopenharmony_ci-                      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
8905bec5421Sopenharmony_ci-    else()
8915bec5421Sopenharmony_ci-      execute_process(COMMAND "${CMAKE_COMMAND}"
8925bec5421Sopenharmony_ci-                              -E create_symlink
8935bec5421Sopenharmony_ci-                              ${S_FILE} ${DEST_FILE}
8945bec5421Sopenharmony_ci-                      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
8955bec5421Sopenharmony_ci-    endif()
8965bec5421Sopenharmony_ci-  endif()
8975bec5421Sopenharmony_ci-
8985bec5421Sopenharmony_ci-  if(S_TARGET)
8995bec5421Sopenharmony_ci-    # We need to use generator expressions, which can be a bit tricky.
9005bec5421Sopenharmony_ci-    # For simplicity, make the symlink a POST_BUILD step, and use the TARGET
9015bec5421Sopenharmony_ci-    # signature of add_custom_command.
9025bec5421Sopenharmony_ci-    if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
9035bec5421Sopenharmony_ci-      add_custom_command(TARGET ${S_TARGET}
9045bec5421Sopenharmony_ci-                         POST_BUILD
9055bec5421Sopenharmony_ci-                         COMMAND "${CMAKE_COMMAND}"
9065bec5421Sopenharmony_ci-                                 -E copy_if_different
9075bec5421Sopenharmony_ci-                                 $<TARGET_LINKER_FILE_NAME:${S_TARGET}>
9085bec5421Sopenharmony_ci-                                 $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
9095bec5421Sopenharmony_ci-    else()
9105bec5421Sopenharmony_ci-      add_custom_command(TARGET ${S_TARGET}
9115bec5421Sopenharmony_ci-                         POST_BUILD
9125bec5421Sopenharmony_ci-                         COMMAND "${CMAKE_COMMAND}"
9135bec5421Sopenharmony_ci-                                 -E create_symlink
9145bec5421Sopenharmony_ci-                                 $<TARGET_LINKER_FILE_NAME:${S_TARGET}>
9155bec5421Sopenharmony_ci-                                 $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
9165bec5421Sopenharmony_ci-    endif()
9175bec5421Sopenharmony_ci-  endif()
9185bec5421Sopenharmony_ci-endfunction()
9195bec5421Sopenharmony_ci-
9205bec5421Sopenharmony_ci-# Create source generation scripts.
9215bec5421Sopenharmony_ci-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in
9225bec5421Sopenharmony_ci-               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake
9235bec5421Sopenharmony_ci-               @ONLY)
9245bec5421Sopenharmony_ci-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in
9255bec5421Sopenharmony_ci-               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake
9265bec5421Sopenharmony_ci-               @ONLY)
9275bec5421Sopenharmony_ci-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in
9285bec5421Sopenharmony_ci-               ${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake
9295bec5421Sopenharmony_ci-               @ONLY)
9305bec5421Sopenharmony_ci-
9315bec5421Sopenharmony_ci-# libpng is a library so default to 'lib'
9325bec5421Sopenharmony_ci-if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
9335bec5421Sopenharmony_ci-  set(CMAKE_INSTALL_LIBDIR lib)
9345bec5421Sopenharmony_ci-endif()
9355bec5421Sopenharmony_ci-
9365bec5421Sopenharmony_ci-# Create pkgconfig files.
9375bec5421Sopenharmony_ci-# We use the same files like ./configure, so we have to set its vars.
9385bec5421Sopenharmony_ci-# Only do this on Windows for Cygwin - the files don't make much sense
9395bec5421Sopenharmony_ci-# outside of a UNIX look-alike.
9405bec5421Sopenharmony_ci-if(NOT WIN32 OR CYGWIN OR MINGW)
9415bec5421Sopenharmony_ci-  set(prefix      ${CMAKE_INSTALL_PREFIX})
9425bec5421Sopenharmony_ci-  set(exec_prefix ${CMAKE_INSTALL_PREFIX})
9435bec5421Sopenharmony_ci-  set(libdir      ${CMAKE_INSTALL_FULL_LIBDIR})
9445bec5421Sopenharmony_ci-  set(includedir  ${CMAKE_INSTALL_FULL_INCLUDEDIR})
9455bec5421Sopenharmony_ci-  set(LIBS        "-lz -lm")
9465bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
9475bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
9485bec5421Sopenharmony_ci-                 @ONLY)
9495bec5421Sopenharmony_ci-  create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
9505bec5421Sopenharmony_ci-  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
9515bec5421Sopenharmony_ci-                 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
9525bec5421Sopenharmony_ci-                 @ONLY)
9535bec5421Sopenharmony_ci-  create_symlink(libpng-config FILE ${PNGLIB_NAME}-config)
9545bec5421Sopenharmony_ci-endif()
9555bec5421Sopenharmony_ci-
9565bec5421Sopenharmony_ci-# Set up links.
9575bec5421Sopenharmony_ci-if(PNG_SHARED)
9585bec5421Sopenharmony_ci-  set_target_properties(png PROPERTIES
9595bec5421Sopenharmony_ci-    VERSION ${PNGLIB_SHARED_VERSION}
9605bec5421Sopenharmony_ci-    SOVERSION ${PNGLIB_SHARED_SOVERSION}
9615bec5421Sopenharmony_ci-    CLEAN_DIRECT_OUTPUT 1)
9625bec5421Sopenharmony_ci-endif()
9635bec5421Sopenharmony_ci-
9645bec5421Sopenharmony_ci-# Install.
9655bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
9665bec5421Sopenharmony_ci-  install(TARGETS ${PNG_LIB_TARGETS}
9675bec5421Sopenharmony_ci-          EXPORT libpng
9685bec5421Sopenharmony_ci-          RUNTIME DESTINATION bin
9695bec5421Sopenharmony_ci-          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
9705bec5421Sopenharmony_ci-          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
9715bec5421Sopenharmony_ci-          FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
9725bec5421Sopenharmony_ci-
9735bec5421Sopenharmony_ci-  if(PNG_SHARED)
9745bec5421Sopenharmony_ci-    # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
9755bec5421Sopenharmony_ci-    if(CYGWIN OR MINGW)
9765bec5421Sopenharmony_ci-      create_symlink(libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET png)
9775bec5421Sopenharmony_ci-      install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
9785bec5421Sopenharmony_ci-              DESTINATION ${CMAKE_INSTALL_LIBDIR})
9795bec5421Sopenharmony_ci-    endif()
9805bec5421Sopenharmony_ci-
9815bec5421Sopenharmony_ci-    if(NOT WIN32)
9825bec5421Sopenharmony_ci-      create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png)
9835bec5421Sopenharmony_ci-      install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
9845bec5421Sopenharmony_ci-              DESTINATION ${CMAKE_INSTALL_LIBDIR})
9855bec5421Sopenharmony_ci-    endif()
9865bec5421Sopenharmony_ci-  endif()
9875bec5421Sopenharmony_ci-
9885bec5421Sopenharmony_ci-  if(PNG_STATIC)
9895bec5421Sopenharmony_ci-    if(NOT WIN32 OR CYGWIN OR MINGW)
9905bec5421Sopenharmony_ci-      create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static)
9915bec5421Sopenharmony_ci-      install(FILES $<TARGET_LINKER_FILE_DIR:png_static>/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
9925bec5421Sopenharmony_ci-              DESTINATION ${CMAKE_INSTALL_LIBDIR})
9935bec5421Sopenharmony_ci-    endif()
9945bec5421Sopenharmony_ci-  endif()
9955bec5421Sopenharmony_ci-endif()
9965bec5421Sopenharmony_ci-
9975bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
9985bec5421Sopenharmony_ci-  install(FILES ${libpng_public_hdrs}
9995bec5421Sopenharmony_ci-          DESTINATION include)
10005bec5421Sopenharmony_ci-  install(FILES ${libpng_public_hdrs}
10015bec5421Sopenharmony_ci-          DESTINATION include/${PNGLIB_NAME})
10025bec5421Sopenharmony_ci-endif()
10035bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL)
10045bec5421Sopenharmony_ci-  if(NOT WIN32 OR CYGWIN OR MINGW)
10055bec5421Sopenharmony_ci-    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
10065bec5421Sopenharmony_ci-            DESTINATION bin)
10075bec5421Sopenharmony_ci-    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
10085bec5421Sopenharmony_ci-            DESTINATION bin)
10095bec5421Sopenharmony_ci-  endif()
10105bec5421Sopenharmony_ci-endif()
10115bec5421Sopenharmony_ci-
10125bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL)
10135bec5421Sopenharmony_ci-  install(TARGETS ${PNG_BIN_TARGETS}
10145bec5421Sopenharmony_ci-          RUNTIME DESTINATION bin)
10155bec5421Sopenharmony_ci-endif()
10165bec5421Sopenharmony_ci-
10175bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
10185bec5421Sopenharmony_ci-  # Install the man pages.
10195bec5421Sopenharmony_ci-  install(FILES libpng.3 libpngpf.3
10205bec5421Sopenharmony_ci-          DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
10215bec5421Sopenharmony_ci-  install(FILES png.5
10225bec5421Sopenharmony_ci-          DESTINATION ${CMAKE_INSTALL_MANDIR}/man5)
10235bec5421Sopenharmony_ci-  # Install the pkg-config files.
10245bec5421Sopenharmony_ci-  if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
10255bec5421Sopenharmony_ci-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
10265bec5421Sopenharmony_ci-            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
10275bec5421Sopenharmony_ci-    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
10285bec5421Sopenharmony_ci-            DESTINATION ${CMAKE_INSTALL_BINDIR})
10295bec5421Sopenharmony_ci-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
10305bec5421Sopenharmony_ci-            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
10315bec5421Sopenharmony_ci-    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
10325bec5421Sopenharmony_ci-            DESTINATION ${CMAKE_INSTALL_BINDIR})
10335bec5421Sopenharmony_ci-  endif()
10345bec5421Sopenharmony_ci-endif()
10355bec5421Sopenharmony_ci-
10365bec5421Sopenharmony_ci-# Create an export file that CMake users can include() to import our targets.
10375bec5421Sopenharmony_ci-if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL)
10385bec5421Sopenharmony_ci-  install(EXPORT libpng
10395bec5421Sopenharmony_ci-          DESTINATION lib/libpng
10405bec5421Sopenharmony_ci-          FILE lib${PNG_LIB_NAME}.cmake)
10415bec5421Sopenharmony_ci-endif()
10425bec5421Sopenharmony_ci-
10435bec5421Sopenharmony_ci-# TODO: Create MSVC import lib for MinGW-compiled shared lib.
10445bec5421Sopenharmony_ci-# pexports libpng.dll > libpng.def
10455bec5421Sopenharmony_ci-# lib /def:libpng.def /machine:x86
10465bec5421Sopenharmony_ci+cmake_minimum_required(VERSION 3.16.5)
10475bec5421Sopenharmony_ci+
10485bec5421Sopenharmony_ci+set(LibpngInc "${PROJECT_SOURCE_DIR}/third_party/libpng")
10495bec5421Sopenharmony_ci+set(LibpngSrc "${PROJECT_SOURCE_DIR}/third_party/libpng")
10505bec5421Sopenharmony_ci+
10515bec5421Sopenharmony_ci+include_directories(${LibpngInc})
10525bec5421Sopenharmony_ci+message(${LibpngSrc})
10535bec5421Sopenharmony_ci+add_library(libpng STATIC
10545bec5421Sopenharmony_ci+    ${LibpngSrc}/png.c
10555bec5421Sopenharmony_ci+    ${LibpngSrc}/pngerror.c
10565bec5421Sopenharmony_ci+    ${LibpngSrc}/pngget.c
10575bec5421Sopenharmony_ci+    ${LibpngSrc}/pngmem.c
10585bec5421Sopenharmony_ci+    ${LibpngSrc}/pngpread.c
10595bec5421Sopenharmony_ci+    ${LibpngSrc}/pngread.c
10605bec5421Sopenharmony_ci+    ${LibpngSrc}/pngrio.c
10615bec5421Sopenharmony_ci+    ${LibpngSrc}/pngrtran.c
10625bec5421Sopenharmony_ci+    ${LibpngSrc}/pngrutil.c
10635bec5421Sopenharmony_ci+    ${LibpngSrc}/pngset.c
10645bec5421Sopenharmony_ci+    ${LibpngSrc}/pngtrans.c
10655bec5421Sopenharmony_ci+    ${LibpngSrc}/pngwio.c
10665bec5421Sopenharmony_ci+    ${LibpngSrc}/pngwrite.c
10675bec5421Sopenharmony_ci+    ${LibpngSrc}/pngwtran.c
10685bec5421Sopenharmony_ci+    ${LibpngSrc}/pngwutil.c
10695bec5421Sopenharmony_ci+    )
10705bec5421Sopenharmony_ci+target_link_libraries(libpng PUBLIC zlib)
10715bec5421Sopenharmony_ci+target_include_directories(libpng PUBLIC ${LibpngInc})
1072