1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
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
8 "Choose the type of build, options are:
9 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
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)
28 # Copyright (C) 2007-2011 Glenn Randers-Pehrson
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
37 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
38 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
41 find_package(ZLIB REQUIRED)
42 include_directories(${ZLIB_INCLUDE_DIR})
45 find_library(M_LIBRARY
47 PATHS /usr/lib /usr/local/lib
51 "math library 'libm' not found - floating point support disabled")
54 # not needed on windows
58 # COMMAND LINE OPTIONS
59 if(DEFINED PNG_SHARED)
60 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
62 option(PNG_SHARED "Build shared lib" ON)
64 if(DEFINED PNG_STATIC)
65 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
67 option(PNG_STATIC "Build static lib" ON)
71 option(PNG_TESTS "Build pngtest" NO)
73 option(PNG_TESTS "Build pngtest" YES)
76 option(PNG_NO_CONSOLE_IO "FIXME" YES)
77 option(PNG_NO_STDIO "FIXME" YES)
78 option(PNG_DEBUG "Build with debug output" NO)
79 option(PNGARG "FIXME" YES)
81 # PNG_CONSOLE_IO_SUPPORTED
83 # maybe needs improving, but currently I don't know when we can enable what :)
84 set(png_asm_tmp "OFF")
86 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
88 exec_program(${uname_executable}
89 ARGS --machine OUTPUT_VARIABLE uname_output)
90 if("uname_output" MATCHES "^.*i[1-9]86.*$")
92 else("uname_output" MATCHES "^.*i[1-9]86.*$")
93 set(png_asm_tmp "OFF")
94 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
95 endif(uname_executable)
97 # this env var is normally only set on win64
98 set(TEXT "ProgramFiles(x86)")
99 if("$ENV{${TEXT}}" STREQUAL "")
100 set(png_asm_tmp "ON")
101 endif("$ENV{${TEXT}}" STREQUAL "")
105 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
107 # to distinguish between debug and release lib
108 set(CMAKE_DEBUG_POSTFIX "d")
110 # Use the prebuilt pnglibconf.h file from the scripts folder
111 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
112 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
113 include_directories(${CMAKE_CURRENT_BINARY_DIR})
116 set(libpng_public_hdrs
119 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
122 ${libpng_public_hdrs}
146 # SOME NEEDED DEFINITIONS
148 add_definitions(-DPNG_CONFIGURE_LIBPNG)
151 add_definitions(-D_ALL_SOURCE)
155 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
158 if(PNG_SHARED OR NOT MSVC)
159 #if building msvc static this has NOT to be defined
160 add_definitions(-DZLIB_DLL)
164 if(PNG_CONSOLE_IO_SUPPORTED)
165 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
168 if(PNG_NO_CONSOLE_IO)
169 add_definitions(-DPNG_NO_CONSOLE_IO)
173 add_definitions(-DPNG_NO_STDIO)
177 add_definitions(-DPNG_DEBUG)
180 if(NOT M_LIBRARY AND NOT WIN32)
181 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
184 # NOW BUILD OUR TARGET
185 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
188 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
190 # msvc does not append 'lib' - do it here to have consistent name
191 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
192 set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
194 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
198 # does not work without changing name
199 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
200 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
202 # msvc does not append 'lib' - do it here to have consistent name
203 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
205 target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
209 if(PNG_SHARED AND WIN32)
210 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
213 if(PNG_TESTS AND PNG_SHARED)
214 # does not work with msvc due to png_lib_ver issue
215 add_executable(pngtest ${pngtest_sources})
216 target_link_libraries(pngtest ${PNG_LIB_NAME})
217 add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
221 # Set a variable with CMake code which:
222 # Creates a symlink from src to dest (if possible) or alternatively
223 # copies if different.
224 macro(_png_generate_symlink_code CODE SRC DEST)
225 if(WIN32 AND NOT CYGWIN)
226 set(_png_gsc_message "Copying ${SRC} to ${DEST} if needed")
227 set(_png_gsc_operation "copy_if_different")
229 set(_png_gsc_message "Symlinking ${SRC} to ${DEST}")
230 set(_png_gsc_operation "create_symlink")
234 message(STATUS \"${_png_gsc_message}\")
235 execute_process(COMMAND \${CMAKE_COMMAND} -E ${_png_gsc_operation}
236 \"${SRC}\" \"${DEST}\")
240 # CREATE PKGCONFIG FILES
241 # we use the same files like ./configure, so we have to set its vars
242 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
243 set(CMAKE_INSTALL_LIBDIR lib)
244 endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
245 set(prefix ${CMAKE_INSTALL_PREFIX})
246 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
247 set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
248 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
250 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
251 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
252 _png_generate_symlink_code(PNG_PC_INSTALL_CODE
253 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
254 ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
255 install(CODE ${PNG_PC_INSTALL_CODE})
257 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
258 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
259 _png_generate_symlink_code(PNG_CONFIG_INSTALL_CODE
260 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
261 ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
262 install(CODE ${PNG_CONFIG_INSTALL_CODE})
266 set_target_properties(${PNG_LIB_NAME} PROPERTIES
267 # VERSION 15.${PNGLIB_RELEASE}.1.5.1
268 VERSION 15.${PNGLIB_RELEASE}.0
270 CLEAN_DIRECT_OUTPUT 1)
273 # MSVC doesn't use a different file extension for shared vs. static
274 # libs. We are able to change OUTPUT_NAME to remove the _static
275 # for all other platforms.
277 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
278 OUTPUT_NAME ${PNG_LIB_NAME}
279 CLEAN_DIRECT_OUTPUT 1)
283 # If CMake > 2.4.x, we set a variable used below to export
284 # targets to an export file.
285 # TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
286 if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
287 set(PNG_EXPORT_RULE EXPORT libpng)
288 elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
289 set(PNG_EXPORT_RULE EXPORT libpng)
293 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
295 install(TARGETS ${PNG_LIB_NAME}
297 RUNTIME DESTINATION bin
298 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
299 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
301 # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
303 _png_generate_symlink_code(PNG_SHARED_IMPLIB_INSTALL_CODE
304 ${PNGLIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}
305 libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
306 install(CODE ${PNG_SHARED_IMPLIB_INSTALL_CODE})
308 ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
309 DESTINATION ${CMAKE_INSTALL_LIBDIR})
313 IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
314 _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
315 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
316 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
317 install(CODE ${PNG_SHARED_INSTALL_CODE})
319 ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
320 DESTINATION ${CMAKE_INSTALL_LIBDIR})
321 ELSE(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
322 _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
323 ${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
324 libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
325 install(CODE ${PNG_SHARED_INSTALL_CODE})
327 ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
328 DESTINATION ${CMAKE_INSTALL_LIBDIR})
329 ENDIF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
334 install(TARGETS ${PNG_LIB_NAME_STATIC}
336 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
337 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
338 if(NOT WIN32 OR CYGWIN)
339 IF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
340 _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
341 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
342 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
343 install(CODE ${PNG_STATIC_INSTALL_CODE})
345 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
346 DESTINATION ${CMAKE_INSTALL_LIBDIR})
347 ELSE(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
348 _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
349 ${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
350 libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
351 install(CODE ${PNG_STATIC_INSTALL_CODE})
353 ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
354 DESTINATION ${CMAKE_INSTALL_LIBDIR})
355 ENDIF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
360 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
361 install(FILES ${libpng_public_hdrs} DESTINATION include)
362 install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME})
364 if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
365 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
366 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
369 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
372 set(PNG_MAN_DIR "share/man")
374 install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
375 install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
376 # Install pkg-config files
377 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
378 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
379 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
381 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
382 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
383 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
387 # On versions of CMake that support it, create an export file CMake
388 # users can include() to import our targets
389 if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
390 install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
393 # what's with libpng-$VER%.txt and all the extra files?
403 # to create msvc import lib for mingw compiled shared lib
404 # pexports libpng.dll > libpng.def
405 # lib /def:libpng.def /machine:x86