blob: d57f7a698ad0bcd66b720d189deacf0c5faf9266 [file] [log] [blame]
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -05001# CMakeLists.txt
2
3# Copyright (C) 2007-2011 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
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -05009cmake_minimum_required(VERSION 2.4.4)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060010set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
11
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -050012if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050013 if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
14 # workaround CMake 2.4.x bug
Glenn Randers-Pehrsone89d33a2010-10-02 21:36:02 -050015 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.")
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050022 else()
23 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
24 "Choose the type of build, options are:
25 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
26 Debug
27 Release
28 RelWithDebInfo
29 MinSizeRel.")
30 endif()
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -050031endif()
32
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060033project(libpng C)
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -050034enable_testing()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060035
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050036set(PNGLIB_MAJOR 1)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060037set(PNGLIB_MINOR 5)
Glenn Randers-Pehrson115020d2011-09-22 09:08:31 -050038set(PNGLIB_RELEASE 6)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050039set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
40set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060041
42# needed packages
43find_package(ZLIB REQUIRED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050044include_directories(${ZLIB_INCLUDE_DIR})
45
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050046if(NOT WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060047 find_library(M_LIBRARY
48 NAMES m
49 PATHS /usr/lib /usr/local/lib
50 )
51 if(NOT M_LIBRARY)
52 message(STATUS
53 "math library 'libm' not found - floating point support disabled")
54 endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050055else()
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060056 # not needed on windows
57 set(M_LIBRARY "")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050058endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060059
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050060# COMMAND LINE OPTIONS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050061if(DEFINED PNG_SHARED)
62 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
63else()
64 option(PNG_SHARED "Build shared lib" ON)
65endif()
66if(DEFINED PNG_STATIC)
67 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
68else()
69 option(PNG_STATIC "Build static lib" ON)
70endif()
71
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -050072option(PNG_TESTS "Build libpng tests" YES)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050073
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -050074# Many more configuration options could be added here
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050075option(PNG_DEBUG "Build with debug output" NO)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -050076option(PNGARG "Disable ANSI-C prototypes" NO)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060077
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050078# SET LIBNAME
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050079set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060080
81# to distinguish between debug and release lib
82set(CMAKE_DEBUG_POSTFIX "d")
83
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050084# Use the prebuilt pnglibconf.h file from the scripts folder
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -050085# TODO: fix this by building with awk; without this no cmake build can be
86# configured directly (to do so indirectly use your local awk to build a
87# pnglibconf.h in the build directory.)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050088configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
89 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
90include_directories(${CMAKE_CURRENT_BINARY_DIR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060091
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050092# OUR SOURCES
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050093set(libpng_public_hdrs
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060094 png.h
95 pngconf.h
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -050096 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
97)
98set(libpng_sources
99 ${libpng_public_hdrs}
Glenn Randers-Pehrson07d9fc92010-08-26 17:11:55 -0500100 pngdebug.h
101 pnginfo.h
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500102 pngpriv.h
Glenn Randers-Pehrson07d9fc92010-08-26 17:11:55 -0500103 pngstruct.h
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600104 png.c
105 pngerror.c
106 pngget.c
107 pngmem.c
108 pngpread.c
109 pngread.c
110 pngrio.c
111 pngrtran.c
112 pngrutil.c
113 pngset.c
114 pngtrans.c
115 pngwio.c
116 pngwrite.c
117 pngwtran.c
118 pngwutil.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600119)
120set(pngtest_sources
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600121 pngtest.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600122)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500123set(pngvalid_sources
124 pngvalid.c
125)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500126# SOME NEEDED DEFINITIONS
Glenn Randers-Pehrson69b0bc02009-11-07 12:02:48 -0600127
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500128add_definitions(-DPNG_CONFIGURE_LIBPNG)
129
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600130if(MSVC)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500131 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600132endif(MSVC)
133
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500134if(PNG_DEBUG)
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500135 add_definitions(-DPNG_DEBUG)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500136endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500137
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500138# NOW BUILD OUR TARGET
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600139include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600140
141if(PNG_SHARED)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600142 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
143 if(MSVC)
144 # msvc does not append 'lib' - do it here to have consistent name
145 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500146 set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600147 endif()
148 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500149endif()
150
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500151if(PNG_STATIC)
152# does not work without changing name
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600153 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
154 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
155 if(MSVC)
156 # msvc does not append 'lib' - do it here to have consistent name
157 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
158 endif()
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500159 target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500160endif()
161
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600162if(PNG_SHARED AND WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600163 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500164endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600165
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500166if(PNG_TESTS AND PNG_SHARED)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600167 # 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})
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500170 add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500171 #
172 add_executable(pngvalid ${pngvalid_sources})
173 target_link_libraries(pngvalid ${PNG_LIB_NAME})
174 add_test(pngvalid ./pngvalid)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500175endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600176
Glenn Randers-Pehrsone61e4032011-08-17 09:02:07 -0500177# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set
178IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500179 IF(WIN32)
180 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "bin")
181 ELSE(WIN32)
182 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
183 ENDIF(WIN32)
Glenn Randers-Pehrsone61e4032011-08-17 09:02:07 -0500184ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
185
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500186# Set a variable with CMake code which:
187# Creates a symlink from src to dest (if possible) or alternatively
188# copies if different.
Glenn Randers-Pehrsonb17c75b2011-07-27 20:47:13 -0500189macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500190 FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
191 if(WIN32 AND NOT CYGWIN)
192 ADD_CUSTOM_COMMAND(
193 OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
194 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
195 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
196 DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC}
197 )
198 ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
199 else(WIN32 AND NOT CYGWIN)
200 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
201 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
202 endif(WIN32 AND NOT CYGWIN)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500203endmacro()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600204
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500205# libpng is a library so default to 'lib'
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500206if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
Glenn Randers-Pehrsond3edb3f2011-01-14 17:08:28 -0600207 set(CMAKE_INSTALL_LIBDIR lib)
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500208endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500209
210# CREATE PKGCONFIG FILES
211# we use the same files like ./configure, so we have to set its vars
212# Only do this on Windows for Cygwin - the files don't make much sense outside
213# a UNIX look alike
214if(NOT WIN32 OR CYGWIN)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500215set(prefix ${CMAKE_INSTALL_PREFIX})
216set(exec_prefix ${CMAKE_INSTALL_PREFIX})
Glenn Randers-Pehrsond3edb3f2011-01-14 17:08:28 -0600217set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500218set(includedir ${CMAKE_INSTALL_PREFIX}/include)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500219set(LIBS "-lz -lm")
220configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500221 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
Glenn Randers-Pehrsonb17c75b2011-07-27 20:47:13 -0500222CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500223
224configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500225 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
Glenn Randers-Pehrsonb17c75b2011-07-27 20:47:13 -0500226CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config)
Glenn Randers-Pehrsone29c4b92011-09-27 19:01:58 -0500227endif(NOT WIN32 OR CYGWIN)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500228
229# SET UP LINKS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500230if(PNG_SHARED)
231 set_target_properties(${PNG_LIB_NAME} PROPERTIES
Glenn Randers-Pehrsonf573ff72011-09-26 16:49:01 -0500232# VERSION 15.${PNGLIB_RELEASE}.1.5.6beta03
Glenn Randers-Pehrsonf1eb9182010-02-08 15:36:41 -0600233 VERSION 15.${PNGLIB_RELEASE}.0
234 SOVERSION 15
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600235 CLEAN_DIRECT_OUTPUT 1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500236endif()
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500237if(PNG_STATIC)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500238 # MSVC doesn't use a different file extension for shared vs. static
239 # libs. We are able to change OUTPUT_NAME to remove the _static
240 # for all other platforms.
241 if(NOT MSVC)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500242 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600243 OUTPUT_NAME ${PNG_LIB_NAME}
244 CLEAN_DIRECT_OUTPUT 1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500245 endif()
246endif()
247
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500248# If CMake > 2.4.x, we set a variable used below to export
249# targets to an export file.
250# TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
251if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
252 set(PNG_EXPORT_RULE EXPORT libpng)
253elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
254 set(PNG_EXPORT_RULE EXPORT libpng)
255endif()
256
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500257# INSTALL
258if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600259 if(PNG_SHARED)
260 install(TARGETS ${PNG_LIB_NAME}
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500261 ${PNG_EXPORT_RULE}
262 RUNTIME DESTINATION bin
263 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
264 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
265
Glenn Randers-Pehrson8409b8f2010-12-31 09:14:01 -0600266 # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500267 if(CYGWIN)
268 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
269 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
270 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
271 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
272 DESTINATION ${CMAKE_INSTALL_LIBDIR})
273 endif(CYGWIN)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500274
275 if(NOT WIN32)
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500276 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
277 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
278 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
279 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
280 DESTINATION ${CMAKE_INSTALL_LIBDIR})
Glenn Randers-Pehrsonb17c75b2011-07-27 20:47:13 -0500281 endif(NOT WIN32)
282 endif(PNG_SHARED)
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500283
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600284 if(PNG_STATIC)
285 install(TARGETS ${PNG_LIB_NAME_STATIC}
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500286 ${PNG_EXPORT_RULE}
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500287 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
288 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500289 if(NOT WIN32 OR CYGWIN)
Glenn Randers-Pehrson0c03fc62011-08-17 09:46:29 -0500290 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
291 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
292 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
293 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
294 DESTINATION ${CMAKE_INSTALL_LIBDIR})
295 endif(NOT WIN32 OR CYGWIN)
Glenn Randers-Pehrsonb17c75b2011-07-27 20:47:13 -0500296 endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500297endif()
298
299if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500300 install(FILES ${libpng_public_hdrs} DESTINATION include)
301 install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME})
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -0500302endif()
303if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600304 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
305 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
306 DESTINATION bin)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500307endif()
308if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600309 # Install man pages
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500310 if(NOT PNG_MAN_DIR)
311 set(PNG_MAN_DIR "share/man")
312 endif()
313 install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
314 install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600315 # Install pkg-config files
316 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500317 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500318 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600319 DESTINATION bin)
320 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500321 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Glenn Randers-Pehrson8c037302010-08-23 17:07:32 -0500322 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600323 DESTINATION bin)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500324endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500325
Glenn Randers-Pehrson0c3fea32010-10-02 21:25:01 -0500326# On versions of CMake that support it, create an export file CMake
327# users can include() to import our targets
328if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
329 install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
330endif()
331
Glenn Randers-Pehrsond3edb3f2011-01-14 17:08:28 -0600332# what's with libpng-$VER%.txt and all the extra files?
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600333
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500334# UNINSTALL
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600335# do we need this?
336
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500337# DIST
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600338# do we need this?
339
340# to create msvc import lib for mingw compiled shared lib
341# pexports libpng.dll > libpng.def
342# lib /def:libpng.def /machine:x86
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500343