PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Image_LibPNG154/CMakeLists.txt

http://github.com/Akranar/daguerreo
CMake | 418 lines | 275 code | 47 blank | 96 comment | 36 complexity | e24aa402b0a236a04aac58f7dd931307 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, LGPL-3.0, GPL-2.0
  1cmake_minimum_required(VERSION 2.4.4)
  2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
  3
  4if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
  5  if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
  6    # workaround CMake 2.4.x bug
  7    set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
  8        "Choose the type of build, options are:
  9           None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
 10           Debug
 11           Release
 12           RelWithDebInfo
 13           MinSizeRel.")
 14  else()
 15    set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
 16        "Choose the type of build, options are:
 17           None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
 18           Debug
 19           Release
 20           RelWithDebInfo
 21           MinSizeRel.")
 22  endif()
 23endif()
 24
 25project(libpng C)
 26enable_testing()
 27
 28# Copyright (C) 2007-2011 Glenn Randers-Pehrson
 29
 30# This code is released under the libpng license.
 31# For conditions of distribution and use, see the disclaimer
 32# and license in png.h
 33
 34set(PNGLIB_MAJOR 1)
 35set(PNGLIB_MINOR 5)
 36set(PNGLIB_RELEASE 4)
 37set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
 38set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
 39
 40# needed packages
 41##Original:
 42    #find_package(ZLIB REQUIRED)
 43    #include_directories(${ZLIB_INCLUDE_DIR})
 44##Akranar Added Begin:
 45SET(PNG_PROJECT_NAME Image_LibPNG154)
 46SET(ZLIB_LIBRARY IO_ZLIB)
 47SET(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../IO_ZLIB)
 48SET(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../IO_ZLIB)
 49include_directories(${ZLIB_INCLUDE_DIR})
 50SET(SKIP_INSTALL_ALL TRUE)
 51##Akranar Added End:
 52
 53if(NOT WIN32)
 54  find_library(M_LIBRARY
 55    NAMES m
 56    PATHS /usr/lib /usr/local/lib
 57  )
 58  if(NOT M_LIBRARY)
 59    message(STATUS
 60      "math library 'libm' not found - floating point support disabled")
 61  endif()
 62else()
 63  # not needed on windows
 64  set(M_LIBRARY "")
 65endif()
 66
 67# COMMAND LINE OPTIONS
 68if(DEFINED PNG_SHARED)
 69  option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
 70else()
 71  option(PNG_SHARED "Build shared lib" OFF) #Akranar changed from ON to OFF
 72endif()
 73if(DEFINED PNG_STATIC)
 74  option(PNG_STATIC "Build static lib" ${PNG_STATIC})
 75else()
 76  option(PNG_STATIC "Build static lib" ON)
 77endif()
 78
 79##Akranar Deleted Begin:
 80#if(MINGW)
 81#  option(PNG_TESTS  "Build pngtest" NO)
 82#else()
 83#  option(PNG_TESTS  "Build pngtest" YES)
 84#endif()
 85#
 86#option(PNG_NO_CONSOLE_IO "FIXME" YES)
 87#option(PNG_NO_STDIO      "FIXME" YES)
 88#option(PNG_DEBUG         "Build with debug output" NO)
 89#option(PNGARG            "FIXME" YES)
 90##TODO:
 91## PNG_CONSOLE_IO_SUPPORTED
 92#
 93## maybe needs improving, but currently I don't know when we can enable what :)
 94#set(png_asm_tmp "OFF")
 95#if(NOT WIN32)
 96#  find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
 97#  if(uname_executable)
 98#    exec_program(${uname_executable}
 99#                 ARGS --machine OUTPUT_VARIABLE uname_output)
