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