blob: c90965515faaa63481200a8b6ed3a0a43111dcd6 [file] [log] [blame]
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -05001project(PNG C)
2cmake_minimum_required(VERSION 2.4.3)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -06003
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05004# Copyright (C) 2007 Glenn Randers-Pehrson
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -05005
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05006# This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -05007# For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05008# and license in png.h
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -06009
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050010set(PNGLIB_MAJOR 1)
11set(PNGLIB_MINOR 4)
12set(PNGLIB_RELEASE 0)
13set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
14set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060015
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050016set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
17
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060018# needed packages
19find_package(ZLIB REQUIRED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050020include_directories(${ZLIB_INCLUDE_DIR})
21
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050022if(NOT WIN32)
23 find_library(M_LIBRARY
24 NAMES m
25 PATHS /usr/lib /usr/local/lib
26 )
27 if(NOT M_LIBRARY)
28 message(STATUS
29 "math library 'libm' not found - floating point support disabled")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050030 endif()
31else()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050032 # not needed on windows
33 set(M_LIBRARY "")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050034endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060035
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050036# COMMAND LINE OPTIONS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050037if(DEFINED PNG_SHARED)
38 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
39else()
40 option(PNG_SHARED "Build shared lib" ON)
41endif()
42if(DEFINED PNG_STATIC)
43 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
44else()
45 option(PNG_STATIC "Build static lib" ON)
46endif()
47
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050048if(MINGW)
49 option(PNG_TESTS "Build pngtest" NO)
50else(MINGW)
51 option(PNG_TESTS "Build pngtest" YES)
52endif(MINGW)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050053
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050054option(PNG_NO_CONSOLE_IO "FIXME" YES)
55option(PNG_NO_STDIO "FIXME" YES)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050056option(PNG_DEBUG "Build with debug output" NO)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050057option(PNGARG "FIXME" YES)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060058#TODO:
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060059# PNG_CONSOLE_IO_SUPPORTED
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060060
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050061# maybe needs improving, but currently I don't know when we can enable what :)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060062set(png_asm_tmp "OFF")
63if(NOT WIN32)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050064 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
65 if(uname_executable)
66 EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
67 if("uname_output" MATCHES "^.*i[1-9]86.*$")
68 set(png_asm_tmp "ON")
69 else("uname_output" MATCHES "^.*i[1-9]86.*$")
70 set(png_asm_tmp "OFF")
71 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
72 endif(uname_executable)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050073else()
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050074 # this env var is normally only set on win64
75 SET(TEXT "ProgramFiles(x86)")
76 if("$ENV{${TEXT}}" STREQUAL "")
77 set(png_asm_tmp "ON")
78 endif("$ENV{${TEXT}}" STREQUAL "")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050079endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060080
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050081# SET LIBNAME
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050082set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060083
84# to distinguish between debug and release lib
85set(CMAKE_DEBUG_POSTFIX "d")
86
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060087
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050088# OUR SOURCES
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060089set(libpng_sources
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050090 png.h
91 pngconf.h
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050092 pngpriv.h
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050093 png.c
94 pngerror.c
95 pngget.c
96 pngmem.c
97 pngpread.c
98 pngread.c
99 pngrio.c
100 pngrtran.c
101 pngrutil.c
102 pngset.c
103 pngtrans.c
104 pngwio.c
105 pngwrite.c
106 pngwtran.c
107 pngwutil.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600108)
109set(pngtest_sources
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500110 pngtest.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600111)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500112# SOME NEEDED DEFINITIONS
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600113if(MSVC)
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500114 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600115endif(MSVC)
116
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500117if(PNG_SHARED OR NOT MSVC)
118 #if building msvc static this has NOT do be defined
119 add_definitions(-DZLIB_DLL)
120endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600121
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500122if(PNG_CONSOLE_IO_SUPPORTED)
123 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500124endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500125
126if(PNG_NO_CONSOLE_IO)
127 add_definitions(-DPNG_NO_CONSOLE_IO)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500128endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500129
130if(PNG_NO_STDIO)
131 add_definitions(-DPNG_NO_STDIO)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500132endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500133
134if(PNG_DEBUG)
135 add_definitions(-DPNG_DEBUG)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500136endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500137
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500138if(NOT M_LIBRARY AND NOT WIN32)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500139 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500140endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500141
142# NOW BUILD OUR TARGET
143include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600144
145if(PNG_SHARED)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500146 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500147 if(MSVC)
148 # msvc does not append 'lib' - do it here to have consistent name
149 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
150 endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500151 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500152endif()
153
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500154if(PNG_STATIC)
155# does not work without changing name
156 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
157 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500158 if(MSVC)
159 # msvc does not append 'lib' - do it here to have consistent name
160 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
161 endif()
162endif()
163
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600164
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600165if(PNG_SHARED AND WIN32)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500166 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500167endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600168
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500169if(PNG_TESTS AND PNG_SHARED)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600170# does not work with msvc due to png_lib_ver issue
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500171 add_executable(pngtest ${pngtest_sources})
172 target_link_libraries(pngtest ${PNG_LIB_NAME})
173# add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500174endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600175
176
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500177# CREATE PKGCONFIG FILES
178# we use the same files like ./configure, so we have to set its vars
179set(prefix ${CMAKE_INSTALL_PREFIX})
180set(exec_prefix ${CMAKE_INSTALL_PREFIX})
181set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
182set(includedir ${CMAKE_INSTALL_PREFIX}/include)
183
184configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
185 ${PNG_BINARY_DIR}/libpng.pc)
186configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
187 ${PNG_BINARY_DIR}/libpng-config)
188configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
189 ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
190configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
191 ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
192
193# SET UP LINKS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500194if(PNG_SHARED)
195 set_target_properties(${PNG_LIB_NAME} PROPERTIES
Glenn Randers-Pehrsonb7e4c1c2009-08-26 12:00:13 -0500196# VERSION 14.${PNGLIB_RELEASE}.1.4.0beta77
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500197 VERSION 14.${PNGLIB_RELEASE}.0
198 SOVERSION 14
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500199 CLEAN_DIRECT_OUTPUT 1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500200endif()
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500201if(PNG_STATIC)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500202 if(NOT WIN32)
203 # that's uncool on win32 - it overwrites our static import lib...
204 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
205 OUTPUT_NAME ${PNG_LIB_NAME}
206 CLEAN_DIRECT_OUTPUT 1)
207 endif()
208endif()
209
210# INSTALL
211if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
212 if(PNG_SHARED)
213 install(TARGETS ${PNG_LIB_NAME}
214 RUNTIME DESTINATION bin
215 LIBRARY DESTINATION lib
216 ARCHIVE DESTINATION lib)
217 endif()
218 if(PNG_STATIC)
219 install(TARGETS ${PNG_LIB_NAME_STATIC}
220 LIBRARY DESTINATION lib
221 ARCHIVE DESTINATION lib)
222 endif()
223endif()
224
225if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500226install(FILES png.h pngconf.h pngpriv.h DESTINATION include)
227install(FILES png.h pngconf.h pngpriv.h DESTINATION include/${PNGLIB_NAME})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500228endif()
229if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
230 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
231 install(FILES png.5 DESTINATION man/man5)
232 install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig)
233 install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin)
234 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig)
235 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
236endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500237
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600238# what's with libpng.txt and all the extra files?
239
240
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500241# UNINSTALL
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600242# do we need this?
243
244
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500245# DIST
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600246# do we need this?
247
248# to create msvc import lib for mingw compiled shared lib
249# pexports libpng.dll > libpng.def
250# lib /def:libpng.def /machine:x86
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500251