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 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
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)
22 # Copyright (C) 2007-2010 Glenn Randers-Pehrson
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
31 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
32 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
35 find_package(ZLIB REQUIRED)
36 include_directories(${ZLIB_INCLUDE_DIR})
39 find_library(M_LIBRARY
41 PATHS /usr/lib /usr/local/lib
45 "math library 'libm' not found - floating point support disabled")
48 # not needed on windows
52 # COMMAND LINE OPTIONS
53 if(DEFINED PNG_SHARED)
54 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
56 option(PNG_SHARED "Build shared lib" ON)
58 if(DEFINED PNG_STATIC)
59 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
61 option(PNG_STATIC "Build static lib" ON)
65 option(PNG_TESTS "Build pngtest" NO)
67 option(PNG_TESTS "Build pngtest" YES)
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)
75 # PNG_CONSOLE_IO_SUPPORTED
77 # maybe needs improving, but currently I don't know when we can enable what :)
78 set(png_asm_tmp "OFF")
80 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
82 exec_program(${uname_executable}
83 ARGS --machine OUTPUT_VARIABLE uname_output)
84 if("uname_output" MATCHES "^.*i[1-9]86.*$")
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)
91 # this env var is normally only set on win64
92 set(TEXT "ProgramFiles(x86)")
93 if("$ENV{${TEXT}}" STREQUAL "")
95 endif("$ENV{${TEXT}}" STREQUAL "")
99 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
101 # to distinguish between debug and release lib
102 set(CMAKE_DEBUG_POSTFIX "d")
129 # SOME NEEDED DEFINITIONS
131 add_definitions(-DPNG_CONFIGURE_LIBPNG)
134 add_definitions(-D_ALL_SOURCE)
138 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
141 if(PNG_SHARED OR NOT MSVC)
142 #if building msvc static this has NOT to be defined
143 add_definitions(-DZLIB_DLL)
147 if(PNG_CONSOLE_IO_SUPPORTED)
148 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
151 if(PNG_NO_CONSOLE_IO)
152 add_definitions(-DPNG_NO_CONSOLE_IO)
156 add_definitions(-DPNG_NO_STDIO)
160 add_definitions(-DPNG_DEBUG)
163 if(NOT M_LIBRARY AND NOT WIN32)
164 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
167 # NOW BUILD OUR TARGET
168 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
171 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
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")
177 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
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})
185 # msvc does not append 'lib' - do it here to have consistent name
186 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
188 target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
192 if(PNG_SHARED AND WIN32)
193 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
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)
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")
212 set(_png_gsc_message "Symlinking ${SRC} to ${DEST}")
213 set(_png_gsc_operation "create_symlink")
217 message(STATUS \"${_png_gsc_message}\")
218 execute_process(COMMAND \${CMAKE_COMMAND} -E ${_png_gsc_operation}
219 \"${SRC}\" \"${DEST}\")
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)
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})
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})
245 set_target_properties(${PNG_LIB_NAME} PROPERTIES
246 # VERSION 14.${PNGLIB_RELEASE}.1.4.4
247 VERSION 14.${PNGLIB_RELEASE}.0
249 CLEAN_DIRECT_OUTPUT 1)
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.
256 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
257 OUTPUT_NAME ${PNG_LIB_NAME}
258 CLEAN_DIRECT_OUTPUT 1)
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)
272 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
274 install(TARGETS ${PNG_LIB_NAME}
276 RUNTIME DESTINATION bin
277 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
278 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
280 # Create a symlink for libpng.dll.a => libpng14.dll.a on 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})
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})
299 install(TARGETS ${PNG_LIB_NAME_STATIC}
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})
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})
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
322 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
325 set(PNG_MAN_DIR "share/man")
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
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
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)
346 # what's with libpng.txt and all the extra files?
356 # to create msvc import lib for mingw compiled shared lib
357 # pexports libpng.dll > libpng.def
358 # lib /def:libpng.def /machine:x86