]> git.saurik.com Git - wxWidgets.git/blob - src/png/CMakeLists.txt
No longer use semi-static IDs for wxPropertyGrid embedded controls and tool bar tools.
[wxWidgets.git] / src / png / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
3
4 if(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()
17 endif()
18
19 project(libpng C)
20 enable_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
28 set(PNGLIB_MAJOR 1)
29 set(PNGLIB_MINOR 4)
30 set(PNGLIB_RELEASE 4)
31 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
32 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
33
34 # needed packages
35 find_package(ZLIB REQUIRED)
36 include_directories(${ZLIB_INCLUDE_DIR})
37
38 if(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()
47 else()
48 # not needed on windows
49 set(M_LIBRARY "")
50 endif()
51
52 # COMMAND LINE OPTIONS
53 if(DEFINED PNG_SHARED)
54 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
55 else()
56 option(PNG_SHARED "Build shared lib" ON)
57 endif()
58 if(DEFINED PNG_STATIC)
59 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
60 else()
61 option(PNG_STATIC "Build static lib" ON)
62 endif()
63
64 if(MINGW)
65 option(PNG_TESTS "Build pngtest" NO)
66 else()
67 option(PNG_TESTS "Build pngtest" YES)
68 endif()
69
70 option(PNG_NO_CONSOLE_IO "FIXME" YES)
71 option(PNG_NO_STDIO "FIXME" YES)
72 option(PNG_DEBUG "Build with debug output" NO)
73 option(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 :)
78 set(png_asm_tmp "OFF")
79 if(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)
90 else()
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 "")
96 endif()
97
98 # SET LIBNAME
99 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
100
101 # to distinguish between debug and release lib
102 set(CMAKE_DEBUG_POSTFIX "d")
103
104
105 # OUR SOURCES
106 set(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 )
126 set(pngtest_sources
127 pngtest.c
128 )
129 # SOME NEEDED DEFINITIONS
130
131 add_definitions(-DPNG_CONFIGURE_LIBPNG)
132
133 if(_AIX)
134 add_definitions(-D_ALL_SOURCE)
135 endif(_AIX)
136
137 if(MSVC)
138 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
139 endif(MSVC)
140
141 if(PNG_SHARED OR NOT MSVC)
142 #if building msvc static this has NOT to be defined
143 add_definitions(-DZLIB_DLL)
144 endif()
145
146
147 if(PNG_CONSOLE_IO_SUPPORTED)
148 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
149 endif()
150
151 if(PNG_NO_CONSOLE_IO)
152 add_definitions(-DPNG_NO_CONSOLE_IO)
153 endif()
154
155 if(PNG_NO_STDIO)
156 add_definitions(-DPNG_NO_STDIO)
157 endif()
158
159 if(PNG_DEBUG)
160 add_definitions(-DPNG_DEBUG)
161 endif()
162
163 if(NOT M_LIBRARY AND NOT WIN32)
164 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
165 endif()
166
167 # NOW BUILD OUR TARGET
168 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
169
170 if(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})
178 endif()
179
180 if(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})
189 endif()
190
191
192 if(PNG_SHARED AND WIN32)
193 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
194 endif()
195
196 if(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)
201 endif()
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.
207 macro(_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 ")
221 endmacro()
222
223 # CREATE PKGCONFIG FILES
224 # we use the same files like ./configure, so we have to set its vars
225 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
226 set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
227 endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
228 set(prefix ${CMAKE_INSTALL_PREFIX})
229 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
230 set(libdir ${CMAKE_INSTALL_LIBDIR})
231 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
232 set(LIBS "-lz -lm")
233 configure_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)
236 install(CODE ${PNG_PC_INSTALL_CODE})
237
238 configure_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)
241 install(CODE ${PNG_CONFIG_INSTALL_CODE})
242
243 # SET UP LINKS
244 if(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)
250 endif()
251 if(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()
260 endif()
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
265 if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
266 set(PNG_EXPORT_RULE EXPORT libpng)
267 elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
268 set(PNG_EXPORT_RULE EXPORT libpng)
269 endif()
270
271 # INSTALL
272 if(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()
311 endif()
312
313 if(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})
316 endif()
317 if(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)
321 endif()
322 if(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)
338 endif()
339
340 # On versions of CMake that support it, create an export file CMake
341 # users can include() to import our targets
342 if(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)
344 endif()
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