CMakeLists.txt 33.0 KB
Newer Older
1 2
# CMakeLists.txt

3
# Copyright (C) 2018 Cosmin Truta
C
Cosmin Truta 已提交
4
# Copyright (C) 2007,2009-2018 Glenn Randers-Pehrson
5 6
# Written by Christian Ehrlicher, 2007
# 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 11 12 13 14
# Revised by Sam Serrels, 2017
# Revised by Vadim Barkov, 2017
# Revised by Vicky Pfau, 2018
# Revised by Cameron Cawley, 2018
# Revised by Cosmin Truta, 2018
15
# Revised by Kyle Bentley, 2018
16 17 18 19 20

# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h

21 22
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
23

24
project(libpng C ASM)
25
enable_testing()
26

27
set(PNGLIB_MAJOR 1)
28
set(PNGLIB_MINOR 6)
C
Cosmin Truta 已提交
29
set(PNGLIB_RELEASE 37)
30 31
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
32

33 34
include(GNUInstallDirs)

35
# needed packages
36

C
Cosmin Truta 已提交
37 38
# Allow users to specify location of Zlib.
# Useful if zlib is being built alongside this as a sub-project.
39 40
option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF)

C
Cosmin Truta 已提交
41
if(NOT PNG_BUILD_ZLIB)
42 43
  find_package(ZLIB REQUIRED)
  include_directories(${ZLIB_INCLUDE_DIR})
C
Cosmin Truta 已提交
44
endif()
45

C
Cosmin Truta 已提交
46 47
if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
  find_library(M_LIBRARY m)
48
else()
C
Cosmin Truta 已提交
49
  # libm is not needed and/or not available
50
  set(M_LIBRARY "")
51
endif()
52

53
# COMMAND LINE OPTIONS
54 55 56
option(PNG_SHARED "Build shared lib" ON)
option(PNG_STATIC "Build static lib" ON)
option(PNG_TESTS  "Build libpng tests" ON)
57

58
# Many more configuration options could be added here
59
option(PNG_FRAMEWORK "Build OS X framework" OFF)
60 61
option(PNG_DEBUG "Build with debug output" OFF)
option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
62

63 64 65
set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names")
set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings")

66
if(PNG_HARDWARE_OPTIMIZATIONS)
C
Cosmin Truta 已提交
67

68
# set definitions and sources for arm
69 70
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR
  CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
71 72 73 74 75 76 77 78 79 80
  set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
  set(PNG_ARM_NEON "check" CACHE STRING "Enable ARM NEON optimizations:
     check: (default) use internal checking code;
     off: disable the optimizations;
     on: turn on unconditionally.")
  set_property(CACHE PNG_ARM_NEON PROPERTY STRINGS
     ${PNG_ARM_NEON_POSSIBLE_VALUES})
  list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
  if(index EQUAL -1)
    message(FATAL_ERROR
C
Cosmin Truta 已提交
81
            "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
82
  elseif(NOT ${PNG_ARM_NEON} STREQUAL "off")
83 84 85
    set(libpng_arm_sources
      arm/arm_init.c
      arm/filter_neon.S
86 87
      arm/filter_neon_intrinsics.c
      arm/palette_neon_intrinsics.c)
88

89 90 91 92 93 94 95 96 97 98
    if(${PNG_ARM_NEON} STREQUAL "on")
      add_definitions(-DPNG_ARM_NEON_OPT=2)
    elseif(${PNG_ARM_NEON} STREQUAL "check")
      add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
    endif()
  else()
    add_definitions(-DPNG_ARM_NEON_OPT=0)
  endif()
endif()

99
# set definitions and sources for powerpc
100
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR
C
Cosmin Truta 已提交
101
   CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*")
102 103 104
  set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off)
  set(PNG_POWERPC_VSX "on" CACHE STRING "Enable POWERPC VSX optimizations:
     off: disable the optimizations.")
105 106 107 108 109
  set_property(CACHE PNG_POWERPC_VSX PROPERTY STRINGS
     ${PNG_POWERPC_VSX_POSSIBLE_VALUES})
  list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index)
  if(index EQUAL -1)
    message(FATAL_ERROR
C
Cosmin Truta 已提交
110
            "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]")
111
  elseif(NOT ${PNG_POWERPC_VSX} STREQUAL "off")
112 113 114 115 116 117 118 119 120 121 122
    set(libpng_powerpc_sources
      powerpc/powerpc_init.c
      powerpc/filter_vsx_intrinsics.c)
    if(${PNG_POWERPC_VSX} STREQUAL "on")
      add_definitions(-DPNG_POWERPC_VSX_OPT=2)
    endif()
  else()
    add_definitions(-DPNG_POWERPC_VSX_OPT=0)
  endif()
endif()

123 124
# set definitions and sources for intel
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR
C
Cosmin Truta 已提交
125
   CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*")
126 127 128 129 130 131 132 133
  set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
  set(PNG_INTEL_SSE "on" CACHE STRING "Enable INTEL_SSE optimizations:
     off: disable the optimizations")
  set_property(CACHE PNG_INTEL_SSE PROPERTY STRINGS
     ${PNG_INTEL_SSE_POSSIBLE_VALUES})
  list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index)
  if(index EQUAL -1)
    message(FATAL_ERROR
C
Cosmin Truta 已提交
134
            "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]")
135
  elseif(NOT ${PNG_INTEL_SSE} STREQUAL "off")
136 137 138 139 140 141 142 143 144 145 146 147 148
    set(libpng_intel_sources
      intel/intel_init.c
      intel/filter_sse2_intrinsics.c)
    if(${PNG_INTEL_SSE} STREQUAL "on")
      add_definitions(-DPNG_INTEL_SSE_OPT=1)
    endif()
  else()
    add_definitions(-DPNG_INTEL_SSE_OPT=0)
  endif()
endif()

# set definitions and sources for MIPS
if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR
C
Cosmin Truta 已提交
149
   CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*")
150 151 152 153 154 155 156 157
  set(PNG_MIPS_MSA_POSSIBLE_VALUES on off)
  set(PNG_MIPS_MSA "on" CACHE STRING "Enable MIPS_MSA optimizations:
     off: disable the optimizations")
  set_property(CACHE PNG_MIPS_MSA PROPERTY STRINGS
     ${PNG_MIPS_MSA_POSSIBLE_VALUES})
  list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index)
  if(index EQUAL -1)
    message(FATAL_ERROR
C
Cosmin Truta 已提交
158
            "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]")
159
  elseif(NOT ${PNG_MIPS_MSA} STREQUAL "off")
160
    set(libpng_mips_sources
161 162 163 164 165 166 167 168 169
      mips/mips_init.c
      mips/filter_msa_intrinsics.c)
    if(${PNG_MIPS_MSA} STREQUAL "on")
      add_definitions(-DPNG_MIPS_MSA_OPT=2)
    endif()
  else()
    add_definitions(-DPNG_MIPS_MSA_OPT=0)
  endif()
endif()
C
Cosmin Truta 已提交
170

171
else(PNG_HARDWARE_OPTIMIZATIONS)
C
Cosmin Truta 已提交
172

173 174
# set definitions and sources for arm
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR
C
Cosmin Truta 已提交
175
   CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
176 177 178 179 180
  add_definitions(-DPNG_ARM_NEON_OPT=0)
endif()

# set definitions and sources for powerpc
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR
C
Cosmin Truta 已提交
181
   CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*")
182 183 184 185 186
  add_definitions(-DPNG_POWERPC_VSX_OPT=0)
endif()

# set definitions and sources for intel
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR
C
Cosmin Truta 已提交
187
   CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*")
188 189 190 191 192
  add_definitions(-DPNG_INTEL_SSE_OPT=0)
endif()

# set definitions and sources for MIPS
if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR
C
Cosmin Truta 已提交
193
   CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*")
194 195
  add_definitions(-DPNG_MIPS_MSA_OPT=0)
endif()
C
Cosmin Truta 已提交
196

197
endif(PNG_HARDWARE_OPTIMIZATIONS)
198

199
# SET LIBNAME
200
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
201 202 203 204

# to distinguish between debug and release lib
set(CMAKE_DEBUG_POSTFIX "d")

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
include(CheckCSourceCompiles)
option(ld-version-script "Enable linker version script" ON)
if(ld-version-script AND NOT APPLE)
  # Check if LD supports linker scripts.
  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 {
        global: sym;
        local: *;
};

VERS_2 {
        global: sym2;
                main;
} VERS_1;
")
  set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
  check_c_source_compiles("void sym(void) {}
void sym2(void) {}
int main(void) {return 0;}
" HAVE_LD_VERSION_SCRIPT)
  if(NOT HAVE_LD_VERSION_SCRIPT)
    set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
  check_c_source_compiles("void sym(void) {}
void sym2(void) {}
int main(void) {return 0;}
" HAVE_SOLARIS_LD_VERSION_SCRIPT)
  endif()
  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
  file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
endif()

# Find symbol prefix.  Likely obsolete and unnecessary with recent
# toolchains (it's not done in many other projects).
function(symbol_prefix)
  set(SYMBOL_PREFIX)

  execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E" "-"
                  INPUT_FILE /dev/null
                  OUTPUT_VARIABLE OUT
                  RESULT_VARIABLE STATUS)

  if(CPP_FAIL)
    message(WARNING "Failed to run the C preprocessor")
  endif()

  string(REPLACE "\n" ";" OUT "${OUT}")
  foreach(line ${OUT})
    string(REGEX MATCH "^PREFIX=" found_match "${line}")
    if(found_match)
C
Cosmin Truta 已提交
254
      string(REGEX REPLACE "^PREFIX=(.*\)" "\\1" prefix "${line}")
255 256
      string(REGEX MATCH "__USER_LABEL_PREFIX__" found_match "${prefix}")
      if(found_match)
C
Cosmin Truta 已提交
257
        string(REGEX REPLACE "(.*)__USER_LABEL_PREFIX__(.*)" "\\1\\2" prefix "${prefix}")
258 259 260 261 262
      endif()
      set(SYMBOL_PREFIX "${prefix}")
    endif()
  endforeach()

C
Cosmin Truta 已提交
263 264
  message(STATUS "Symbol prefix: ${SYMBOL_PREFIX}")
  set(SYMBOL_PREFIX "${SYMBOL_PREFIX}" PARENT_SCOPE)
265 266 267 268 269 270 271 272
endfunction()

if(UNIX)
  symbol_prefix()
endif()

find_program(AWK NAMES gawk awk)

273
include_directories(${CMAKE_CURRENT_BINARY_DIR})
274

275
if(NOT AWK OR ANDROID)
276 277 278 279 280 281 282 283 284 285 286 287 288
  # No awk available to generate sources; use pre-built pnglibconf.h
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
                 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
  add_custom_target(genfiles) # Dummy
else()
  include(CMakeParseArguments)
  # Generate .chk from .out with awk
  # generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
  function(generate_chk)
    set(options)
    set(oneValueArgs INPUT OUTPUT)
    set(multiValueArgs DEPENDS)
    cmake_parse_arguments(_GC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
C
Cosmin Truta 已提交
289 290
    if(NOT _GC_INPUT)
      message(FATAL_ERROR "generate_chk: Missing INPUT argument")
291
    endif()
C
Cosmin Truta 已提交
292 293
    if(NOT _GC_OUTPUT)
      message(FATAL_ERROR "generate_chk: Missing OUTPUT argument")
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    endif()

    add_custom_command(OUTPUT "${_GC_OUTPUT}"
                       COMMAND "${CMAKE_COMMAND}"
                               "-DINPUT=${_GC_INPUT}"
                               "-DOUTPUT=${_GC_OUTPUT}"
                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake"
                       DEPENDS "${_GC_INPUT}" ${_GC_DEPENDS}
                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
  endfunction()

  # Generate .out from .c with awk
  # generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
  function(generate_out)
    set(options)
    set(oneValueArgs INPUT OUTPUT)
    set(multiValueArgs DEPENDS)
    cmake_parse_arguments(_GO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
C
Cosmin Truta 已提交
312 313
    if(NOT _GO_INPUT)
      message(FATAL_ERROR "generate_out: Missing INPUT argument")
314
    endif()
C
Cosmin Truta 已提交
315 316
    if(NOT _GO_OUTPUT)
      message(FATAL_ERROR "generate_out: Missing OUTPUT argument")
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
    endif()

    add_custom_command(OUTPUT "${_GO_OUTPUT}"
                       COMMAND "${CMAKE_COMMAND}"
                               "-DINPUT=${_GO_INPUT}"
                               "-DOUTPUT=${_GO_OUTPUT}"
                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake"
                       DEPENDS "${_GO_INPUT}" ${_GO_DEPENDS}
                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
  endfunction()

  # Generate specific source file with awk
  # generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]])
  function(generate_source)
    set(options)
    set(oneValueArgs OUTPUT)
    set(multiValueArgs DEPENDS)
    cmake_parse_arguments(_GSO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
C
Cosmin Truta 已提交
335 336
    if(NOT _GSO_OUTPUT)
      message(FATAL_ERROR "generate_source: Missing OUTPUT argument")
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
    endif()

    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}"
                       COMMAND "${CMAKE_COMMAND}"
                               "-DOUTPUT=${_GSO_OUTPUT}"
                               -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
                       DEPENDS ${_GSO_DEPENDS}
                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
  endfunction()

  # Copy file
  function(generate_copy source destination)
    add_custom_command(OUTPUT "${destination}"
                       COMMAND "${CMAKE_COMMAND}" -E remove "${destination}"
                       COMMAND "${CMAKE_COMMAND}" -E copy "${source}"
                                                          "${destination}"
                       DEPENDS "${source}")
  endfunction()

  # Generate scripts/pnglibconf.h
  generate_source(OUTPUT "scripts/pnglibconf.c"
                  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
                          "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
                          "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")

  # Generate pnglibconf.c
  generate_source(OUTPUT "pnglibconf.c"
                  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
                          "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
                          "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")

  if(PNG_PREFIX)
    set(PNGLIBCONF_H_EXTRA_DEPENDS
        "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
        "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst")
    set(PNGPREFIX_H_EXTRA_DEPENDS
        "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
  endif()

  generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")

  # Generate pnglibconf.h
  generate_source(OUTPUT "pnglibconf.h"
                  DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
                          ${PNGLIBCONF_H_EXTRA_DEPENDS})

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
               DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
                       "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")

  # Generate pngprefix.h
  generate_source(OUTPUT "pngprefix.h"
                  DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS})

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
               DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
                       "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt")

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
                       "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
                       "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")

  generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
               DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk"
                       "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def")

  add_custom_target(symbol-check DEPENDS
                    "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk")

  generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
                "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")
  generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
                "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")

  add_custom_target(genvers DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")
  add_custom_target(gensym DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")

  add_custom_target("genprebuilt"
                    COMMAND "${CMAKE_COMMAND}"
                            "-DOUTPUT=scripts/pnglibconf.h.prebuilt"
                            -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
                    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

  # A single target handles generation of all generated files.  If
L
luz.paz 已提交
437
  # they are depended upon separately by multiple targets, this
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
  # confuses parallel make (it would require a separate top-level
  # target for each file to track the dependencies properly).
  add_custom_target(genfiles DEPENDS
    "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym"
    "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers"
    "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
    "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
    "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
    "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
    "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out")
454
endif(NOT AWK OR ANDROID)
455

456
# OUR SOURCES
457
set(libpng_public_hdrs
458 459
  png.h
  pngconf.h
460
  "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
461
)
462 463 464 465 466 467
set(libpng_private_hdrs
  pngpriv.h
  pngdebug.h
  pnginfo.h
  pngstruct.h
)
468
if(AWK AND NOT ANDROID)
469 470
  list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
endif()
471 472
set(libpng_sources
  ${libpng_public_hdrs}
473
  ${libpng_private_hdrs}
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
  png.c
  pngerror.c
  pngget.c
  pngmem.c
  pngpread.c
  pngread.c
  pngrio.c
  pngrtran.c
  pngrutil.c
  pngset.c
  pngtrans.c
  pngwio.c
  pngwrite.c
  pngwtran.c
  pngwutil.c
489
  ${libpng_arm_sources}
490
  ${libpng_intel_sources}
491 492
  ${libpng_mips_sources}
  ${libpng_powerpc_sources}
493 494
)
set(pngtest_sources
495
  pngtest.c
496
)
497
set(pngvalid_sources
498 499 500 501
  contrib/libtests/pngvalid.c
)
set(pngstest_sources
  contrib/libtests/pngstest.c
502
)
503 504 505 506 507 508 509 510 511 512 513 514
set(pngunknown_sources
  contrib/libtests/pngunknown.c
)
set(pngimage_sources
  contrib/libtests/pngimage.c
)
set(pngfix_sources
  contrib/tools/pngfix.c
)
set(png_fix_itxt_sources
  contrib/tools/png-fix-itxt.c
)
515

516
if(MSVC)
517
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
C
Cosmin Truta 已提交
518
endif()
519

520
if(PNG_DEBUG)
521
  add_definitions(-DPNG_DEBUG)
522
endif()
523 524

# NOW BUILD OUR TARGET
525
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
526

527 528
unset(PNG_LIB_TARGETS)

529
if(PNG_SHARED)
530 531 532 533
  add_library(png SHARED ${libpng_sources})
  set(PNG_LIB_TARGETS png)
  set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME})
  add_dependencies(png genfiles)
534 535
  if(MSVC)
    # msvc does not append 'lib' - do it here to have consistent name
536 537 538 539 540 541 542 543 544 545 546 547 548
    set_target_properties(png PROPERTIES PREFIX "lib")
    set_target_properties(png PROPERTIES IMPORT_PREFIX "lib")
  endif()
  target_link_libraries(png ${ZLIB_LIBRARY} ${M_LIBRARY})

  if(UNIX AND AWK)
    if(HAVE_LD_VERSION_SCRIPT)
      set_target_properties(png PROPERTIES LINK_FLAGS
        "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
    elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)
      set_target_properties(png PROPERTIES LINK_FLAGS
        "-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
    endif()
549
  endif()
550 551
endif()

552
if(PNG_STATIC)
553
  # does not work without changing name
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
  set(PNG_LIB_NAME_STATIC png_static)
  add_library(png_static STATIC ${libpng_sources})
  add_dependencies(png_static genfiles)
  # MSVC doesn't use a different file extension for shared vs. static
  # libs.  We are able to change OUTPUT_NAME to remove the _static
  # for all other platforms.
  if(NOT MSVC)
    set_target_properties(png_static PROPERTIES
      OUTPUT_NAME "${PNG_LIB_NAME}"
      CLEAN_DIRECT_OUTPUT 1)
  else()
    set_target_properties(png_static PROPERTIES
      OUTPUT_NAME "${PNG_LIB_NAME}_static"
      CLEAN_DIRECT_OUTPUT 1)
  endif()
  list(APPEND PNG_LIB_TARGETS png_static)
570 571
  if(MSVC)
    # msvc does not append 'lib' - do it here to have consistent name
572
    set_target_properties(png_static PROPERTIES PREFIX "lib")
573
  endif()
574
  target_link_libraries(png_static ${ZLIB_LIBRARY} ${M_LIBRARY})
575 576
endif()

577
if(PNG_FRAMEWORK)
578 579 580 581 582
  set(PNG_LIB_NAME_FRAMEWORK png_framework)
  add_library(png_framework SHARED ${libpng_sources})
  add_dependencies(png_framework genfiles)
  list(APPEND PNG_LIB_TARGETS png_framework)
  set_target_properties(png_framework PROPERTIES
583 584 585 586 587 588 589 590
    FRAMEWORK TRUE
    FRAMEWORK_VERSION ${PNGLIB_VERSION}
    MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
    MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}
    MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng
    XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
    PUBLIC_HEADER "${libpng_public_hdrs}"
    OUTPUT_NAME png)
591
  target_link_libraries(png_framework ${ZLIB_LIBRARY} ${M_LIBRARY})
592 593
endif()

594 595 596
if(NOT PNG_LIB_TARGETS)
  message(SEND_ERROR
    "No library variant selected to build. "
597
    "Please enable at least one of the following options: "
C
Cosmin Truta 已提交
598
    "PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK")
599 600
endif()

601
if(PNG_SHARED AND WIN32)
602
  set_target_properties(png PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
603
endif()
604

605 606 607 608 609 610
function(png_add_test)
  set(options)
  set(oneValueArgs NAME COMMAND)
  set(multiValueArgs OPTIONS FILES)
  cmake_parse_arguments(_PAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

C
Cosmin Truta 已提交
611 612
  if(NOT _PAT_NAME)
    message(FATAL_ERROR "png_add_test: Missing NAME argument")
613
  endif()
C
Cosmin Truta 已提交
614 615
  if(NOT _PAT_COMMAND)
    message(FATAL_ERROR "png_add_test: Missing COMMAND argument")
616 617 618 619 620 621 622
  endif()

  set(TEST_OPTIONS "${_PAT_OPTIONS}")
  set(TEST_FILES "${_PAT_FILES}")

  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scripts/test.cmake.in"
                 "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake" @ONLY)
623 624 625 626 627
  add_test(NAME "${_PAT_NAME}"
           COMMAND "${CMAKE_COMMAND}"
           "-DLIBPNG=$<TARGET_FILE:png>"
           "-DTEST_COMMAND=$<TARGET_FILE:${_PAT_COMMAND}>"
           -P "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake")
628 629
endfunction()

630
if(PNG_TESTS AND PNG_SHARED)
631 632
  # Find test PNG files by globbing, but sort lists to ensure
  # consistency between different filesystems.
633
  file(GLOB PNGSUITE_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png")
634
  list(SORT PNGSUITE_PNGS)
635
  file(GLOB TEST_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png")
636
  list(SORT TEST_PNGS)
637 638 639

  set(PNGTEST_PNG "${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png")

640
  add_executable(pngtest ${pngtest_sources})
641 642 643 644
  target_link_libraries(pngtest png)

  png_add_test(NAME pngtest COMMAND pngtest FILES "${PNGTEST_PNG}")

645
  add_executable(pngvalid ${pngvalid_sources})
646 647 648 649 650 651 652 653
  target_link_libraries(pngvalid png)

  png_add_test(NAME pngvalid-gamma-16-to-8
               COMMAND pngvalid OPTIONS --gamma-16-to-8)
  png_add_test(NAME pngvalid-gamma-alpha-mode
               COMMAND pngvalid OPTIONS --gamma-alpha-mode)
  png_add_test(NAME pngvalid-gamma-background
               COMMAND pngvalid OPTIONS --gamma-background)
654
  png_add_test(NAME pngvalid-gamma-expand16-alpha-mode
655
               COMMAND pngvalid OPTIONS --gamma-alpha-mode --expand16)
656
  png_add_test(NAME pngvalid-gamma-expand16-background
657
               COMMAND pngvalid OPTIONS --gamma-background --expand16)
658
  png_add_test(NAME pngvalid-gamma-expand16-transform
659 660 661 662 663 664 665
               COMMAND pngvalid OPTIONS --gamma-transform --expand16)
  png_add_test(NAME pngvalid-gamma-sbit
               COMMAND pngvalid OPTIONS --gamma-sbit)
  png_add_test(NAME pngvalid-gamma-threshold
               COMMAND pngvalid OPTIONS --gamma-threshold)
  png_add_test(NAME pngvalid-gamma-transform
               COMMAND pngvalid OPTIONS --gamma-transform)
666
  png_add_test(NAME pngvalid-progressive-interlace-standard
667
               COMMAND pngvalid OPTIONS --standard --progressive-read --interlace)
668
  png_add_test(NAME pngvalid-progressive-size
669
               COMMAND pngvalid OPTIONS --size --progressive-read)
670
  png_add_test(NAME pngvalid-progressive-standard
671 672 673 674 675 676
               COMMAND pngvalid OPTIONS --standard --progressive-read)
  png_add_test(NAME pngvalid-standard
               COMMAND pngvalid OPTIONS --standard)
  png_add_test(NAME pngvalid-transform
               COMMAND pngvalid OPTIONS --transform)

677
  add_executable(pngstest ${pngstest_sources})
678 679 680 681 682 683 684 685 686 687 688 689 690 691
  target_link_libraries(pngstest png)

  foreach(gamma_type 1.8 linear none sRGB)
    foreach(alpha_type none alpha)
      set(PNGSTEST_FILES)
      foreach(test_png ${TEST_PNGS})
        string(REGEX MATCH ".*-linear[-.].*" TEST_PNG_LINEAR "${test_png}")
        string(REGEX MATCH ".*-sRGB[-.].*" TEST_PNG_SRGB "${test_png}")
        string(REGEX MATCH ".*-1.8[-.].*" TEST_PNG_G18 "${test_png}")
        string(REGEX MATCH ".*-alpha-.*" TEST_PNG_ALPHA "${test_png}")

        set(TEST_PNG_VALID TRUE)

        if(TEST_PNG_ALPHA)
C
Cosmin Truta 已提交
692
          if(NOT "${alpha_type}" STREQUAL "alpha")
693 694 695
            set(TEST_PNG_VALID FALSE)
          endif()
        else()
C
Cosmin Truta 已提交
696
          if("${alpha_type}" STREQUAL "alpha")
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
            set(TEST_PNG_VALID FALSE)
          endif()
        endif()

        if(TEST_PNG_LINEAR)
          if(NOT "${gamma_type}" STREQUAL "linear")
            set(TEST_PNG_VALID FALSE)
          endif()
        elseif(TEST_PNG_SRGB)
          if(NOT "${gamma_type}" STREQUAL "sRGB")
            set(TEST_PNG_VALID FALSE)
          endif()
        elseif(TEST_PNG_G18)
          if(NOT "${gamma_type}" STREQUAL "1.8")
            set(TEST_PNG_VALID FALSE)
          endif()
        else()
          if(NOT "${gamma_type}" STREQUAL "none")
            set(TEST_PNG_VALID FALSE)
          endif()
        endif()

        if(TEST_PNG_VALID)
          list(APPEND PNGSTEST_FILES "${test_png}")
        endif()
      endforeach()
723 724
      # Should already be sorted, but sort anyway to be certain.
      list(SORT PNGSTEST_FILES)
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
      png_add_test(NAME pngstest-${gamma_type}-${alpha_type}
                   COMMAND pngstest
                   OPTIONS --tmpfile "${gamma_type}-${alpha_type}-" --log
                   FILES ${PNGSTEST_FILES})
    endforeach()
  endforeach()

  add_executable(pngunknown ${pngunknown_sources})
  target_link_libraries(pngunknown png)

  png_add_test(NAME pngunknown-discard COMMAND pngunknown OPTIONS --strict default=discard FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-IDAT COMMAND pngunknown OPTIONS --strict default=discard IDAT=save FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-if-safe COMMAND pngunknown OPTIONS --strict default=if-safe FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-sAPI COMMAND pngunknown OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-save COMMAND pngunknown OPTIONS --strict default=save FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-sTER COMMAND pngunknown OPTIONS --strict sTER=if-safe FILES "${PNGTEST_PNG}")
  png_add_test(NAME pngunknown-vpAg COMMAND pngunknown OPTIONS --strict vpAg=if-safe FILES "${PNGTEST_PNG}")

  add_executable(pngimage ${pngimage_sources})
  target_link_libraries(pngimage png)

  png_add_test(NAME pngimage-quick COMMAND pngimage OPTIONS --list-combos --log FILES ${PNGSUITE_PNGS})
  png_add_test(NAME pngimage-full COMMAND pngimage OPTIONS --exhaustive --list-combos --log FILES ${PNGSUITE_PNGS})
endif()

if(PNG_SHARED)
  add_executable(pngfix ${pngfix_sources})
  target_link_libraries(pngfix png)
  set(PNG_BIN_TARGETS pngfix)

  add_executable(png-fix-itxt ${png_fix_itxt_sources})
  target_link_libraries(png-fix-itxt ${ZLIB_LIBRARY} ${M_LIBRARY})
  list(APPEND PNG_BIN_TARGETS png-fix-itxt)
758
endif()
759

760 761 762
# Set a variable with CMake code which:
# Creates a symlink from src to dest (if possible) or alternatively
# copies if different.
763 764
include(CMakeParseArguments)

C
Cosmin Truta 已提交
765
function(create_symlink DEST_FILE)
766 767 768 769

  cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})

  if(NOT S_TARGET AND NOT S_FILE)
C
Cosmin Truta 已提交
770 771
    message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
  endif()
772 773

  if(S_TARGET AND S_FILE)
C
Cosmin Truta 已提交
774 775
    message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.")
  endif()
776 777 778 779

  if(S_FILE)
    # If we don't need to symlink something that's coming from a build target,
    # we can go ahead and symlink/copy at configure time.
780
    if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
781
      execute_process(
C
Cosmin Truta 已提交
782 783 784
        COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
    else()
785
      execute_process(
C
Cosmin Truta 已提交
786 787 788 789
        COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
    endif()
  endif()
790 791 792 793 794

  if(S_TARGET)
    # We need to use generator expressions, which can be a bit tricky, so for
    # simplicity make the symlink a POST_BUILD step and use the TARGET
    # signature of add_custom_command.
795
    if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
796
      add_custom_command(TARGET ${S_TARGET} POST_BUILD
C
Cosmin Truta 已提交
797 798
        COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
    else()
799
      add_custom_command(TARGET ${S_TARGET} POST_BUILD
C
Cosmin Truta 已提交
800 801 802
        COMMAND "${CMAKE_COMMAND}" -E create_symlink $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
    endif()
  endif()
803 804

endfunction()
805

806 807 808 809 810 811 812 813
# Create source generation scripts.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in
               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in
               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in
               ${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake @ONLY)

814
# libpng is a library so default to 'lib'
815
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
816
  set(CMAKE_INSTALL_LIBDIR lib)
C
Cosmin Truta 已提交
817
endif()
818 819

# CREATE PKGCONFIG FILES
C
Cosmin Truta 已提交
820
# We use the same files like ./configure, so we have to set its vars.
821
# Only do this on Windows for Cygwin - the files don't make much sense outside
C
Cosmin Truta 已提交
822
# of a UNIX look-alike.
823 824 825
if(NOT WIN32 OR CYGWIN OR MINGW)
  set(prefix      ${CMAKE_INSTALL_PREFIX})
  set(exec_prefix ${CMAKE_INSTALL_PREFIX})
826 827
  set(libdir      ${CMAKE_INSTALL_FULL_LIBDIR})
  set(includedir  ${CMAKE_INSTALL_FULL_INCLUDEDIR})
828 829 830
  set(LIBS        "-lz -lm")
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
C
Cosmin Truta 已提交
831
  create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
832 833 834

  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
C
Cosmin Truta 已提交
835 836
  create_symlink(libpng-config FILE ${PNGLIB_NAME}-config)
endif()
837 838

# SET UP LINKS
839
if(PNG_SHARED)
840
  set_target_properties(png PROPERTIES
C
Cosmin Truta 已提交
841
#   VERSION 16.${PNGLIB_RELEASE}.1.6.37.git
842 843
    VERSION 16.${PNGLIB_RELEASE}.0
    SOVERSION 16
844
    CLEAN_DIRECT_OUTPUT 1)
845 846 847
endif()

# INSTALL
C
Cosmin Truta 已提交
848
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
849
  install(TARGETS ${PNG_LIB_TARGETS}
850 851 852 853 854
          EXPORT libpng
          RUNTIME DESTINATION bin
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
          FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
855

856
  if(PNG_SHARED)
857
    # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
858
    if(CYGWIN OR MINGW)
C
Cosmin Truta 已提交
859
      create_symlink(libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET png)
860 861
      install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
              DESTINATION ${CMAKE_INSTALL_LIBDIR})
C
Cosmin Truta 已提交
862
    endif()
863 864

    if(NOT WIN32)
C
Cosmin Truta 已提交
865
      create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png)
866 867
      install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
              DESTINATION ${CMAKE_INSTALL_LIBDIR})
C
Cosmin Truta 已提交
868 869
    endif()
  endif()
870

871
  if(PNG_STATIC)
872
    if(NOT WIN32 OR CYGWIN OR MINGW)
C
Cosmin Truta 已提交
873
      create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static)
874 875
      install(FILES $<TARGET_LINKER_FILE_DIR:png_static>/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
              DESTINATION ${CMAKE_INSTALL_LIBDIR})
C
Cosmin Truta 已提交
876 877
    endif()
  endif()
878 879
endif()

C
Cosmin Truta 已提交
880 881 882
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
  install(FILES ${libpng_public_hdrs} DESTINATION include)
  install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME})
883
endif()
C
Cosmin Truta 已提交
884
if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL)
885 886
  if(NOT WIN32 OR CYGWIN OR MINGW)
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
C
Cosmin Truta 已提交
887 888
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
  endif()
889
endif()
890

C
Cosmin Truta 已提交
891
if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL)
892
  install(TARGETS ${PNG_BIN_TARGETS}
893
          RUNTIME DESTINATION bin)
894 895
endif()

C
Cosmin Truta 已提交
896
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
897
  # Install man pages
898 899 900
  if(NOT PNG_MAN_DIR)
    set(PNG_MAN_DIR "share/man")
  endif()
C
Cosmin Truta 已提交
901 902
  install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
  install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
903
  # Install pkg-config files
904
  if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
905 906 907 908 909 910 911 912
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
            DESTINATION bin)
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
            DESTINATION bin)
C
Cosmin Truta 已提交
913
  endif()
914
endif()
915

916 917
# Create an export file that CMake users can include() to import our targets.
if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL)
918 919 920
  install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
endif()

921
# what's with libpng-manual.txt and all the extra files?
922

923
# UNINSTALL
924 925
# do we need this?

926
# DIST
927 928 929 930 931
# do we need this?

# to create msvc import lib for mingw compiled shared lib
# pexports libpng.dll > libpng.def
# lib /def:libpng.def /machine:x86