all repos — mgba @ 6882339f625b97f344c6464915c2038bc453ea3c

mGBA Game Boy Advance Emulator

src/third-party/libpng/CMakeLists.txt (view raw)

  1# CMakeLists.txt
  2
  3# Copyright (C) 2007-2015 Glenn Randers-Pehrson
  4
  5# This code is released under the libpng license.
  6# For conditions of distribution and use, see the disclaimer
  7# and license in png.h
  8
  9cmake_minimum_required(VERSION 2.4.4)
 10set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
 11
 12set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
 13
 14project(libpng C)
 15enable_testing()
 16
 17set(PNGLIB_MAJOR 1)
 18set(PNGLIB_MINOR 6)
 19set(PNGLIB_RELEASE 17)
 20set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
 21set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
 22
 23# needed packages
 24find_package(ZLIB REQUIRED)
 25include_directories(${ZLIB_INCLUDE_DIR})
 26
 27if(NOT WIN32)
 28  find_library(M_LIBRARY
 29    NAMES m
 30    PATHS /usr/lib /usr/local/lib
 31  )
 32  if(NOT M_LIBRARY)
 33    message(STATUS "math lib 'libm' not found; floating point support disabled")
 34  endif()
 35else()
 36  # not needed on windows
 37  set(M_LIBRARY "")
 38endif()
 39
 40# COMMAND LINE OPTIONS
 41option(PNG_SHARED "Build shared lib" ON)
 42option(PNG_STATIC "Build static lib" ON)
 43option(PNG_TESTS  "Build libpng tests" ON)
 44
 45# Many more configuration options could be added here
 46option(PNG_FRAMEWORK "Build OS X framework" OFF)
 47option(PNG_DEBUG     "Build with debug output" OFF)
 48option(PNGARG        "Disable ANSI-C prototypes" OFF)
 49
 50# SET LIBNAME
 51set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
 52
 53# to distinguish between debug and release lib
 54set(CMAKE_DEBUG_POSTFIX "d")
 55
 56# Use the prebuilt pnglibconf.h file from the scripts folder
 57# TODO: fix this by building with awk; without this no cmake build can be
 58# configured directly (to do so indirectly use your local awk to build a
 59# pnglibconf.h in the build directory.)
 60configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
 61               ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
 62include_directories(${CMAKE_CURRENT_BINARY_DIR})
 63
 64# OUR SOURCES
 65set(libpng_public_hdrs
 66  png.h
 67  pngconf.h
 68  ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
 69)
 70set(libpng_sources
 71  ${libpng_public_hdrs}
 72  pngdebug.h
 73  pnginfo.h
 74  pngpriv.h
 75  pngstruct.h
 76  png.c
 77  pngerror.c
 78  pngget.c
 79  pngmem.c
 80  pngpread.c
 81  pngread.c
 82  pngrio.c
 83  pngrtran.c
 84  pngrutil.c
 85  pngset.c
 86  pngtrans.c
 87  pngwio.c
 88  pngwrite.c
 89  pngwtran.c
 90  pngwutil.c
 91)
 92set(pngtest_sources
 93  pngtest.c
 94)
 95set(pngvalid_sources
 96  contrib/libtests/pngvalid.c
 97)
 98set(pngstest_sources
 99  contrib/libtests/pngstest.c
100)
101# SOME NEEDED DEFINITIONS
102
103if(MSVC)
104  add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
105endif(MSVC)
106
107if(PNG_DEBUG)
108  add_definitions(-DPNG_DEBUG)
109endif()
110
111# NOW BUILD OUR TARGET
112include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
113
114unset(PNG_LIB_TARGETS)
115
116if(PNG_SHARED)
117  add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
118  set(PNG_LIB_TARGETS ${PNG_LIB_NAME})
119  if(MSVC)
120    # msvc does not append 'lib' - do it here to have consistent name
121    set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
122    set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
123  endif()
124  target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
125endif()
126
127if(PNG_STATIC)
128  # does not work without changing name
129  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
130  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
131  list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC})
132  if(MSVC)
133    # msvc does not append 'lib' - do it here to have consistent name
134    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
135  endif()
136  target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
137endif()
138
139if(PNG_FRAMEWORK)
140  set(PNG_LIB_NAME_FRAMEWORK ${PNG_LIB_NAME}_framework)
141  add_library(${PNG_LIB_NAME_FRAMEWORK} SHARED ${libpng_sources})
142  list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_FRAMEWORK})
143  set_target_properties(${PNG_LIB_NAME_FRAMEWORK} PROPERTIES
144    FRAMEWORK TRUE
145    FRAMEWORK_VERSION ${PNGLIB_VERSION}
146    MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
147    MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}
148    MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng
149    XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
150    PUBLIC_HEADER "${libpng_public_hdrs}"
151    OUTPUT_NAME png)
152  target_link_libraries(${PNG_LIB_NAME_FRAMEWORK} ${ZLIB_LIBRARY} ${M_LIBRARY})
153endif()
154
155if(NOT PNG_LIB_TARGETS)
156  message(SEND_ERROR
157    "No library variant selected to build. "
158    "Please enable at least one of the following options: "
159    " PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK")
160endif()
161
162if(PNG_SHARED AND WIN32)
163  set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
164endif()
165
166if(PNG_TESTS AND PNG_SHARED)
167  # does not work with msvc due to png_lib_ver issue
168  add_executable(pngtest ${pngtest_sources})
169  target_link_libraries(pngtest ${PNG_LIB_NAME})
170  add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
171  #
172  add_executable(pngvalid ${pngvalid_sources})
173  target_link_libraries(pngvalid ${PNG_LIB_NAME})
174  add_test(pngvalid ./pngvalid)
175  add_executable(pngstest ${pngstest_sources})
176  target_link_libraries(pngstest ${PNG_LIB_NAME})
177  add_test(pngstest ./pngstest
178    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g01.png
179    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g02.png
180    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g04.png
181    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g08.png
182    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g16.png
183    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c08.png
184    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c16.png
185    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p01.png
186    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p02.png
187    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p04.png
188    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p08.png
189    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a08.png
190    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a16.png
191    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a08.png
192    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a16.png
193    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g01.png
194    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g02.png
195    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g04.png
196    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn2c16.png
197    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn3p08.png
198    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn2c16.png
199    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn3p08.png
200    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbrn2c08.png
201    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn0g16.png
202    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn3p08.png
203    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbyn3p08.png
204    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n0g08.png
205    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n2c08.png
206    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n3p08.png
207    ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp1n3p08.png
208  )
209endif()
210
211# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set
212IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
213  SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
214ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
215
216# Set a variable with CMake code which:
217# Creates a symlink from src to dest (if possible) or alternatively
218# copies if different.
219macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
220  FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
221  if(WIN32 AND NOT CYGWIN AND NOT MSYS)
222    ADD_CUSTOM_COMMAND(
223        OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}   ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
224        COMMAND ${CMAKE_COMMAND} -E copy_if_different  "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
225        COMMAND ${CMAKE_COMMAND} -E copy_if_different  "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
226        DEPENDS ${PNG_LIB_TARGETS}
227        )
228    ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
229  else(WIN32 AND NOT CYGWIN AND NOT MSYS)
230    get_filename_component(LINK_TARGET "${SRC_FILE}" NAME)
231    execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
232    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
233    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
234  endif(WIN32 AND NOT CYGWIN AND NOT MSYS)
235endmacro()
236
237# libpng is a library so default to 'lib'
238if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
239  set(CMAKE_INSTALL_LIBDIR lib)
240endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
241
242# CREATE PKGCONFIG FILES
243# we use the same files like ./configure, so we have to set its vars
244# Only do this on Windows for Cygwin - the files don't make much sense outside
245# a UNIX look alike
246if(NOT WIN32 OR CYGWIN OR MINGW)
247  set(prefix      ${CMAKE_INSTALL_PREFIX})
248  set(exec_prefix ${CMAKE_INSTALL_PREFIX})
249  set(libdir      ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
250  set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
251  set(LIBS        "-lz -lm")
252  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
253    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
254  CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc)
255
256  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
257    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
258  CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config)
259endif(NOT WIN32 OR CYGWIN OR MINGW)
260
261# SET UP LINKS
262if(PNG_SHARED)
263  set_target_properties(${PNG_LIB_NAME} PROPERTIES
264#   VERSION 16.${PNGLIB_RELEASE}.1.6.17
265    VERSION 16.${PNGLIB_RELEASE}.0
266    SOVERSION 16
267    CLEAN_DIRECT_OUTPUT 1)
268endif()
269if(PNG_STATIC)
270  # MSVC doesn't use a different file extension for shared vs. static
271  # libs.  We are able to change OUTPUT_NAME to remove the _static
272  # for all other platforms.
273  if(NOT MSVC)
274    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
275      OUTPUT_NAME ${PNG_LIB_NAME}
276      CLEAN_DIRECT_OUTPUT 1)
277  endif()
278endif()
279
280# If CMake > 2.4.x, we set a variable used below to export
281# targets to an export file.
282# TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
283if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
284  set(PNG_EXPORT_RULE EXPORT libpng)
285elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
286  set(PNG_EXPORT_RULE EXPORT libpng)
287endif()
288
289# INSTALL
290if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
291  install(TARGETS ${PNG_LIB_TARGETS}
292      ${PNG_EXPORT_RULE}
293      RUNTIME DESTINATION bin
294      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
295      ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
296      FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
297
298  if(PNG_SHARED)
299    # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
300    if(CYGWIN OR MINGW)
301       get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
302       CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
303       install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
304         DESTINATION ${CMAKE_INSTALL_LIBDIR})
305    endif(CYGWIN OR MINGW)
306
307    if(NOT WIN32)
308      get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
309      CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
310      install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
311         DESTINATION ${CMAKE_INSTALL_LIBDIR})
312    endif(NOT WIN32)
313  endif(PNG_SHARED)
314
315  if(PNG_STATIC)
316    if(NOT WIN32 OR CYGWIN OR MINGW)
317      get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
318      CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
319      install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
320         DESTINATION ${CMAKE_INSTALL_LIBDIR})
321    endif(NOT WIN32 OR CYGWIN OR MINGW)
322 endif()
323endif()
324
325if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
326  install(FILES ${libpng_public_hdrs}   DESTINATION include)
327  install(FILES ${libpng_public_hdrs}   DESTINATION include/${PNGLIB_NAME})
328endif()
329if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
330  if(NOT WIN32 OR CYGWIN OR MINGW)
331    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
332    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
333            DESTINATION bin)
334  endif(NOT WIN32 OR CYGWIN OR MINGW)
335endif()
336
337if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
338  # Install man pages
339  if(NOT PNG_MAN_DIR)
340    set(PNG_MAN_DIR "share/man")
341  endif()
342  install(FILES libpng.3 libpngpf.3      DESTINATION ${PNG_MAN_DIR}/man3)
343  install(FILES png.5                    DESTINATION ${PNG_MAN_DIR}/man5)
344  # Install pkg-config files
345  if(NOT WIN32 OR CYGWIN OR MINGW)
346    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
347            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
348    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
349            DESTINATION bin)
350    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
351            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
352    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
353            DESTINATION bin)
354  endif(NOT WIN32 OR CYGWIN OR MINGW)
355endif()
356
357# On versions of CMake that support it, create an export file CMake
358# users can include() to import our targets
359if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
360  install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
361endif()
362
363# what's with libpng-manual.txt and all the extra files?
364
365# UNINSTALL
366# do we need this?
367
368# DIST
369# do we need this?
370
371# to create msvc import lib for mingw compiled shared lib
372# pexports libpng.dll > libpng.def
373# lib /def:libpng.def /machine:x86
374