VirtualBox

source: vbox/trunk/src/libs/libpng-1.6.45/CMakeLists.txt@ 107935

Last change on this file since 107935 was 107813, checked in by vboxsync, 3 weeks ago

libpng-1.6.45: Applied and adjusted our libpng changes to 1.6.45. bugref:8515

  • Property svn:eol-style set to native
File size: 41.9 KB
Line 
1# CMakeLists.txt - CMake lists for libpng
2#
3# Copyright (c) 2018-2025 Cosmin Truta
4# Copyright (c) 2007-2018 Glenn Randers-Pehrson
5# Originally written by Christian Ehrlicher, 2007
6#
7# Use, modification and distribution are subject to
8# the same licensing terms and conditions as libpng.
9# Please see the copyright notice in png.h or visit
10# http://libpng.org/pub/png/src/libpng-LICENSE.txt
11#
12# For copyright and licensing purposes, please see
13# the accompanying file scripts/cmake/AUTHORS.md
14#
15# SPDX-License-Identifier: libpng-2.0
16
17cmake_minimum_required(VERSION 3.14)
18
19set(PNGLIB_MAJOR 1)
20set(PNGLIB_MINOR 6)
21set(PNGLIB_REVISION 45)
22set(PNGLIB_SUBREVISION 0)
23#set(PNGLIB_SUBREVISION "git")
24set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_REVISION})
25set(PNGLIB_ABI_VERSION ${PNGLIB_MAJOR}${PNGLIB_MINOR})
26set(PNGLIB_SHARED_VERSION ${PNGLIB_ABI_VERSION}.${PNGLIB_REVISION}.${PNGLIB_SUBREVISION})
27
28project(libpng
29 VERSION ${PNGLIB_VERSION}
30 LANGUAGES C ASM)
31
32include(CheckCSourceCompiles)
33include(GNUInstallDirs)
34
35# Allow the users to specify an application-specific API prefix for libpng
36# vendoring purposes. A standard libpng build should have no such prefix.
37set(PNG_PREFIX ""
38 CACHE STRING "Prefix to prepend to the API function names")
39
40# Allow the users to override the postfix appended to debug library file names.
41# Previously, we used to set CMAKE_DEBUG_POSTFIX globally. That variable should
42# not be cached, however, because doing so would affect all projects processed
43# after libpng, in unexpected and undesirable ways.
44set(PNG_DEBUG_POSTFIX "d"
45 CACHE STRING "Postfix to append to library file names under the Debug configuration")
46
47# Allow the users to import their own extra configuration settings.
48set(DFA_XTRA ""
49 CACHE FILEPATH "File containing extra configuration settings")
50
51# Allow the users to switch on/off various library build types.
52option(PNG_SHARED "Build libpng as a shared library" ON)
53option(PNG_STATIC "Build libpng as a static library" ON)
54if(APPLE)
55 option(PNG_FRAMEWORK "Build libpng as a framework bundle" ON)
56endif()
57
58# Allow the users to switch on/off the auxiliary build and test artifacts.
59# These artifacts are NOT part of libpng proper, and are subject to change
60# at any time.
61option(PNG_TESTS "Build the libpng tests" ON)
62
63# Same as above, but for the third-party tools.
64# Although these tools are targetted at development environments only,
65# the users are allowed to override the option to build by default.
66if(ANDROID OR IOS)
67 option(PNG_TOOLS "Build the libpng tools" OFF)
68else()
69 option(PNG_TOOLS "Build the libpng tools" ON)
70endif()
71
72# Maintain backwards compatibility with the deprecated option PNG_EXECUTABLES.
73option(PNG_EXECUTABLES "[Deprecated; please use PNG_TOOLS]" ON)
74if(NOT PNG_EXECUTABLES)
75 message(DEPRECATION "The option PNG_EXECUTABLES has been deprecated in favour of PNG_TOOLS")
76 if(PNG_TOOLS)
77 message(AUTHOR_WARNING
78 "Setting PNG_TOOLS to ${PNG_EXECUTABLES}, to stay compatible with PNG_EXECUTABLES")
79 set(PNG_TOOLS "${PNG_EXECUTABLES}")
80 endif()
81endif()
82
83# Allow the users to configure various compilation options.
84option(PNG_DEBUG "Enable debug output" OFF)
85option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
86
87# Initialize and show the target architecture variable PNG_TARGET_ARCHITECTURE.
88#
89# NOTE:
90# On macOS, CMake sets CMAKE_SYSTEM_PROCESSOR to either "x86_64" or "arm64",
91# based upon the OS architecture, not the target architecture. As such, we need
92# to check CMAKE_OSX_ARCHITECTURES to identify which hardware-specific flags to
93# enable. Note that this will fail if you attempt to build a universal binary
94# in a single CMake invocation.
95if(APPLE AND CMAKE_OSX_ARCHITECTURES)
96 string(TOLOWER "${CMAKE_OSX_ARCHITECTURES}" PNG_TARGET_ARCHITECTURE)
97else()
98 string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" PNG_TARGET_ARCHITECTURE)
99endif()
100message(STATUS "Building for target architecture: ${PNG_TARGET_ARCHITECTURE}")
101
102# Allow the users to specify a custom location of zlib.
103# With CMake 3.12 and newer, this option is no longer necessary.
104option(PNG_BUILD_ZLIB "[Deprecated; please use ZLIB_ROOT]" OFF)
105if(PNG_BUILD_ZLIB)
106 if("x${ZLIB_ROOT}" STREQUAL "x")
107 message(SEND_ERROR
108 "The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
109 "please use ZLIB_ROOT instead")
110 else()
111 message(SEND_ERROR
112 "The option PNG_BUILD_ZLIB=${PNG_BUILD_ZLIB} is no longer supported; "
113 "using ZLIB_ROOT=\"${ZLIB_ROOT}\"")
114 endif()
115endif()
116
117find_package(ZLIB REQUIRED)
118
119if(UNIX
120 AND NOT (APPLE OR BEOS OR HAIKU)
121 AND NOT EMSCRIPTEN)
122 find_library(M_LIBRARY m)
123 if(M_LIBRARY)
124 set(M_LIBRARY m)
125 else()
126 set(M_LIBRARY "")
127 endif()
128else()
129 # libm is not available or not needed.
130endif()
131
132if(PNG_HARDWARE_OPTIMIZATIONS)
133
134 # Set definitions and sources for ARM.
135 if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm|aarch)")
136 if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm64|aarch64)")
137 set(PNG_ARM_NEON_POSSIBLE_VALUES on off)
138 set(PNG_ARM_NEON "on"
139 CACHE STRING "Enable ARM NEON optimizations: on|off; on is default")
140 else()
141 set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
142 set(PNG_ARM_NEON "off"
143 CACHE STRING "Enable ARM NEON optimizations: check|on|off; off is default")
144 endif()
145 set_property(CACHE PNG_ARM_NEON
146 PROPERTY STRINGS ${PNG_ARM_NEON_POSSIBLE_VALUES})
147 list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
148 if(index EQUAL -1)
149 message(FATAL_ERROR "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
150 elseif(NOT PNG_ARM_NEON STREQUAL "off")
151 set(libpng_arm_sources
152 arm/arm_init.c
153 arm/filter_neon_intrinsics.c
154 arm/palette_neon_intrinsics.c)
155 if(PNG_ARM_NEON STREQUAL "on")
156 add_definitions(-DPNG_ARM_NEON_OPT=2)
157 elseif(PNG_ARM_NEON STREQUAL "check")
158 add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
159 endif()
160 else()
161 add_definitions(-DPNG_ARM_NEON_OPT=0)
162 endif()
163 endif()
164
165 # Set definitions and sources for PowerPC.
166 if(PNG_TARGET_ARCHITECTURE MATCHES "^(powerpc|ppc64)")
167 set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off)
168 set(PNG_POWERPC_VSX "on"
169 CACHE STRING "Enable POWERPC VSX optimizations: on|off; on is default")
170 set_property(CACHE PNG_POWERPC_VSX
171 PROPERTY STRINGS ${PNG_POWERPC_VSX_POSSIBLE_VALUES})
172 list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index)
173 if(index EQUAL -1)
174 message(FATAL_ERROR "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]")
175 elseif(NOT PNG_POWERPC_VSX STREQUAL "off")
176 set(libpng_powerpc_sources
177 powerpc/powerpc_init.c
178 powerpc/filter_vsx_intrinsics.c)
179 if(PNG_POWERPC_VSX STREQUAL "on")
180 add_definitions(-DPNG_POWERPC_VSX_OPT=2)
181 endif()
182 else()
183 add_definitions(-DPNG_POWERPC_VSX_OPT=0)
184 endif()
185 endif()
186
187 # Set definitions and sources for Intel.
188 if(PNG_TARGET_ARCHITECTURE MATCHES "^(i[3-6]86|x86|amd64)")
189 set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
190 set(PNG_INTEL_SSE "on"
191 CACHE STRING "Enable INTEL_SSE optimizations: on|off; on is default")
192 set_property(CACHE PNG_INTEL_SSE
193 PROPERTY STRINGS ${PNG_INTEL_SSE_POSSIBLE_VALUES})
194 list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index)
195 if(index EQUAL -1)
196 message(FATAL_ERROR "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]")
197 elseif(NOT PNG_INTEL_SSE STREQUAL "off")
198 set(libpng_intel_sources
199 intel/intel_init.c
200 intel/filter_sse2_intrinsics.c)
201 if(PNG_INTEL_SSE STREQUAL "on")
202 add_definitions(-DPNG_INTEL_SSE_OPT=1)
203 endif()
204 else()
205 add_definitions(-DPNG_INTEL_SSE_OPT=0)
206 endif()
207 endif()
208
209 # Set definitions and sources for MIPS.
210 if(PNG_TARGET_ARCHITECTURE MATCHES "^(mipsel|mips64el)")
211 set(PNG_MIPS_MSA_POSSIBLE_VALUES on off)
212 set(PNG_MIPS_MSA "on"
213 CACHE STRING "Enable MIPS_MSA optimizations: on|off; on is default")
214 set_property(CACHE PNG_MIPS_MSA
215 PROPERTY STRINGS ${PNG_MIPS_MSA_POSSIBLE_VALUES})
216 list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index_msa)
217 if(index_msa EQUAL -1)
218 message(FATAL_ERROR "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]")
219 endif()
220
221 set(PNG_MIPS_MMI_POSSIBLE_VALUES on off)
222 set(PNG_MIPS_MMI "on"
223 CACHE STRING "Enable MIPS_MMI optimizations: on|off; on is default")
224 set_property(CACHE PNG_MIPS_MMI
225 PROPERTY STRINGS ${PNG_MIPS_MMI_POSSIBLE_VALUES})
226 list(FIND PNG_MIPS_MMI_POSSIBLE_VALUES ${PNG_MIPS_MMI} index_mmi)
227 if(index_mmi EQUAL -1)
228 message(FATAL_ERROR "PNG_MIPS_MMI must be one of [${PNG_MIPS_MMI_POSSIBLE_VALUES}]")
229 endif()
230
231 if(PNG_MIPS_MSA STREQUAL "on" AND PNG_MIPS_MMI STREQUAL "on")
232 set(libpng_mips_sources
233 mips/mips_init.c
234 mips/filter_msa_intrinsics.c
235 mips/filter_mmi_inline_assembly.c)
236 add_definitions(-DPNG_MIPS_MSA_OPT=2)
237 add_definitions(-DPNG_MIPS_MMI_OPT=1)
238 elseif(PNG_MIPS_MSA STREQUAL "on")
239 set(libpng_mips_sources
240 mips/mips_init.c
241 mips/filter_msa_intrinsics.c)
242 add_definitions(-DPNG_MIPS_MSA_OPT=2)
243 add_definitions(-DPNG_MIPS_MMI_OPT=0)
244 elseif(PNG_MIPS_MMI STREQUAL "on")
245 set(libpng_mips_sources
246 mips/mips_init.c
247 mips/filter_mmi_inline_assembly.c)
248 add_definitions(-DPNG_MIPS_MSA_OPT=0)
249 add_definitions(-DPNG_MIPS_MMI_OPT=1)
250 else()
251 add_definitions(-DPNG_MIPS_MSA_OPT=0)
252 add_definitions(-DPNG_MIPS_MMI_OPT=0)
253 endif()
254 endif()
255
256 # Set definitions and sources for LoongArch.
257 if(PNG_TARGET_ARCHITECTURE MATCHES "^(loongarch)")
258 include(CheckCCompilerFlag)
259 set(PNG_LOONGARCH_LSX_POSSIBLE_VALUES on off)
260 set(PNG_LOONGARCH_LSX "on"
261 CACHE STRING "Enable LOONGARCH_LSX optimizations: on|off; on is default")
262 set_property(CACHE PNG_LOONGARCH_LSX
263 PROPERTY STRINGS ${PNG_LOONGARCH_LSX_POSSIBLE_VALUES})
264 list(FIND PNG_LOONGARCH_LSX_POSSIBLE_VALUES ${PNG_LOONGARCH_LSX} index)
265 if(index EQUAL -1)
266 message(FATAL_ERROR "PNG_LOONGARCH_LSX must be one of [${PNG_LOONGARCH_LSX_POSSIBLE_VALUES}]")
267 elseif(NOT PNG_LOONGARCH_LSX STREQUAL "off")
268 CHECK_C_COMPILER_FLAG("-mlsx" COMPILER_SUPPORTS_LSX)
269 if(COMPILER_SUPPORTS_LSX)
270 set(libpng_loongarch_sources
271 loongarch/loongarch_lsx_init.c
272 loongarch/filter_lsx_intrinsics.c)
273 set_source_files_properties(${libpng_loongarch_sources}
274 PROPERTIES
275 COMPILE_FLAGS "-mlsx")
276 add_definitions(-DPNG_LOONGARCH_LSX_OPT=1)
277 else()
278 message(FATAL_ERROR "Compiler does not support -mlsx option")
279 endif()
280 else()
281 add_definitions(-DPNG_LOONGARCH_LSX_OPT=0)
282 endif()
283 endif()
284
285else(PNG_HARDWARE_OPTIMIZATIONS)
286
287 # Set definitions and sources for ARM.
288 if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm|aarch)")
289 add_definitions(-DPNG_ARM_NEON_OPT=0)
290 endif()
291
292 # Set definitions and sources for PowerPC.
293 if(PNG_TARGET_ARCHITECTURE MATCHES "^(powerpc|ppc64)")
294 add_definitions(-DPNG_POWERPC_VSX_OPT=0)
295 endif()
296
297 # Set definitions and sources for Intel.
298 if(PNG_TARGET_ARCHITECTURE MATCHES "^(i[3-6]86|x86|amd64)")
299 add_definitions(-DPNG_INTEL_SSE_OPT=0)
300 endif()
301
302 # Set definitions and sources for MIPS.
303 if(PNG_TARGET_ARCHITECTURE MATCHES "^(mipsel|mips64el)")
304 add_definitions(-DPNG_MIPS_MSA_OPT=0)
305 endif()
306
307 # Set definitions and sources for LoongArch.
308 if(PNG_TARGET_ARCHITECTURE MATCHES "^(loongarch)")
309 add_definitions(-DPNG_LOONGARCH_LSX_OPT=0)
310 endif()
311
312endif(PNG_HARDWARE_OPTIMIZATIONS)
313
314option(ld-version-script "Enable linker version script" ON)
315if(ld-version-script AND NOT (ANDROID OR APPLE))
316 # Check if LD supports linker scripts.
317 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "
318VERS_1 { global: sym1; local: *; };
319VERS_2 { global: sym2; main; } VERS_1;
320")
321 set(_SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
322 if(NOT CMAKE_HOST_SOLARIS)
323 # Avoid using CMAKE_SHARED_LIBRARY_C_FLAGS in version script checks on
324 # Solaris, because of an incompatibility with the Solaris link editor.
325 list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
326 endif()
327 list(APPEND CMAKE_REQUIRED_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
328 check_c_source_compiles("
329void sym1(void) {}
330void sym2(void) {}
331int main(void) { return 0; }
332" HAVE_LD_VERSION_SCRIPT)
333 if(NOT HAVE_LD_VERSION_SCRIPT)
334 set(CMAKE_REQUIRED_FLAGS ${_SAVED_CMAKE_REQUIRED_FLAGS})
335 if(NOT CMAKE_HOST_SOLARIS)
336 # Again, avoid using CMAKE_SHARED_LIBRARY_C_FLAGS in version script
337 # checks on Solaris.
338 list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
339 endif()
340 list(APPEND CMAKE_REQUIRED_FLAGS "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
341 check_c_source_compiles("
342void sym1(void) {}
343void sym2(void) {}
344int main(void) { return 0; }
345" HAVE_SOLARIS_LD_VERSION_SCRIPT)
346 endif()
347 set(CMAKE_REQUIRED_FLAGS ${_SAVED_CMAKE_REQUIRED_FLAGS})
348 file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
349endif()
350
351# Find an AWK language processor.
352# Start with specific AWK implementations like gawk and nawk, which are
353# known to work with our scripts, then fall back to the system awk.
354find_program(AWK NAMES gawk nawk awk)
355if(AWK)
356 message(STATUS "Found AWK program: ${AWK}")
357else()
358 message(STATUS "Could not find an AWK-compatible program")
359endif()
360
361if(NOT AWK OR (ANDROID OR IOS))
362 # No awk available to generate sources; use pre-built pnglibconf.h
363 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
364 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
365 add_custom_target(png_genfiles)
366else()
367 # Include the internal module PNGGenConfig.cmake
368 include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/PNGGenConfig.cmake)
369
370 # Copy the awk scripts, converting their line endings to Unix (LF)
371 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk
372 ${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk
373 @ONLY
374 NEWLINE_STYLE LF)
375 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk
376 ${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk
377 @ONLY
378 NEWLINE_STYLE LF)
379 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/dfn.awk
380 ${CMAKE_CURRENT_BINARY_DIR}/scripts/dfn.awk
381 @ONLY
382 NEWLINE_STYLE LF)
383
384 # Generate scripts/pnglibconf.h
385 generate_source(OUTPUT "scripts/pnglibconf.c"
386 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
387 "${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
388 "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
389 add_custom_target(png_scripts_pnglibconf_c
390 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c")
391
392 # Generate pnglibconf.c
393 generate_source(OUTPUT "pnglibconf.c"
394 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
395 "${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
396 "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
397 add_custom_target(pnglibconf_c
398 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c")
399
400 if(PNG_PREFIX)
401 set(PNGLIBCONF_H_EXTRA_DEPENDS
402 "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
403 "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst")
404 set(PNGPREFIX_H_EXTRA_DEPENDS
405 "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
406 endif()
407
408 generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
409 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
410 DEPENDS pnglibconf_c)
411 add_custom_target(pnglibconf_out
412 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")
413
414 # Generate pnglibconf.h
415 generate_source(OUTPUT "pnglibconf.h"
416 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out
417 ${PNGLIBCONF_H_EXTRA_DEPENDS})
418 add_custom_target(pnglibconf_h
419 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")
420
421 generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c"
422 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
423 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
424 add_custom_target(png_scripts_intprefix_out
425 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
426
427 generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c"
428 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
429 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
430 "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
431 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out)
432 add_custom_target(png_scripts_prefix_out
433 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out")
434
435 # Generate pngprefix.h
436 generate_source(OUTPUT "pngprefix.h"
437 DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS})
438 add_custom_target(pngprefix_h
439 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
440
441 generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c"
442 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
443 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
444 add_custom_target(png_scripts_sym_out
445 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out")
446
447 generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c"
448 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
449 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
450 "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
451 "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt")
452 add_custom_target(png_scripts_symbols_out
453 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out")
454
455 generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c"
456 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
457 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
458 "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
459 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
460 add_custom_target(png_scripts_vers_out
461 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out")
462
463 generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
464 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
465 DEPENDS png_scripts_symbols_out
466 "${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk"
467 "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def")
468
469 add_custom_target(png_scripts_symbols_chk
470 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk")
471
472 generate_copy(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
473 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym"
474 DEPENDS png_scripts_sym_out)
475 generate_copy(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
476 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers"
477 DEPENDS png_scripts_vers_out)
478
479 add_custom_target(png_genvers
480 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")
481 add_custom_target(png_gensym
482 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")
483
484 add_custom_target(png_genprebuilt
485 COMMAND "${CMAKE_COMMAND}"
486 "-DOUTPUT=scripts/pnglibconf.h.prebuilt"
487 -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/cmake/gensrc.cmake"
488 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
489
490 # A single target handles generation of all generated files.
491 add_custom_target(png_genfiles
492 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym" png_gensym
493 "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers" png_genvers
494 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" pnglibconf_c
495 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h
496 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out
497 "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h" pngprefix_h
498 "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" png_scripts_intprefix_out
499 "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c" png_scripts_pnglibconf_c
500 "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" png_scripts_prefix_out
501 "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" png_scripts_sym_out
502 "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" png_scripts_symbols_chk
503 "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" png_scripts_symbols_out
504 "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" png_scripts_vers_out)
505endif(NOT AWK OR (ANDROID OR IOS))
506
507# List the source code files.
508set(libpng_public_hdrs
509 png.h
510 pngconf.h
511 "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
512)
513set(libpng_private_hdrs
514 pngpriv.h
515 pngdebug.h
516 pnginfo.h
517 pngstruct.h
518)
519if(AWK AND NOT (ANDROID OR IOS))
520 list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
521endif()
522set(libpng_sources
523 ${libpng_public_hdrs}
524 ${libpng_private_hdrs}
525 png.c
526 pngerror.c
527 pngget.c
528 pngmem.c
529 pngpread.c
530 pngread.c
531 pngrio.c
532 pngrtran.c
533 pngrutil.c
534 pngset.c
535 pngtrans.c
536 pngwio.c
537 pngwrite.c
538 pngwtran.c
539 pngwutil.c
540 ${libpng_arm_sources}
541 ${libpng_intel_sources}
542 ${libpng_mips_sources}
543 ${libpng_powerpc_sources}
544 ${libpng_loongarch_sources}
545)
546set(pngtest_sources
547 pngtest.c
548)
549set(pngvalid_sources
550 contrib/libtests/pngvalid.c
551)
552set(pngstest_sources
553 contrib/libtests/pngstest.c
554)
555set(pngunknown_sources
556 contrib/libtests/pngunknown.c
557)
558set(pngimage_sources
559 contrib/libtests/pngimage.c
560)
561set(pngfix_sources
562 contrib/tools/pngfix.c
563)
564set(png_fix_itxt_sources
565 contrib/tools/png-fix-itxt.c
566)
567
568if(MSVC OR (WIN32 AND (CMAKE_C_COMPILER_ID MATCHES "Clang")))
569 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
570 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
571endif()
572
573if(PNG_DEBUG)
574 add_definitions(-DPNG_DEBUG)
575endif()
576
577# Now build our targets.
578
579# Initialize the list of libpng library targets.
580set(PNG_LIBRARY_TARGETS "")
581
582# Initialize the libpng library file names.
583if(UNIX
584 OR (WIN32 AND NOT CMAKE_SHARED_LIBRARY_PREFIX STREQUAL "")
585 OR (WIN32 AND NOT CMAKE_STATIC_LIBRARY_PREFIX STREQUAL ""))
586 # We are on a Unix or Unix-like toolchain like the GNU toolchain on Windows.
587 # Library file names are expected to have an implicit prefix such as "lib".
588 # Let CMake prepend and append its usual prefixes and suffixes by default.
589 set(PNG_SHARED_OUTPUT_NAME "png${PNGLIB_ABI_VERSION}")
590 set(PNG_STATIC_OUTPUT_NAME "png${PNGLIB_ABI_VERSION}")
591else()
592 # We are, most likely, on a Windows toolchain like MSVC, Clang on Windows,
593 # Borland/Embarcadero, etc. We need to specify the "libpng" name explicitly.
594 # We also need to use a custom suffix, in order to distinguish between the
595 # shared import library name and the static library name.
596 set(PNG_SHARED_OUTPUT_NAME "libpng${PNGLIB_ABI_VERSION}")
597 set(PNG_STATIC_OUTPUT_NAME "libpng${PNGLIB_ABI_VERSION}_static")
598endif()
599
600if(PNG_SHARED)
601 add_library(png_shared SHARED ${libpng_sources})
602 add_dependencies(png_shared png_genfiles)
603 list(APPEND PNG_LIBRARY_TARGETS png_shared)
604 set_target_properties(png_shared PROPERTIES
605 OUTPUT_NAME "${PNG_SHARED_OUTPUT_NAME}"
606 DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}"
607 VERSION "${PNGLIB_SHARED_VERSION}"
608 SOVERSION "${PNGLIB_ABI_VERSION}")
609 if(UNIX AND AWK)
610 if(HAVE_LD_VERSION_SCRIPT)
611 set_target_properties(png_shared PROPERTIES
612 LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
613 elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)
614 set_target_properties(png_shared PROPERTIES
615 LINK_FLAGS "-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
616 endif()
617 endif()
618 if(APPLE)
619 # Avoid CMake's implicit compile definition "png_shared_EXPORTS".
620 set_target_properties(png_shared PROPERTIES DEFINE_SYMBOL "")
621 elseif(WIN32)
622 # Use the explicit compile definition "PNG_BUILD_DLL" for Windows DLLs.
623 set_target_properties(png_shared PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
624 endif()
625 target_include_directories(png_shared
626 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
627 target_include_directories(png_shared
628 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
629 target_include_directories(png_shared SYSTEM
630 INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>)
631 target_link_libraries(png_shared PUBLIC ZLIB::ZLIB ${M_LIBRARY})
632endif()
633
634if(PNG_STATIC)
635 add_library(png_static STATIC ${libpng_sources})
636 add_dependencies(png_static png_genfiles)
637 list(APPEND PNG_LIBRARY_TARGETS png_static)
638 set_target_properties(png_static PROPERTIES
639 OUTPUT_NAME "${PNG_STATIC_OUTPUT_NAME}"
640 DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}")
641 target_include_directories(png_static
642 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
643 target_include_directories(png_static
644 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
645 target_include_directories(png_static SYSTEM
646 INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>)
647 target_link_libraries(png_static PUBLIC ZLIB::ZLIB ${M_LIBRARY})
648endif()
649
650if(PNG_FRAMEWORK AND NOT APPLE)
651 message(AUTHOR_WARNING
652 "Setting PNG_FRAMEWORK to OFF, as it only applies to Apple systems")
653 set(PNG_FRAMEWORK OFF)
654endif()
655
656if(PNG_FRAMEWORK)
657 add_library(png_framework SHARED ${libpng_sources})
658 add_dependencies(png_framework png_genfiles)
659 list(APPEND PNG_LIBRARY_TARGETS png_framework)
660 set_target_properties(png_framework PROPERTIES
661 FRAMEWORK TRUE
662 FRAMEWORK_VERSION "${PNGLIB_VERSION}"
663 MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${PNGLIB_MAJOR}.${PNGLIB_MINOR}"
664 MACOSX_FRAMEWORK_BUNDLE_VERSION "${PNGLIB_VERSION}"
665 MACOSX_FRAMEWORK_IDENTIFIER "org.libpng.libpng"
666 XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
667 PUBLIC_HEADER "${libpng_public_hdrs}"
668 OUTPUT_NAME "png"
669 DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}")
670 # Avoid CMake's implicit compile definition "-Dpng_framework_EXPORTS".
671 set_target_properties(png_framework PROPERTIES DEFINE_SYMBOL "")
672 target_include_directories(png_framework
673 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
674 target_include_directories(png_framework
675 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
676 target_include_directories(png_framework SYSTEM
677 INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>)
678 target_link_libraries(png_framework PUBLIC ZLIB::ZLIB ${M_LIBRARY})
679endif()
680
681if(NOT PNG_LIBRARY_TARGETS)
682 message(SEND_ERROR "No library variant selected to build. "
683 "Please enable at least one of the following options: "
684 "PNG_SHARED, PNG_STATIC, PNG_FRAMEWORK")
685endif()
686
687if(PNG_TESTS AND PNG_SHARED)
688 enable_testing()
689
690 # Include the internal module PNGTest.cmake
691 include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/PNGTest.cmake)
692
693 # Find test PNG files by globbing, but sort lists to ensure
694 # consistency between different filesystems.
695 file(GLOB PNGSUITE_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png")
696 list(SORT PNGSUITE_PNGS)
697 file(GLOB TEST_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png")
698 list(SORT TEST_PNGS)
699 file(GLOB TEST_PNG3_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/png-3/*.png")
700 list(SORT TEST_PNG3_PNGS)
701
702 set(PNGTEST_PNG "${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png")
703
704 add_executable(pngtest ${pngtest_sources})
705 target_link_libraries(pngtest PRIVATE png_shared)
706
707 png_add_test(NAME pngtest
708 COMMAND pngtest
709 FILES "${PNGTEST_PNG}")
710
711 png_add_test(NAME pngtest-png-3
712 COMMAND pngtest
713 FILES "${TEST_PNG3_PNGS}")
714
715 add_executable(pngvalid ${pngvalid_sources})
716 target_link_libraries(pngvalid PRIVATE png_shared)
717
718 png_add_test(NAME pngvalid-gamma-16-to-8
719 COMMAND pngvalid
720 OPTIONS --gamma-16-to-8)
721 png_add_test(NAME pngvalid-gamma-alpha-mode
722 COMMAND pngvalid
723 OPTIONS --gamma-alpha-mode)
724 png_add_test(NAME pngvalid-gamma-background
725 COMMAND pngvalid
726 OPTIONS --gamma-background)
727 png_add_test(NAME pngvalid-gamma-expand16-alpha-mode
728 COMMAND pngvalid
729 OPTIONS --gamma-alpha-mode --expand16)
730 png_add_test(NAME pngvalid-gamma-expand16-background
731 COMMAND pngvalid
732 OPTIONS --gamma-background --expand16)
733 png_add_test(NAME pngvalid-gamma-expand16-transform
734 COMMAND pngvalid
735 OPTIONS --gamma-transform --expand16)
736 png_add_test(NAME pngvalid-gamma-sbit
737 COMMAND pngvalid
738 OPTIONS --gamma-sbit)
739 png_add_test(NAME pngvalid-gamma-threshold
740 COMMAND pngvalid
741 OPTIONS --gamma-threshold)
742 png_add_test(NAME pngvalid-gamma-transform
743 COMMAND pngvalid
744 OPTIONS --gamma-transform)
745 png_add_test(NAME pngvalid-progressive-interlace-standard
746 COMMAND pngvalid
747 OPTIONS --standard --progressive-read --interlace)
748 png_add_test(NAME pngvalid-progressive-size
749 COMMAND pngvalid
750 OPTIONS --size --progressive-read)
751 png_add_test(NAME pngvalid-progressive-standard
752 COMMAND pngvalid
753 OPTIONS --standard --progressive-read)
754 png_add_test(NAME pngvalid-standard
755 COMMAND pngvalid
756 OPTIONS --standard)
757 png_add_test(NAME pngvalid-transform
758 COMMAND pngvalid
759 OPTIONS --transform)
760
761 add_executable(pngstest ${pngstest_sources})
762 target_link_libraries(pngstest PRIVATE png_shared)
763
764 foreach(gamma_type 1.8 linear none sRGB)
765 foreach(alpha_type none alpha)
766 set(PNGSTEST_FILES)
767 foreach(test_png ${TEST_PNGS})
768 string(REGEX MATCH "-linear[-.]" TEST_PNG_LINEAR "${test_png}")
769 string(REGEX MATCH "-sRGB[-.]" TEST_PNG_SRGB "${test_png}")
770 string(REGEX MATCH "-1.8[-.]" TEST_PNG_G18 "${test_png}")
771 string(REGEX MATCH "-alpha-" TEST_PNG_ALPHA "${test_png}")
772
773 set(TEST_PNG_VALID TRUE)
774
775 if(TEST_PNG_ALPHA)
776 if(NOT alpha_type STREQUAL "alpha")
777 set(TEST_PNG_VALID FALSE)
778 endif()
779 else()
780 if(alpha_type STREQUAL "alpha")
781 set(TEST_PNG_VALID FALSE)
782 endif()
783 endif()
784
785 if(TEST_PNG_LINEAR)
786 if(NOT gamma_type STREQUAL "linear")
787 set(TEST_PNG_VALID FALSE)
788 endif()
789 elseif(TEST_PNG_SRGB)
790 if(NOT gamma_type STREQUAL "sRGB")
791 set(TEST_PNG_VALID FALSE)
792 endif()
793 elseif(TEST_PNG_G18)
794 if(NOT gamma_type STREQUAL "1.8")
795 set(TEST_PNG_VALID FALSE)
796 endif()
797 else()
798 if(NOT gamma_type STREQUAL "none")
799 set(TEST_PNG_VALID FALSE)
800 endif()
801 endif()
802
803 if(TEST_PNG_VALID)
804 list(APPEND PNGSTEST_FILES "${test_png}")
805 endif()
806 endforeach()
807 # Should already be sorted, but sort anyway to be certain.
808 list(SORT PNGSTEST_FILES)
809 png_add_test(NAME pngstest-${gamma_type}-${alpha_type}
810 COMMAND pngstest
811 OPTIONS --tmpfile "${gamma_type}-${alpha_type}-" --log
812 FILES ${PNGSTEST_FILES})
813 endforeach()
814 endforeach()
815
816 add_executable(pngunknown ${pngunknown_sources})
817 target_link_libraries(pngunknown PRIVATE png_shared)
818
819 png_add_test(NAME pngunknown-discard
820 COMMAND pngunknown
821 OPTIONS --strict default=discard
822 FILES "${PNGTEST_PNG}")
823 png_add_test(NAME pngunknown-IDAT
824 COMMAND pngunknown
825 OPTIONS --strict default=discard IDAT=save
826 FILES "${PNGTEST_PNG}")
827 png_add_test(NAME pngunknown-if-safe
828 COMMAND pngunknown
829 OPTIONS --strict default=if-safe
830 FILES "${PNGTEST_PNG}")
831 png_add_test(NAME pngunknown-sAPI
832 COMMAND pngunknown
833 OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save
834 FILES "${PNGTEST_PNG}")
835 png_add_test(NAME pngunknown-save
836 COMMAND pngunknown
837 OPTIONS --strict default=save
838 FILES "${PNGTEST_PNG}")
839 png_add_test(NAME pngunknown-sTER
840 COMMAND pngunknown
841 OPTIONS --strict sTER=if-safe
842 FILES "${PNGTEST_PNG}")
843 png_add_test(NAME pngunknown-vpAg
844 COMMAND pngunknown
845 OPTIONS --strict vpAg=if-safe
846 FILES "${PNGTEST_PNG}")
847
848 add_executable(pngimage ${pngimage_sources})
849 target_link_libraries(pngimage PRIVATE png_shared)
850
851 png_add_test(NAME pngimage-quick
852 COMMAND pngimage
853 OPTIONS --list-combos --log
854 FILES ${PNGSUITE_PNGS})
855 png_add_test(NAME pngimage-full
856 COMMAND pngimage
857 OPTIONS --exhaustive --list-combos --log
858 FILES ${PNGSUITE_PNGS})
859endif()
860
861if(PNG_SHARED AND PNG_TOOLS)
862 add_executable(pngfix ${pngfix_sources})
863 target_link_libraries(pngfix PRIVATE png_shared)
864 set(PNG_BIN_TARGETS pngfix)
865
866 add_executable(png-fix-itxt ${png_fix_itxt_sources})
867 target_link_libraries(png-fix-itxt PRIVATE ZLIB::ZLIB ${M_LIBRARY})
868 list(APPEND PNG_BIN_TARGETS png-fix-itxt)
869endif()
870
871# Create a symlink that points to a target file (if symlinking is possible),
872# or make a copy of the target file (if symlinking is not possible):
873# create_symlink(<destfile> [FILE <file> | TARGET <target>])
874function(create_symlink DEST_FILE)
875 # TODO:
876 # Replace this implementation with CMake's built-in create_symlink function,
877 # which has been fully functional on all platforms, including Windows, since
878 # CMake version 3.13.
879 cmake_parse_arguments(_SYM "" "FILE;TARGET" "" ${ARGN})
880 if(NOT _SYM_FILE AND NOT _SYM_TARGET)
881 message(FATAL_ERROR "create_symlink: Missing FILE or TARGET argument")
882 endif()
883 if(_SYM_FILE AND _SYM_TARGET)
884 message(FATAL_ERROR "create_symlink: "
885 "The arguments FILE (${_SYM_FILE}) and TARGET (${_SYM_TARGET}) "
886 "are mutually-exclusive")
887 endif()
888
889 if(_SYM_FILE)
890 # If we don't need to symlink something that's coming from a build target,
891 # we can go ahead and symlink/copy at configure time.
892 if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
893 execute_process(COMMAND "${CMAKE_COMMAND}"
894 -E copy_if_different
895 ${_SYM_FILE} ${DEST_FILE}
896 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
897 else()
898 execute_process(COMMAND "${CMAKE_COMMAND}"
899 -E create_symlink
900 ${_SYM_FILE} ${DEST_FILE}
901 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
902 endif()
903 endif()
904
905 if(_SYM_TARGET)
906 # We need to use generator expressions, which can be a bit tricky.
907 # For simplicity, make the symlink a POST_BUILD step, and use the TARGET
908 # signature of add_custom_command.
909 if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
910 add_custom_command(TARGET ${_SYM_TARGET}
911 POST_BUILD
912 COMMAND "${CMAKE_COMMAND}"
913 -E copy_if_different
914 $<TARGET_LINKER_FILE_DIR:${_SYM_TARGET}>/$<TARGET_LINKER_FILE_NAME:${_SYM_TARGET}>
915 $<TARGET_LINKER_FILE_DIR:${_SYM_TARGET}>/${DEST_FILE})
916 else()
917 add_custom_command(TARGET ${_SYM_TARGET}
918 POST_BUILD
919 COMMAND "${CMAKE_COMMAND}"
920 -E create_symlink
921 $<TARGET_LINKER_FILE_NAME:${_SYM_TARGET}>
922 $<TARGET_LINKER_FILE_DIR:${_SYM_TARGET}>/${DEST_FILE})
923 endif()
924 endif()
925endfunction()
926
927# Create source generation scripts.
928configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/genchk.cmake.in
929 ${CMAKE_CURRENT_BINARY_DIR}/scripts/cmake/genchk.cmake
930 @ONLY)
931configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/genout.cmake.in
932 ${CMAKE_CURRENT_BINARY_DIR}/scripts/cmake/genout.cmake
933 @ONLY)
934configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/gensrc.cmake.in
935 ${CMAKE_CURRENT_BINARY_DIR}/scripts/cmake/gensrc.cmake
936 @ONLY)
937
938# libpng is a library so default to 'lib'
939if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
940 set(CMAKE_INSTALL_LIBDIR lib)
941endif()
942
943# Create pkgconfig files.
944# We use the same files like ./configure, so we have to set its vars.
945# Only do this on Windows for Cygwin - the files don't make much sense
946# outside of a UNIX look-alike.
947if(NOT WIN32 OR CYGWIN OR MINGW)
948 set(prefix ${CMAKE_INSTALL_PREFIX})
949 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
950 set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
951 set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
952 set(LIBS "-lz -lm")
953 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
954 ${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}.pc
955 @ONLY)
956 create_symlink(libpng.pc FILE libpng${PNGLIB_ABI_VERSION}.pc)
957 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
958 ${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config
959 @ONLY)
960 create_symlink(libpng-config FILE libpng${PNGLIB_ABI_VERSION}-config)
961endif()
962
963# Install.
964if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
965 install(TARGETS ${PNG_LIBRARY_TARGETS}
966 EXPORT libpng
967 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
968 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
969 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
970 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
971
972 if(PNG_SHARED)
973 # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
974 if(NOT WIN32 OR CYGWIN OR MINGW)
975 create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png_shared)
976 install(FILES $<TARGET_LINKER_FILE_DIR:png_shared>/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
977 DESTINATION ${CMAKE_INSTALL_LIBDIR})
978 endif()
979 endif()
980
981 if(PNG_STATIC)
982 if(NOT WIN32 OR CYGWIN OR MINGW)
983 create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static)
984 install(FILES $<TARGET_LINKER_FILE_DIR:png_static>/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
985 DESTINATION ${CMAKE_INSTALL_LIBDIR})
986 endif()
987 endif()
988endif()
989
990if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
991 install(FILES ${libpng_public_hdrs}
992 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
993 install(FILES ${libpng_public_hdrs}
994 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION})
995endif()
996if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL)
997 if(NOT WIN32 OR CYGWIN OR MINGW)
998 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
999 DESTINATION ${CMAKE_INSTALL_BINDIR})
1000 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config
1001 DESTINATION ${CMAKE_INSTALL_BINDIR})
1002 endif()
1003endif()
1004
1005if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL)
1006 install(TARGETS ${PNG_BIN_TARGETS}
1007 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1008endif()
1009
1010if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
1011 # Install the man pages.
1012 install(FILES libpng.3 libpngpf.3
1013 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
1014 install(FILES png.5
1015 DESTINATION ${CMAKE_INSTALL_MANDIR}/man5)
1016 # Install the pkg-config files.
1017 if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
1018 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
1019 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1020 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
1021 DESTINATION ${CMAKE_INSTALL_BINDIR})
1022 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}.pc
1023 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1024 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config
1025 DESTINATION ${CMAKE_INSTALL_BINDIR})
1026 endif()
1027endif()
1028
1029# Create an export file that CMake users can include() to import our targets.
1030if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL)
1031 install(EXPORT libpng
1032 DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpng
1033 FILE libpng${PNGLIB_ABI_VERSION}.cmake)
1034endif()
1035
1036# Create a CMake Config File that can be used via find_package(PNG CONFIG)
1037if(NOT SKIP_INSTALL_CONFIG_FILE AND NOT SKIP_INSTALL_ALL)
1038 install(TARGETS ${PNG_LIBRARY_TARGETS}
1039 EXPORT PNGTargets
1040 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1041 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1042 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1043 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
1044
1045 include(CMakePackageConfigHelpers)
1046 write_basic_package_version_file(PNGConfigVersion.cmake
1047 VERSION ${PNGLIB_VERSION}
1048 COMPATIBILITY SameMinorVersion)
1049
1050 install(EXPORT PNGTargets
1051 FILE PNGTargets.cmake
1052 NAMESPACE PNG::
1053 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PNG)
1054
1055 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/PNGConfig.cmake
1056 ${CMAKE_CURRENT_BINARY_DIR}/PNGConfigVersion.cmake
1057 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PNG)
1058endif()
1059
1060# TODO: Create MSVC import lib for MinGW-compiled shared lib.
1061# pexports libpng.dll > libpng.def
1062# lib /def:libpng.def /machine:x86
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette