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