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
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")
124 # SOME NEEDED DEFINITIONS
126 add_definitions(-DPNG_CONFIGURE_LIBPNG)
129 add_definitions(-D_ALL_SOURCE)
133 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
136 if(PNG_SHARED OR NOT MSVC)
137 #if building msvc static this has NOT to be defined
138 add_definitions(-DZLIB_DLL)
142 if(PNG_CONSOLE_IO_SUPPORTED)
143 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
146 if(PNG_NO_CONSOLE_IO)
147 add_definitions(-DPNG_NO_CONSOLE_IO)
151 add_definitions(-DPNG_NO_STDIO)
155 add_definitions(-DPNG_DEBUG)
158 if(NOT M_LIBRARY AND NOT WIN32)
159 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
162 # NOW BUILD OUR TARGET
163 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
166 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
168 # msvc does not append 'lib' - do it here to have consistent name
169 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
171 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
175 # does not work without changing name
176 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
177 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
179 # msvc does not append 'lib' - do it here to have consistent name
180 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
185 if(PNG_SHARED AND WIN32)
186 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
189 if(PNG_TESTS AND PNG_SHARED)
190 # does not work with msvc due to png_lib_ver issue
191 add_executable(pngtest ${pngtest_sources})
192 target_link_libraries(pngtest ${PNG_LIB_NAME})
193 add_test(pngtest pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
197 # CREATE PKGCONFIG FILES
198 # we use the same files like ./configure, so we have to set its vars
199 set(prefix ${CMAKE_INSTALL_PREFIX})
200 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
201 set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
202 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
204 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
205 ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
206 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
207 ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
208 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
209 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc)
210 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
211 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config)
215 set_target_properties(${PNG_LIB_NAME} PROPERTIES
216 # VERSION 14.${PNGLIB_RELEASE}.1.4.1
217 VERSION 14.${PNGLIB_RELEASE}.0
219 CLEAN_DIRECT_OUTPUT 1)
223 # that's uncool on win32 - it overwrites our static import lib...
224 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
225 OUTPUT_NAME ${PNG_LIB_NAME}
226 CLEAN_DIRECT_OUTPUT 1)
231 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
233 install(TARGETS ${PNG_LIB_NAME}
234 RUNTIME DESTINATION bin
235 LIBRARY DESTINATION lib
236 ARCHIVE DESTINATION lib)
239 install(TARGETS ${PNG_LIB_NAME_STATIC}
240 LIBRARY DESTINATION lib
241 ARCHIVE DESTINATION lib)
245 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
246 install(FILES png.h pngconf.h DESTINATION include)
247 install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME})
249 if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
250 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
251 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
254 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
256 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
257 install(FILES png.5 DESTINATION man/man5)
258 # Install pkg-config files
259 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
260 DESTINATION lib/pkgconfig)
261 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
263 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
264 DESTINATION lib/pkgconfig)
265 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
269 # what's with libpng.txt and all the extra files?
279 # to create msvc import lib for mingw compiled shared lib
280 # pexports libpng.dll > libpng.def
281 # lib /def:libpng.def /machine:x86