CMakeLists.txt.patched 35 KB

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