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