100#    if("uname_output" MATCHES "^.*i[1-9]86.*$")
101#      set(png_asm_tmp "ON")
102#    else("uname_output" MATCHES "^.*i[1-9]86.*$")
103#      set(png_asm_tmp "OFF")
104#    endif("uname_output" MATCHES "^.*i[1-9]86.*$")
105#  endif(uname_executable)
106#else()
107#  # this env var is normally only set on win64
108#  set(TEXT "ProgramFiles(x86)")
109#  if("$ENV{${TEXT}}" STREQUAL "")
110#    set(png_asm_tmp "ON")
111#  endif("$ENV{${TEXT}}" STREQUAL "")
112#endif()
113##Akranar Delete End
114
115# SET LIBNAME
116set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
117
118# to distinguish between debug and release lib
119set(CMAKE_DEBUG_POSTFIX "d")
120
121# Use the prebuilt pnglibconf.h file from the scripts folder
122configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
123               ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
124include_directories(${CMAKE_CURRENT_BINARY_DIR})
125
126# OUR SOURCES
127set(libpng_public_hdrs
128  png.h
129  pngconf.h
130  ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
131)
132set(libpng_sources
133  ${libpng_public_hdrs}
134  pngdebug.h
135  pnginfo.h
136  pngpriv.h
137  pngstruct.h
138  png.c
139  pngerror.c
140  pngget.c
141  pngmem.c
142  pngpread.c
143  pngread.c
144  pngrio.c
145  pngrtran.c
146  pngrutil.c
147  pngset.c
148  pngtrans.c
149  pngwio.c
150  pngwrite.c
151  pngwtran.c
152  pngwutil.c
153)
154set(pngtest_sources
155  pngtest.c
156)
157# SOME NEEDED DEFINITIONS
158
159add_definitions(-DPNG_CONFIGURE_LIBPNG)
160
161if(MSVC)
162  add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
163endif(MSVC)
164
165if(PNG_SHARED OR  NOT MSVC)
166  #if building msvc static this has NOT to be defined
167  add_definitions(-DZLIB_DLL)
168endif()
169
170
171if(PNG_CONSOLE_IO_SUPPORTED)
172  add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
173endif()
174
175if(PNG_NO_CONSOLE_IO)
176  add_definitions(-DPNG_NO_CONSOLE_IO)
177endif()
178
179if(PNG_NO_STDIO)
180  add_definitions(-DPNG_NO_STDIO)
181endif()
182
183if(PNG_DEBUG)
184  add_definitions(-DPNG_DEBUG)
185endif()
186
187if(NOT M_LIBRARY AND NOT WIN32)
188  add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
189endif()
190
191# NOW BUILD OUR TARGET
192include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
193
194if(PNG_SHARED)
195  add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
196  if(MSVC)
197    # msvc does not append 'lib' - do it here to have consistent name
198    set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
199    set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
200  endif()
201  target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
202endif()
203
204if(PNG_STATIC)
205# does not work without changing name
206##Original:
207#  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
208#  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
209#  if(MSVC)
210#    # msvc does not append 'lib' - do it here to have consistent name
211#    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
212#  endif()
213#  target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
214##Akranar Change Begin:
215    SET(PNG_LIB_NAME_STATIC ${PNG_PROJECT_NAME})
216    ADD_LIBRARY(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
217##Akranar Change End:
218endif()
219
220
221if(PNG_SHARED AND WIN32)
222  set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
223endif()
224
225if(PNG_TESTS AND PNG_SHARED)
226  # does not work with msvc due to png_lib_ver issue
227  add_executable(pngtest ${pngtest_sources})
228  target_link_libraries(pngtest ${PNG_LIB_NAME})
229  add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
230endif()
231
232#
233# Set a variable with CMake code which:
234# Creates a symlink from src to dest (if possible) or alternatively
235# copies if different.
236macro(_png_generate_symlink_code CODE SRC DEST)
237  if(WIN32 AND NOT CYGWIN)
238    set(_png_gsc_message "Copying ${SRC} to ${DEST} if needed")
239    set(_png_gsc_operation "copy_if_different")
240  else()
241    set(_png_gsc_message "Symlinking ${SRC} to ${DEST}")
242    set(_png_gsc_operation "create_symlink")
243  endif()
244
245  set(${CODE} "
246    message(STATUS \"${_png_gsc_message}\")
247    execute_process(COMMAND \${CMAKE_COMMAND} -E ${_png_gsc_operation}
248      \"${SRC}\" \"${DEST}\")
249    ")
250endmacro()
251
252# CREATE PKGCONFIG FILES
253# we use the same files like ./configure, so we have to set its vars
254if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
255  set(CMAKE_INSTALL_LIBDIR lib)
256endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
257set(prefix      ${CMAKE_INSTALL_PREFIX})
258set(exec_prefix ${CMAKE_INSTALL_PREFIX})
259set(libdir      ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
260set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
261set(LIBS        "-lz -lm")
262configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
263  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
264_png_generate_symlink_code(PNG_PC_INSTALL_CODE
265  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
266  ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
267install(CODE ${PNG_PC_INSTALL_CODE})
268
269configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
270  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
271_png_generate_symlink_code(PNG_CONFIG_INSTALL_CODE
272  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
273  ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
274install(CODE ${PNG_CONFIG_INSTALL_CODE})
275
276# SET UP LINKS
277if(PNG_SHARED)
278  set_target_properties(${PNG_LIB_NAME} PROPERTIES
279#   VERSION 15.${PNGLIB_RELEASE}.1.5.4
280    VERSION 15.${PNGLIB_RELEASE}.0
281    SOVERSION 15
282    CLEAN_DIRECT_OUTPUT 1)
283endif()
284if(PNG_STATIC)
285  # MSVC doesn't use a different file extension for shared vs. static
286  # libs.  We are able to change OUTPUT_NAME to remove the _static
287  # for all other platforms.
288  if(NOT MSVC)
289    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
290      OUTPUT_NAME ${PNG_LIB_NAME}
291      CLEAN_DIRECT_OUTPUT 1)
292  endif()
293endif()
294
295# If CMake > 2.4.x, we set a variable used below to export
296# targets to an export file.
297# TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
298if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
299  set(PNG_EXPORT_RULE EXPORT libpng)
300elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
301  set(PNG_EXPORT_RULE EXPORT libpng)
302endif()
303
304# INSTALL
305if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
306  if(PNG_SHARED)
307    install(TARGETS ${PNG_LIB_NAME}
308        ${PNG_EXPORT_RULE}
309        RUNTIME DESTINATION bin
310        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
311        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
312
313    # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
314    if(CYGWIN)
315      _png_generate_symlink_code(PNG_SHARED_IMPLIB_INSTALL_CODE
316        ${PNGLIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}
317        libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
318      install(CODE ${PNG_SHARED_IMPLIB_INSTALL_CODE})
319      install(FILES
320        ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
321        DESTINATION ${CMAKE_INSTALL_LIBDIR})
322    endif()
323
324    if(NOT WIN32)
325      IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
326        _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
327 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
328 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
329                install(CODE ${PNG_SHARED_INSTALL_CODE})
330                install(FILES
331 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
332                DESTINATION ${CMAKE_INSTALL_LIBDIR})
333      ELSE(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
334        _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
335           ${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
336           libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
337        install(CODE ${PNG_SHARED_INSTALL_CODE})
338        install(FILES
339           ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
340                DESTINATION ${CMAKE_INSTALL_LIBDIR})
341      ENDIF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
342    endif()
343  endif()
344
345  if(PNG_STATIC)
346    install(TARGETS ${PNG_LIB_NAME_STATIC}
347        ${PNG_EXPORT_RULE}
348            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
349            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
350    if(NOT WIN32 OR CYGWIN)
351      IF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
352         _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
353${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
354        ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
355        install(CODE ${PNG_STATIC_INSTALL_CODE})
356        install(FILES
357          ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
358             DESTINATION ${CMAKE_INSTALL_LIBDIR})
359      ELSE(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
360        _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
361           ${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
362           libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
363        install(CODE ${PNG_STATIC_INSTALL_CODE})
364        install(FILES
365          ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
366                     DESTINATION ${CMAKE_INSTALL_LIBDIR})
367      ENDIF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
368    endif()
369  endif()
370endif()
371
372if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
373  install(FILES ${libpng_public_hdrs}   DESTINATION include)
374  install(FILES ${libpng_public_hdrs}   DESTINATION include/${PNGLIB_NAME})
375endif()
376if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
377  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
378  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
379          DESTINATION bin)
380endif()
381if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
382  # Install man pages
383  if(NOT PNG_MAN_DIR)
384    set(PNG_MAN_DIR "share/man")
385  endif()
386  install(FILES libpng.3 libpngpf.3      DESTINATION ${PNG_MAN_DIR}/man3)
387  install(FILES png.5                    DESTINATION ${PNG_MAN_DIR}/man5)
388  # Install pkg-config files
389  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
390          DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
391  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
392          DESTINATION bin)
393  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
394          DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
395  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
396          DESTINATION bin)
397endif()
398
399# On versions of CMake that support it, create an export file CMake
400# users can include() to import our targets
401if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
402  install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
403endif()
404
405# what's with libpng-$VER%.txt and all the extra files?
406
407
408# UNINSTALL
409# do we need this?
410
411
412# DIST
413# do we need this?
414
415# to create msvc import lib for mingw compiled shared lib
416# pexports libpng.dll > libpng.def
417# lib /def:libpng.def /machine:x86
418