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