Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 1 | # CMakeLists.txt |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 2 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 3 | # Copyright (c) 2018-2020 Cosmin Truta |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 4 | # Copyright (c) 2007,2009-2018 Glenn Randers-Pehrson |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 5 | # Written by Christian Ehrlicher, 2007 |
| 6 | # Revised by Roger Lowman, 2009-2010 |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 7 | # Revised by Clifford Yapp, 2011-2012,2017 |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 8 | # Revised by Roger Leigh, 2016 |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 9 | # Revised by Andreas Franek, 2016 |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 10 | # Revised by Sam Serrels, 2017 |
| 11 | # Revised by Vadim Barkov, 2017 |
| 12 | # Revised by Vicky Pfau, 2018 |
| 13 | # Revised by Cameron Cawley, 2018 |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 14 | # Revised by Kyle Bentley, 2018 |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 15 | # Revised by David Callu, 2020 |
| 16 | # Revised by Steve Robinson, 2020 |
| 17 | # Revised by Simon Hausmann, 2020 |
| 18 | # Revised by Alex Gaynor, 2020 |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 19 | |
| 20 | # This code is released under the libpng license. |
| 21 | # For conditions of distribution and use, see the disclaimer |
| 22 | # and license in png.h |
| 23 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 24 | cmake_minimum_required(VERSION 3.1) |
| 25 | cmake_policy(VERSION 3.1) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 26 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 27 | project(libpng C ASM) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 28 | enable_testing() |
| 29 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 30 | set(PNGLIB_MAJOR 1) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 31 | set(PNGLIB_MINOR 6) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 32 | set(PNGLIB_RELEASE 38) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 33 | set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
| 34 | set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) |
| 35 | |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 36 | include(GNUInstallDirs) |
| 37 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 38 | # Allow users to specify location of zlib. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 39 | # Useful if zlib is being built alongside this as a sub-project. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 40 | option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF) |
| 41 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 42 | if(NOT PNG_BUILD_ZLIB) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 43 | find_package(ZLIB REQUIRED) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 44 | include_directories(${ZLIB_INCLUDE_DIRS}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 45 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 46 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 47 | if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 48 | find_library(M_LIBRARY m) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 49 | else() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 50 | # libm is not needed and/or not available. |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 51 | set(M_LIBRARY "") |
| 52 | endif() |
| 53 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 54 | # Public CMake configuration variables. |
Matt Sarett | 9b1fe63 | 2015-11-25 10:21:17 -0500 | [diff] [blame] | 55 | option(PNG_SHARED "Build shared lib" ON) |
| 56 | option(PNG_STATIC "Build static lib" ON) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 57 | option(PNG_EXECUTABLES "Build libpng executables" ON) |
| 58 | option(PNG_TESTS "Build libpng tests" ON) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 59 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 60 | # Many more configuration options could be added here. |
Matt Sarett | 9b1fe63 | 2015-11-25 10:21:17 -0500 | [diff] [blame] | 61 | option(PNG_FRAMEWORK "Build OS X framework" OFF) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 62 | option(PNG_DEBUG "Build with debug output" OFF) |
| 63 | option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 64 | |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 65 | set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names") |
| 66 | set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings") |
| 67 | |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 68 | if(PNG_HARDWARE_OPTIMIZATIONS) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 69 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 70 | # Set definitions and sources for ARM. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 71 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR |
| 72 | CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") |
| 73 | set(PNG_ARM_NEON_POSSIBLE_VALUES check on off) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 74 | set(PNG_ARM_NEON "check" |
| 75 | CACHE STRING "Enable ARM NEON optimizations: check|on|off; check is default") |
| 76 | set_property(CACHE PNG_ARM_NEON |
| 77 | PROPERTY STRINGS ${PNG_ARM_NEON_POSSIBLE_VALUES}) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 78 | list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index) |
| 79 | if(index EQUAL -1) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 80 | message(FATAL_ERROR "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 81 | elseif(NOT ${PNG_ARM_NEON} STREQUAL "off") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 82 | set(libpng_arm_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 83 | arm/arm_init.c |
| 84 | arm/filter_neon.S |
| 85 | arm/filter_neon_intrinsics.c |
| 86 | arm/palette_neon_intrinsics.c) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 87 | if(${PNG_ARM_NEON} STREQUAL "on") |
| 88 | add_definitions(-DPNG_ARM_NEON_OPT=2) |
| 89 | elseif(${PNG_ARM_NEON} STREQUAL "check") |
| 90 | add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED) |
| 91 | endif() |
| 92 | else() |
| 93 | add_definitions(-DPNG_ARM_NEON_OPT=0) |
| 94 | endif() |
| 95 | endif() |
| 96 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 97 | # Set definitions and sources for PowerPC. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 98 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 99 | CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 100 | set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 101 | set(PNG_POWERPC_VSX "on" |
| 102 | CACHE STRING "Enable POWERPC VSX optimizations: on|off; on is default") |
| 103 | set_property(CACHE PNG_POWERPC_VSX |
| 104 | PROPERTY STRINGS ${PNG_POWERPC_VSX_POSSIBLE_VALUES}) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 105 | list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index) |
| 106 | if(index EQUAL -1) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 107 | message(FATAL_ERROR "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 108 | elseif(NOT ${PNG_POWERPC_VSX} STREQUAL "off") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 109 | set(libpng_powerpc_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 110 | powerpc/powerpc_init.c |
| 111 | powerpc/filter_vsx_intrinsics.c) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 112 | if(${PNG_POWERPC_VSX} STREQUAL "on") |
| 113 | add_definitions(-DPNG_POWERPC_VSX_OPT=2) |
| 114 | endif() |
| 115 | else() |
| 116 | add_definitions(-DPNG_POWERPC_VSX_OPT=0) |
| 117 | endif() |
| 118 | endif() |
| 119 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 120 | # Set definitions and sources for Intel. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 121 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 122 | CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 123 | set(PNG_INTEL_SSE_POSSIBLE_VALUES on off) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 124 | set(PNG_INTEL_SSE "on" |
| 125 | CACHE STRING "Enable INTEL_SSE optimizations: on|off; on is default") |
| 126 | set_property(CACHE PNG_INTEL_SSE |
| 127 | PROPERTY STRINGS ${PNG_INTEL_SSE_POSSIBLE_VALUES}) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 128 | list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index) |
| 129 | if(index EQUAL -1) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 130 | message(FATAL_ERROR "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 131 | elseif(NOT ${PNG_INTEL_SSE} STREQUAL "off") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 132 | set(libpng_intel_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 133 | intel/intel_init.c |
| 134 | intel/filter_sse2_intrinsics.c) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 135 | if(${PNG_INTEL_SSE} STREQUAL "on") |
| 136 | add_definitions(-DPNG_INTEL_SSE_OPT=1) |
| 137 | endif() |
| 138 | else() |
| 139 | add_definitions(-DPNG_INTEL_SSE_OPT=0) |
| 140 | endif() |
| 141 | endif() |
| 142 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 143 | # Set definitions and sources for MIPS. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 144 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 145 | CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 146 | set(PNG_MIPS_MSA_POSSIBLE_VALUES on off) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 147 | set(PNG_MIPS_MSA "on" |
| 148 | CACHE STRING "Enable MIPS_MSA optimizations: on|off; on is default") |
| 149 | set_property(CACHE PNG_MIPS_MSA |
| 150 | PROPERTY STRINGS ${PNG_MIPS_MSA_POSSIBLE_VALUES}) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 151 | list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index) |
| 152 | if(index EQUAL -1) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 153 | message(FATAL_ERROR "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 154 | elseif(NOT ${PNG_MIPS_MSA} STREQUAL "off") |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 155 | set(libpng_mips_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 156 | mips/mips_init.c |
| 157 | mips/filter_msa_intrinsics.c) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 158 | if(${PNG_MIPS_MSA} STREQUAL "on") |
| 159 | add_definitions(-DPNG_MIPS_MSA_OPT=2) |
| 160 | endif() |
| 161 | else() |
| 162 | add_definitions(-DPNG_MIPS_MSA_OPT=0) |
| 163 | endif() |
| 164 | endif() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 165 | |
| 166 | else(PNG_HARDWARE_OPTIMIZATIONS) |
| 167 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 168 | # Set definitions and sources for ARM. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 169 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR |
| 170 | CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") |
| 171 | add_definitions(-DPNG_ARM_NEON_OPT=0) |
| 172 | endif() |
| 173 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 174 | # Set definitions and sources for PowerPC. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 175 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR |
| 176 | CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*") |
| 177 | add_definitions(-DPNG_POWERPC_VSX_OPT=0) |
| 178 | endif() |
| 179 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 180 | # Set definitions and sources for Intel. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 181 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR |
| 182 | CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*") |
| 183 | add_definitions(-DPNG_INTEL_SSE_OPT=0) |
| 184 | endif() |
| 185 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 186 | # Set definitions and sources for MIPS. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 187 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR |
| 188 | CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*") |
| 189 | add_definitions(-DPNG_MIPS_MSA_OPT=0) |
| 190 | endif() |
| 191 | |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 192 | endif(PNG_HARDWARE_OPTIMIZATIONS) |
| 193 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 194 | # Set PNG_LIB_NAME. |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 195 | set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
| 196 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 197 | # Distinguish between debug and release builds. |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 198 | set(CMAKE_DEBUG_POSTFIX "d") |
| 199 | |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 200 | include(CheckCSourceCompiles) |
| 201 | option(ld-version-script "Enable linker version script" ON) |
| 202 | if(ld-version-script AND NOT APPLE) |
| 203 | # Check if LD supports linker scripts. |
| 204 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 { |
| 205 | global: sym; |
| 206 | local: *; |
| 207 | }; |
| 208 | |
| 209 | VERS_2 { |
| 210 | global: sym2; |
| 211 | main; |
| 212 | } VERS_1; |
| 213 | ") |
| 214 | set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS}) |
| 215 | set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'") |
| 216 | check_c_source_compiles("void sym(void) {} |
| 217 | void sym2(void) {} |
| 218 | int main(void) {return 0;} |
| 219 | " HAVE_LD_VERSION_SCRIPT) |
| 220 | if(NOT HAVE_LD_VERSION_SCRIPT) |
| 221 | set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map") |
| 222 | check_c_source_compiles("void sym(void) {} |
| 223 | void sym2(void) {} |
| 224 | int main(void) {return 0;} |
| 225 | " HAVE_SOLARIS_LD_VERSION_SCRIPT) |
| 226 | endif() |
| 227 | set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE}) |
| 228 | file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map") |
| 229 | endif() |
| 230 | |
| 231 | # Find symbol prefix. Likely obsolete and unnecessary with recent |
| 232 | # toolchains (it's not done in many other projects). |
| 233 | function(symbol_prefix) |
| 234 | set(SYMBOL_PREFIX) |
| 235 | |
| 236 | execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E" "-" |
| 237 | INPUT_FILE /dev/null |
| 238 | OUTPUT_VARIABLE OUT |
| 239 | RESULT_VARIABLE STATUS) |
| 240 | |
| 241 | if(CPP_FAIL) |
| 242 | message(WARNING "Failed to run the C preprocessor") |
| 243 | endif() |
| 244 | |
| 245 | string(REPLACE "\n" ";" OUT "${OUT}") |
| 246 | foreach(line ${OUT}) |
| 247 | string(REGEX MATCH "^PREFIX=" found_match "${line}") |
| 248 | if(found_match) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 249 | string(REGEX REPLACE "^PREFIX=(.*\)" "\\1" prefix "${line}") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 250 | string(REGEX MATCH "__USER_LABEL_PREFIX__" found_match "${prefix}") |
| 251 | if(found_match) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 252 | string(REGEX REPLACE "(.*)__USER_LABEL_PREFIX__(.*)" "\\1\\2" prefix "${prefix}") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 253 | endif() |
| 254 | set(SYMBOL_PREFIX "${prefix}") |
| 255 | endif() |
| 256 | endforeach() |
| 257 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 258 | message(STATUS "Symbol prefix: ${SYMBOL_PREFIX}") |
| 259 | set(SYMBOL_PREFIX "${SYMBOL_PREFIX}" PARENT_SCOPE) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 260 | endfunction() |
| 261 | |
| 262 | if(UNIX) |
| 263 | symbol_prefix() |
| 264 | endif() |
| 265 | |
| 266 | find_program(AWK NAMES gawk awk) |
| 267 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 268 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 269 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 270 | if(NOT AWK OR ANDROID OR IOS) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 271 | # No awk available to generate sources; use pre-built pnglibconf.h |
| 272 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt |
| 273 | ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h) |
| 274 | add_custom_target(genfiles) # Dummy |
| 275 | else() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 276 | # Generate .chk from .out with awk: |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 277 | # generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]]) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 278 | include(CMakeParseArguments) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 279 | function(generate_chk) |
| 280 | set(options) |
| 281 | set(oneValueArgs INPUT OUTPUT) |
| 282 | set(multiValueArgs DEPENDS) |
| 283 | cmake_parse_arguments(_GC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 284 | if(NOT _GC_INPUT) |
| 285 | message(FATAL_ERROR "generate_chk: Missing INPUT argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 286 | endif() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 287 | if(NOT _GC_OUTPUT) |
| 288 | message(FATAL_ERROR "generate_chk: Missing OUTPUT argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 289 | endif() |
| 290 | |
| 291 | add_custom_command(OUTPUT "${_GC_OUTPUT}" |
| 292 | COMMAND "${CMAKE_COMMAND}" |
| 293 | "-DINPUT=${_GC_INPUT}" |
| 294 | "-DOUTPUT=${_GC_OUTPUT}" |
| 295 | -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake" |
| 296 | DEPENDS "${_GC_INPUT}" ${_GC_DEPENDS} |
| 297 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
| 298 | endfunction() |
| 299 | |
| 300 | # Generate .out from .c with awk |
| 301 | # generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]]) |
| 302 | function(generate_out) |
| 303 | set(options) |
| 304 | set(oneValueArgs INPUT OUTPUT) |
| 305 | set(multiValueArgs DEPENDS) |
| 306 | cmake_parse_arguments(_GO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 307 | if(NOT _GO_INPUT) |
| 308 | message(FATAL_ERROR "generate_out: Missing INPUT argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 309 | endif() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 310 | if(NOT _GO_OUTPUT) |
| 311 | message(FATAL_ERROR "generate_out: Missing OUTPUT argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 312 | endif() |
| 313 | |
| 314 | add_custom_command(OUTPUT "${_GO_OUTPUT}" |
| 315 | COMMAND "${CMAKE_COMMAND}" |
| 316 | "-DINPUT=${_GO_INPUT}" |
| 317 | "-DOUTPUT=${_GO_OUTPUT}" |
| 318 | -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake" |
| 319 | DEPENDS "${_GO_INPUT}" ${_GO_DEPENDS} |
| 320 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
| 321 | endfunction() |
| 322 | |
| 323 | # Generate specific source file with awk |
| 324 | # generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]]) |
| 325 | function(generate_source) |
| 326 | set(options) |
| 327 | set(oneValueArgs OUTPUT) |
| 328 | set(multiValueArgs DEPENDS) |
| 329 | cmake_parse_arguments(_GSO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 330 | if(NOT _GSO_OUTPUT) |
| 331 | message(FATAL_ERROR "generate_source: Missing OUTPUT argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 332 | endif() |
| 333 | |
| 334 | add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}" |
| 335 | COMMAND "${CMAKE_COMMAND}" |
| 336 | "-DOUTPUT=${_GSO_OUTPUT}" |
| 337 | -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake" |
| 338 | DEPENDS ${_GSO_DEPENDS} |
| 339 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
| 340 | endfunction() |
| 341 | |
| 342 | # Copy file |
| 343 | function(generate_copy source destination) |
| 344 | add_custom_command(OUTPUT "${destination}" |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 345 | COMMAND "${CMAKE_COMMAND}" |
| 346 | -E remove "${destination}" |
| 347 | COMMAND "${CMAKE_COMMAND}" |
| 348 | -E copy "${source}" "${destination}" |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 349 | DEPENDS "${source}") |
| 350 | endfunction() |
| 351 | |
| 352 | # Generate scripts/pnglibconf.h |
| 353 | generate_source(OUTPUT "scripts/pnglibconf.c" |
| 354 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa" |
| 355 | "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk" |
| 356 | "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h") |
| 357 | |
| 358 | # Generate pnglibconf.c |
| 359 | generate_source(OUTPUT "pnglibconf.c" |
| 360 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa" |
| 361 | "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk" |
| 362 | "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h") |
| 363 | |
| 364 | if(PNG_PREFIX) |
| 365 | set(PNGLIBCONF_H_EXTRA_DEPENDS |
| 366 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" |
| 367 | "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst") |
| 368 | set(PNGPREFIX_H_EXTRA_DEPENDS |
| 369 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out") |
| 370 | endif() |
| 371 | |
| 372 | generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" |
| 373 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out") |
| 374 | |
| 375 | # Generate pnglibconf.h |
| 376 | generate_source(OUTPUT "pnglibconf.h" |
| 377 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" |
| 378 | ${PNGLIBCONF_H_EXTRA_DEPENDS}) |
| 379 | |
| 380 | generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c" |
| 381 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" |
| 382 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") |
| 383 | |
| 384 | generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c" |
| 385 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" |
| 386 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" |
| 387 | "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" |
| 388 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out") |
| 389 | |
| 390 | # Generate pngprefix.h |
| 391 | generate_source(OUTPUT "pngprefix.h" |
| 392 | DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS}) |
| 393 | |
| 394 | generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c" |
| 395 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" |
| 396 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") |
| 397 | |
| 398 | generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c" |
| 399 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" |
| 400 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" |
| 401 | "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" |
| 402 | "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt") |
| 403 | |
| 404 | generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c" |
| 405 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" |
| 406 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" |
| 407 | "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" |
| 408 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") |
| 409 | |
| 410 | generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" |
| 411 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" |
| 412 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk" |
| 413 | "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def") |
| 414 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 415 | add_custom_target(symbol-check |
| 416 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 417 | |
| 418 | generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" |
| 419 | "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym") |
| 420 | generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" |
| 421 | "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers") |
| 422 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 423 | add_custom_target(genvers |
| 424 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers") |
| 425 | add_custom_target(gensym |
| 426 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 427 | |
| 428 | add_custom_target("genprebuilt" |
| 429 | COMMAND "${CMAKE_COMMAND}" |
| 430 | "-DOUTPUT=scripts/pnglibconf.h.prebuilt" |
| 431 | -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake" |
| 432 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
| 433 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 434 | # A single target handles generation of all generated files. |
| 435 | # If they are depended upon separately by multiple targets, this |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 436 | # confuses parallel make (it would require a separate top-level |
| 437 | # target for each file to track the dependencies properly). |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 438 | add_custom_target(genfiles |
| 439 | DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym" |
| 440 | "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers" |
| 441 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" |
| 442 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" |
| 443 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" |
| 444 | "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h" |
| 445 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" |
| 446 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c" |
| 447 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" |
| 448 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" |
| 449 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" |
| 450 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" |
| 451 | "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out") |
| 452 | endif(NOT AWK OR ANDROID OR IOS) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 453 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 454 | # List the source code files. |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 455 | set(libpng_public_hdrs |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 456 | png.h |
| 457 | pngconf.h |
| 458 | "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 459 | ) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 460 | set(libpng_private_hdrs |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 461 | pngpriv.h |
| 462 | pngdebug.h |
| 463 | pnginfo.h |
| 464 | pngstruct.h |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 465 | ) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 466 | if(AWK AND NOT ANDROID AND NOT IOS) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 467 | list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h") |
| 468 | endif() |
| 469 | set(libpng_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 470 | ${libpng_public_hdrs} |
| 471 | ${libpng_private_hdrs} |
| 472 | png.c |
| 473 | pngerror.c |
| 474 | pngget.c |
| 475 | pngmem.c |
| 476 | pngpread.c |
| 477 | pngread.c |
| 478 | pngrio.c |
| 479 | pngrtran.c |
| 480 | pngrutil.c |
| 481 | pngset.c |
| 482 | pngtrans.c |
| 483 | pngwio.c |
| 484 | pngwrite.c |
| 485 | pngwtran.c |
| 486 | pngwutil.c |
| 487 | ${libpng_arm_sources} |
| 488 | ${libpng_intel_sources} |
| 489 | ${libpng_mips_sources} |
| 490 | ${libpng_powerpc_sources} |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 491 | ) |
| 492 | set(pngtest_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 493 | pngtest.c |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 494 | ) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 495 | set(pngvalid_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 496 | contrib/libtests/pngvalid.c |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 497 | ) |
| 498 | set(pngstest_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 499 | contrib/libtests/pngstest.c |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 500 | ) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 501 | set(pngunknown_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 502 | contrib/libtests/pngunknown.c |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 503 | ) |
| 504 | set(pngimage_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 505 | contrib/libtests/pngimage.c |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 506 | ) |
| 507 | set(pngfix_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 508 | contrib/tools/pngfix.c |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 509 | ) |
| 510 | set(png_fix_itxt_sources |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 511 | contrib/tools/png-fix-itxt.c |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 512 | ) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 513 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 514 | if(MSVC) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 515 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 516 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 517 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 518 | if(PNG_DEBUG) |
| 519 | add_definitions(-DPNG_DEBUG) |
| 520 | endif() |
| 521 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 522 | # Now build our target. |
| 523 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIRS}) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 524 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 525 | unset(PNG_LIB_TARGETS) |
| 526 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 527 | if(PNG_SHARED) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 528 | add_library(png SHARED ${libpng_sources}) |
| 529 | set(PNG_LIB_TARGETS png) |
| 530 | set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME}) |
| 531 | add_dependencies(png genfiles) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 532 | if(MSVC) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 533 | # MVC does not append 'lib'. Do it here, to have consistent name. |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 534 | set_target_properties(png PROPERTIES PREFIX "lib") |
| 535 | set_target_properties(png PROPERTIES IMPORT_PREFIX "lib") |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 536 | endif() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 537 | target_link_libraries(png ${ZLIB_LIBRARIES} ${M_LIBRARY}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 538 | |
| 539 | if(UNIX AND AWK) |
| 540 | if(HAVE_LD_VERSION_SCRIPT) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 541 | set_target_properties(png PROPERTIES |
| 542 | LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 543 | elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 544 | set_target_properties(png PROPERTIES |
| 545 | LINK_FLAGS "-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 546 | endif() |
| 547 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 548 | endif() |
| 549 | |
| 550 | if(PNG_STATIC) |
Matt Sarett | 9b1fe63 | 2015-11-25 10:21:17 -0500 | [diff] [blame] | 551 | # does not work without changing name |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 552 | set(PNG_LIB_NAME_STATIC png_static) |
| 553 | add_library(png_static STATIC ${libpng_sources}) |
| 554 | add_dependencies(png_static genfiles) |
| 555 | # MSVC doesn't use a different file extension for shared vs. static |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 556 | # libs. We are able to change OUTPUT_NAME to remove the _static |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 557 | # for all other platforms. |
| 558 | if(NOT MSVC) |
| 559 | set_target_properties(png_static PROPERTIES |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 560 | OUTPUT_NAME "${PNG_LIB_NAME}" |
| 561 | CLEAN_DIRECT_OUTPUT 1) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 562 | else() |
| 563 | set_target_properties(png_static PROPERTIES |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 564 | OUTPUT_NAME "${PNG_LIB_NAME}_static" |
| 565 | CLEAN_DIRECT_OUTPUT 1) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 566 | endif() |
| 567 | list(APPEND PNG_LIB_TARGETS png_static) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 568 | if(MSVC) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 569 | # MSVC does not append 'lib'. Do it here, to have consistent name. |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 570 | set_target_properties(png_static PROPERTIES PREFIX "lib") |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 571 | endif() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 572 | target_link_libraries(png_static ${ZLIB_LIBRARIES} ${M_LIBRARY}) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 573 | endif() |
| 574 | |
Matt Sarett | 9b1fe63 | 2015-11-25 10:21:17 -0500 | [diff] [blame] | 575 | if(PNG_FRAMEWORK) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 576 | set(PNG_LIB_NAME_FRAMEWORK png_framework) |
| 577 | add_library(png_framework SHARED ${libpng_sources}) |
| 578 | add_dependencies(png_framework genfiles) |
| 579 | list(APPEND PNG_LIB_TARGETS png_framework) |
| 580 | set_target_properties(png_framework PROPERTIES |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 581 | FRAMEWORK TRUE |
| 582 | FRAMEWORK_VERSION ${PNGLIB_VERSION} |
| 583 | MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR} |
| 584 | MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION} |
| 585 | MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng |
| 586 | XCODE_ATTRIBUTE_INSTALL_PATH "@rpath" |
| 587 | PUBLIC_HEADER "${libpng_public_hdrs}" |
| 588 | OUTPUT_NAME png) |
| 589 | target_link_libraries(png_framework ${ZLIB_LIBRARIES} ${M_LIBRARY}) |
Matt Sarett | 9b1fe63 | 2015-11-25 10:21:17 -0500 | [diff] [blame] | 590 | endif() |
| 591 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 592 | if(NOT PNG_LIB_TARGETS) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 593 | message(SEND_ERROR "No library variant selected to build. " |
| 594 | "Please enable at least one of the following options: " |
| 595 | "PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK") |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 596 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 597 | |
| 598 | if(PNG_SHARED AND WIN32) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 599 | set_target_properties(png PROPERTIES |
| 600 | DEFINE_SYMBOL PNG_BUILD_DLL) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 601 | endif() |
| 602 | |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 603 | function(png_add_test) |
| 604 | set(options) |
| 605 | set(oneValueArgs NAME COMMAND) |
| 606 | set(multiValueArgs OPTIONS FILES) |
| 607 | cmake_parse_arguments(_PAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 608 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 609 | if(NOT _PAT_NAME) |
| 610 | message(FATAL_ERROR "png_add_test: Missing NAME argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 611 | endif() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 612 | if(NOT _PAT_COMMAND) |
| 613 | message(FATAL_ERROR "png_add_test: Missing COMMAND argument") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 614 | endif() |
| 615 | |
| 616 | set(TEST_OPTIONS "${_PAT_OPTIONS}") |
| 617 | set(TEST_FILES "${_PAT_FILES}") |
| 618 | |
| 619 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scripts/test.cmake.in" |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 620 | "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake" |
| 621 | @ONLY) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 622 | add_test(NAME "${_PAT_NAME}" |
| 623 | COMMAND "${CMAKE_COMMAND}" |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 624 | "-DLIBPNG=$<TARGET_FILE:png>" |
| 625 | "-DTEST_COMMAND=$<TARGET_FILE:${_PAT_COMMAND}>" |
| 626 | -P "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 627 | endfunction() |
| 628 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 629 | if(PNG_TESTS AND PNG_SHARED) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 630 | # Find test PNG files by globbing, but sort lists to ensure |
| 631 | # consistency between different filesystems. |
| 632 | file(GLOB PNGSUITE_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png") |
| 633 | list(SORT PNGSUITE_PNGS) |
| 634 | file(GLOB TEST_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png") |
| 635 | list(SORT TEST_PNGS) |
| 636 | |
| 637 | set(PNGTEST_PNG "${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png") |
| 638 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 639 | add_executable(pngtest ${pngtest_sources}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 640 | target_link_libraries(pngtest png) |
| 641 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 642 | png_add_test(NAME pngtest |
| 643 | COMMAND pngtest |
| 644 | FILES "${PNGTEST_PNG}") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 645 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 646 | add_executable(pngvalid ${pngvalid_sources}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 647 | target_link_libraries(pngvalid png) |
| 648 | |
| 649 | png_add_test(NAME pngvalid-gamma-16-to-8 |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 650 | COMMAND pngvalid |
| 651 | OPTIONS --gamma-16-to-8) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 652 | png_add_test(NAME pngvalid-gamma-alpha-mode |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 653 | COMMAND pngvalid |
| 654 | OPTIONS --gamma-alpha-mode) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 655 | png_add_test(NAME pngvalid-gamma-background |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 656 | COMMAND pngvalid |
| 657 | OPTIONS --gamma-background) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 658 | png_add_test(NAME pngvalid-gamma-expand16-alpha-mode |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 659 | COMMAND pngvalid |
| 660 | OPTIONS --gamma-alpha-mode --expand16) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 661 | png_add_test(NAME pngvalid-gamma-expand16-background |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 662 | COMMAND pngvalid |
| 663 | OPTIONS --gamma-background --expand16) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 664 | png_add_test(NAME pngvalid-gamma-expand16-transform |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 665 | COMMAND pngvalid |
| 666 | OPTIONS --gamma-transform --expand16) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 667 | png_add_test(NAME pngvalid-gamma-sbit |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 668 | COMMAND pngvalid |
| 669 | OPTIONS --gamma-sbit) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 670 | png_add_test(NAME pngvalid-gamma-threshold |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 671 | COMMAND pngvalid |
| 672 | OPTIONS --gamma-threshold) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 673 | png_add_test(NAME pngvalid-gamma-transform |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 674 | COMMAND pngvalid |
| 675 | OPTIONS --gamma-transform) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 676 | png_add_test(NAME pngvalid-progressive-interlace-standard |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 677 | COMMAND pngvalid |
| 678 | OPTIONS --standard --progressive-read --interlace) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 679 | png_add_test(NAME pngvalid-progressive-size |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 680 | COMMAND pngvalid |
| 681 | OPTIONS --size --progressive-read) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 682 | png_add_test(NAME pngvalid-progressive-standard |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 683 | COMMAND pngvalid |
| 684 | OPTIONS --standard --progressive-read) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 685 | png_add_test(NAME pngvalid-standard |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 686 | COMMAND pngvalid |
| 687 | OPTIONS --standard) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 688 | png_add_test(NAME pngvalid-transform |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 689 | COMMAND pngvalid |
| 690 | OPTIONS --transform) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 691 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 692 | add_executable(pngstest ${pngstest_sources}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 693 | target_link_libraries(pngstest png) |
| 694 | |
| 695 | foreach(gamma_type 1.8 linear none sRGB) |
| 696 | foreach(alpha_type none alpha) |
| 697 | set(PNGSTEST_FILES) |
| 698 | foreach(test_png ${TEST_PNGS}) |
| 699 | string(REGEX MATCH ".*-linear[-.].*" TEST_PNG_LINEAR "${test_png}") |
| 700 | string(REGEX MATCH ".*-sRGB[-.].*" TEST_PNG_SRGB "${test_png}") |
| 701 | string(REGEX MATCH ".*-1.8[-.].*" TEST_PNG_G18 "${test_png}") |
| 702 | string(REGEX MATCH ".*-alpha-.*" TEST_PNG_ALPHA "${test_png}") |
| 703 | |
| 704 | set(TEST_PNG_VALID TRUE) |
| 705 | |
| 706 | if(TEST_PNG_ALPHA) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 707 | if(NOT "${alpha_type}" STREQUAL "alpha") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 708 | set(TEST_PNG_VALID FALSE) |
| 709 | endif() |
| 710 | else() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 711 | if("${alpha_type}" STREQUAL "alpha") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 712 | set(TEST_PNG_VALID FALSE) |
| 713 | endif() |
| 714 | endif() |
| 715 | |
| 716 | if(TEST_PNG_LINEAR) |
| 717 | if(NOT "${gamma_type}" STREQUAL "linear") |
| 718 | set(TEST_PNG_VALID FALSE) |
| 719 | endif() |
| 720 | elseif(TEST_PNG_SRGB) |
| 721 | if(NOT "${gamma_type}" STREQUAL "sRGB") |
| 722 | set(TEST_PNG_VALID FALSE) |
| 723 | endif() |
| 724 | elseif(TEST_PNG_G18) |
| 725 | if(NOT "${gamma_type}" STREQUAL "1.8") |
| 726 | set(TEST_PNG_VALID FALSE) |
| 727 | endif() |
| 728 | else() |
| 729 | if(NOT "${gamma_type}" STREQUAL "none") |
| 730 | set(TEST_PNG_VALID FALSE) |
| 731 | endif() |
| 732 | endif() |
| 733 | |
| 734 | if(TEST_PNG_VALID) |
| 735 | list(APPEND PNGSTEST_FILES "${test_png}") |
| 736 | endif() |
| 737 | endforeach() |
| 738 | # Should already be sorted, but sort anyway to be certain. |
| 739 | list(SORT PNGSTEST_FILES) |
| 740 | png_add_test(NAME pngstest-${gamma_type}-${alpha_type} |
| 741 | COMMAND pngstest |
| 742 | OPTIONS --tmpfile "${gamma_type}-${alpha_type}-" --log |
| 743 | FILES ${PNGSTEST_FILES}) |
| 744 | endforeach() |
| 745 | endforeach() |
| 746 | |
| 747 | add_executable(pngunknown ${pngunknown_sources}) |
| 748 | target_link_libraries(pngunknown png) |
| 749 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 750 | png_add_test(NAME pngunknown-discard |
| 751 | COMMAND pngunknown |
| 752 | OPTIONS --strict default=discard |
| 753 | FILES "${PNGTEST_PNG}") |
| 754 | png_add_test(NAME pngunknown-IDAT |
| 755 | COMMAND pngunknown |
| 756 | OPTIONS --strict default=discard IDAT=save |
| 757 | FILES "${PNGTEST_PNG}") |
| 758 | png_add_test(NAME pngunknown-if-safe |
| 759 | COMMAND pngunknown |
| 760 | OPTIONS --strict default=if-safe |
| 761 | FILES "${PNGTEST_PNG}") |
| 762 | png_add_test(NAME pngunknown-sAPI |
| 763 | COMMAND pngunknown |
| 764 | OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save |
| 765 | FILES "${PNGTEST_PNG}") |
| 766 | png_add_test(NAME pngunknown-save |
| 767 | COMMAND pngunknown |
| 768 | OPTIONS --strict default=save |
| 769 | FILES "${PNGTEST_PNG}") |
| 770 | png_add_test(NAME pngunknown-sTER |
| 771 | COMMAND pngunknown |
| 772 | OPTIONS --strict sTER=if-safe |
| 773 | FILES "${PNGTEST_PNG}") |
| 774 | png_add_test(NAME pngunknown-vpAg |
| 775 | COMMAND pngunknown |
| 776 | OPTIONS --strict vpAg=if-safe |
| 777 | FILES "${PNGTEST_PNG}") |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 778 | |
| 779 | add_executable(pngimage ${pngimage_sources}) |
| 780 | target_link_libraries(pngimage png) |
| 781 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 782 | png_add_test(NAME pngimage-quick |
| 783 | COMMAND pngimage |
| 784 | OPTIONS --list-combos --log |
| 785 | FILES ${PNGSUITE_PNGS}) |
| 786 | png_add_test(NAME pngimage-full |
| 787 | COMMAND pngimage |
| 788 | OPTIONS --exhaustive --list-combos --log |
| 789 | FILES ${PNGSUITE_PNGS}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 790 | endif() |
| 791 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 792 | if(PNG_SHARED AND PNG_EXECUTABLES) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 793 | add_executable(pngfix ${pngfix_sources}) |
| 794 | target_link_libraries(pngfix png) |
| 795 | set(PNG_BIN_TARGETS pngfix) |
| 796 | |
| 797 | add_executable(png-fix-itxt ${png_fix_itxt_sources}) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 798 | target_link_libraries(png-fix-itxt ${ZLIB_LIBRARIES} ${M_LIBRARY}) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 799 | list(APPEND PNG_BIN_TARGETS png-fix-itxt) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 800 | endif() |
| 801 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 802 | # Creates a symlink from src to dest (if possible), or, alternatively, |
| 803 | # copies src to dest if different. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 804 | include(CMakeParseArguments) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 805 | function(create_symlink DEST_FILE) |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 806 | cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN}) |
| 807 | |
| 808 | if(NOT S_TARGET AND NOT S_FILE) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 809 | message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument") |
| 810 | endif() |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 811 | |
| 812 | if(S_TARGET AND S_FILE) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 813 | message(FATAL_ERROR "create_symlink: " |
| 814 | "Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; " |
| 815 | "can only have one") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 816 | endif() |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 817 | |
| 818 | if(S_FILE) |
| 819 | # If we don't need to symlink something that's coming from a build target, |
| 820 | # we can go ahead and symlink/copy at configure time. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 821 | if(CMAKE_HOST_WIN32 AND NOT CYGWIN) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 822 | execute_process(COMMAND "${CMAKE_COMMAND}" |
| 823 | -E copy_if_different |
| 824 | ${S_FILE} ${DEST_FILE} |
| 825 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 826 | else() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 827 | execute_process(COMMAND "${CMAKE_COMMAND}" |
| 828 | -E create_symlink |
| 829 | ${S_FILE} ${DEST_FILE} |
| 830 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 831 | endif() |
| 832 | endif() |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 833 | |
| 834 | if(S_TARGET) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 835 | # We need to use generator expressions, which can be a bit tricky. |
| 836 | # For simplicity, make the symlink a POST_BUILD step, and use the TARGET |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 837 | # signature of add_custom_command. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 838 | if(CMAKE_HOST_WIN32 AND NOT CYGWIN) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 839 | add_custom_command(TARGET ${S_TARGET} |
| 840 | POST_BUILD |
| 841 | COMMAND "${CMAKE_COMMAND}" |
| 842 | -E copy_if_different |
| 843 | $<TARGET_LINKER_FILE_NAME:${S_TARGET}> |
| 844 | $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 845 | else() |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 846 | add_custom_command(TARGET ${S_TARGET} |
| 847 | POST_BUILD |
| 848 | COMMAND "${CMAKE_COMMAND}" |
| 849 | -E create_symlink |
| 850 | $<TARGET_LINKER_FILE_NAME:${S_TARGET}> |
| 851 | $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 852 | endif() |
| 853 | endif() |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 854 | endfunction() |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 855 | |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 856 | # Create source generation scripts. |
| 857 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 858 | ${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake |
| 859 | @ONLY) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 860 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 861 | ${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake |
| 862 | @ONLY) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 863 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 864 | ${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake |
| 865 | @ONLY) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 866 | |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 867 | # libpng is a library so default to 'lib' |
| 868 | if(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
| 869 | set(CMAKE_INSTALL_LIBDIR lib) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 870 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 871 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 872 | # Create pkgconfig files. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 873 | # We use the same files like ./configure, so we have to set its vars. |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 874 | # Only do this on Windows for Cygwin - the files don't make much sense |
| 875 | # outside of a UNIX look-alike. |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 876 | if(NOT WIN32 OR CYGWIN OR MINGW) |
| 877 | set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 878 | set(exec_prefix ${CMAKE_INSTALL_PREFIX}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 879 | set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 880 | set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 881 | set(LIBS "-lz -lm") |
| 882 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 883 | ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc |
| 884 | @ONLY) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 885 | create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 886 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 887 | ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config |
| 888 | @ONLY) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 889 | create_symlink(libpng-config FILE ${PNGLIB_NAME}-config) |
| 890 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 891 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 892 | # Set up links. |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 893 | if(PNG_SHARED) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 894 | set_target_properties(png PROPERTIES |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 895 | VERSION 16.${PNGLIB_RELEASE}.git |
| 896 | # VERSION 16.${PNGLIB_RELEASE}.0 |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 897 | SOVERSION 16 |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 898 | CLEAN_DIRECT_OUTPUT 1) |
| 899 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 900 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 901 | # Install. |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 902 | if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 903 | install(TARGETS ${PNG_LIB_TARGETS} |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 904 | EXPORT libpng |
| 905 | RUNTIME DESTINATION bin |
| 906 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 907 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 908 | FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 909 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 910 | if(PNG_SHARED) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 911 | # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin |
| 912 | if(CYGWIN OR MINGW) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 913 | create_symlink(libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET png) |
| 914 | install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} |
| 915 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 916 | endif() |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 917 | |
| 918 | if(NOT WIN32) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 919 | create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png) |
| 920 | install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} |
| 921 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 922 | endif() |
| 923 | endif() |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 924 | |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 925 | if(PNG_STATIC) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 926 | if(NOT WIN32 OR CYGWIN OR MINGW) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 927 | create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static) |
| 928 | install(FILES $<TARGET_LINKER_FILE_DIR:png_static>/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 929 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 930 | endif() |
| 931 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 932 | endif() |
| 933 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 934 | if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 935 | install(FILES ${libpng_public_hdrs} |
| 936 | DESTINATION include) |
| 937 | install(FILES ${libpng_public_hdrs} |
| 938 | DESTINATION include/${PNGLIB_NAME}) |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 939 | endif() |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 940 | if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 941 | if(NOT WIN32 OR CYGWIN OR MINGW) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 942 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config |
| 943 | DESTINATION bin) |
| 944 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config |
| 945 | DESTINATION bin) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 946 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 947 | endif() |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 948 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 949 | if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 950 | install(TARGETS ${PNG_BIN_TARGETS} |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 951 | RUNTIME DESTINATION bin) |
Matt Sarett | 1146686 | 2016-02-19 13:41:30 -0500 | [diff] [blame] | 952 | endif() |
| 953 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 954 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 955 | # Install the man pages. |
| 956 | install(FILES libpng.3 libpngpf.3 |
| 957 | DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) |
| 958 | install(FILES png.5 |
| 959 | DESTINATION ${CMAKE_INSTALL_MANDIR}/man5) |
| 960 | # Install the pkg-config files. |
Leon Scroggins III | 3cc83ac | 2017-10-06 11:02:56 -0400 | [diff] [blame] | 961 | if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 962 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc |
| 963 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 964 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 965 | DESTINATION ${CMAKE_INSTALL_BINDIR}) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 966 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc |
| 967 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 968 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 969 | DESTINATION ${CMAKE_INSTALL_BINDIR}) |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 970 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 971 | endif() |
| 972 | |
xNombre | d07bb0d | 2020-03-10 20:17:12 +0100 | [diff] [blame] | 973 | # Create an export file that CMake users can include() to import our targets. |
| 974 | if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL) |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 975 | install(EXPORT libpng |
| 976 | DESTINATION lib/libpng |
| 977 | FILE lib${PNG_LIB_NAME}.cmake) |
Chris Craik | b50c217 | 2013-07-29 15:28:30 -0700 | [diff] [blame] | 978 | endif() |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 979 | |
xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 980 | # TODO: Create MSVC import lib for MinGW-compiled shared lib. |
Patrick Scott | 5f6bd84 | 2010-06-28 16:55:16 -0400 | [diff] [blame] | 981 | # pexports libpng.dll > libpng.def |
| 982 | # lib /def:libpng.def /machine:x86 |