1 cmake_minimum_required(VERSION 2.4.3)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
4 if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
5 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
6 "Choose the type of build, options are:
7 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
17 # Copyright (C) 2007-2010 Glenn Randers-Pehrson
19 # This code is released under the libpng license.
20 # For conditions of distribution and use, see the disclaimer
21 # and license in png.h
25 set(PNGLIB_RELEASE 51)
26 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
27 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
30 find_package(ZLIB REQUIRED)
31 include_directories(${ZLIB_INCLUDE_DIR})
34 find_library(M_LIBRARY
36 PATHS /usr/lib /usr/local/lib
40 "math library 'libm' not found - floating point support disabled")
43 # not needed on windows
47 # COMMAND LINE OPTIONS
48 if(DEFINED PNG_SHARED)
49 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
51 option(PNG_SHARED "Build shared lib" ON)
53 if(DEFINED PNG_STATIC)
54 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
56 option(PNG_STATIC "Build static lib" ON)
60 option(PNG_TESTS "Build pngtest" NO)
62 option(PNG_TESTS "Build pngtest" YES)
65 option(PNG_NO_CONSOLE_IO "FIXME" YES)
66 option(PNG_NO_STDIO "FIXME" YES)
67 option(PNG_DEBUG "Build with debug output" NO)
68 option(PNGARG "FIXME" YES)
70 # PNG_CONSOLE_IO_SUPPORTED
72 # maybe needs improving, but currently I don't know when we can enable what :)
73 set(png_asm_tmp "OFF")
75 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
77 exec_program(${uname_executable}
78 ARGS --machine OUTPUT_VARIABLE uname_output)
79 if("uname_output" MATCHES "^.*i[1-9]86.*$")
81 else("uname_output" MATCHES "^.*i[1-9]86.*$")
82 set(png_asm_tmp "OFF")
83 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
84 endif(uname_executable)
86 # this env var is normally only set on win64
87 set(TEXT "ProgramFiles(x86)")
88 if("$ENV{${TEXT}}" STREQUAL "")
90 endif("$ENV{${TEXT}}" STREQUAL "")
94 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
96 # to distinguish between debug and release lib
97 set(CMAKE_DEBUG_POSTFIX "d")
123 # SOME NEEDED DEFINITIONS
125 add_definitions(-DPNG_CONFIGURE_LIBPNG)
128 add_definitions(-D_ALL_SOURCE)
132 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
135 if(PNG_SHARED OR NOT MSVC)
136 #if building msvc static this has NOT to be defined
137 add_definitions(-DZLIB_DLL)
140 add_definitions(-DLIBPNG_NO_MMX)
141 add_definitions(-DPNG_NO_MMX_CODE)
144 if(PNG_CONSOLE_IO_SUPPORTED)
145 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
148 if(PNG_NO_CONSOLE_IO)
149 add_definitions(-DPNG_NO_CONSOLE_IO)
153 add_definitions(-DPNG_NO_STDIO)
157 add_definitions(-DPNG_DEBUG)
160 if(NOT M_LIBRARY AND NOT WIN32)
161 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
164 # NOW BUILD OUR TARGET
165 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
168 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
170 # msvc does not append 'lib' - do it here to have consistent name
171 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
173 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
177 # does not work without changing name
178 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
179 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
181 # msvc does not append 'lib' - do it here to have consistent name
182 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
187 if(PNG_SHARED AND WIN32)
188 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
191 if(PNG_TESTS AND PNG_SHARED)
192 # does not work with msvc due to png_lib_ver issue
193 add_executable(pngtest ${pngtest_sources})
194 target_link_libraries(pngtest ${PNG_LIB_NAME})
195 add_test(pngtest pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
199 # CREATE PKGCONFIG FILES
200 # we use the same files like ./configure, so we have to set its vars
201 set(prefix ${CMAKE_INSTALL_PREFIX})
202 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
203 set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
204 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
206 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in
207 ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
208 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in
209 ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
210 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in
211 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc)
212 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in
213 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config)
217 set_target_properties(${PNG_LIB_NAME} PROPERTIES
218 # VERSION 0.${PNGLIB_RELEASE}.1.2.51
219 VERSION 0.${PNGLIB_RELEASE}.0
221 CLEAN_DIRECT_OUTPUT 1)
225 # that's uncool on win32 - it overwrites our static import lib...
226 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
227 OUTPUT_NAME ${PNG_LIB_NAME}
228 CLEAN_DIRECT_OUTPUT 1)
233 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
235 install(TARGETS ${PNG_LIB_NAME}
236 RUNTIME DESTINATION bin
237 LIBRARY DESTINATION lib
238 ARCHIVE DESTINATION lib)
241 install(TARGETS ${PNG_LIB_NAME_STATIC}
242 LIBRARY DESTINATION lib
243 ARCHIVE DESTINATION lib)
247 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
248 install(FILES png.h pngconf.h DESTINATION include)
249 install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME})
251 if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
252 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
253 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
256 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
258 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
259 install(FILES png.5 DESTINATION man/man5)
260 # Install pkg-config files
261 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
262 DESTINATION lib/pkgconfig)
263 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
265 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
266 DESTINATION lib/pkgconfig)
267 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
271 # what's with libpng.txt and all the extra files?
281 # to create msvc import lib for mingw compiled shared lib
282 # pexports libpng.dll > libpng.def
283 # lib /def:libpng.def /machine:x86