blob: 881fe7cea33f56eab3813d23d752939663350298 [file] [log] [blame]
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -05001cmake_minimum_required(VERSION 2.4.3)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06002set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
3
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -05004if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005 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)
8 Debug
9 Release
10 RelWithDebInfo
11 MinSizeRel.")
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -050012endif()
13
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060014project(libpng C)
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -050015enable_testing()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060016
Glenn Randers-Pehrsonf81b50b2009-12-29 16:50:15 -060017# Copyright (C) 2007-2010 Glenn Randers-Pehrson
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -050018
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -050019# This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -050020# For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -050021# and license in png.h
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060022
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050023set(PNGLIB_MAJOR 1)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060024set(PNGLIB_MINOR 5)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050025set(PNGLIB_RELEASE 0)
26set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
27set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060028
29# needed packages
30find_package(ZLIB REQUIRED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050031include_directories(${ZLIB_INCLUDE_DIR})
32
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050033if(NOT WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060034 find_library(M_LIBRARY
35 NAMES m
36 PATHS /usr/lib /usr/local/lib
37 )
38 if(NOT M_LIBRARY)
39 message(STATUS
40 "math library 'libm' not found - floating point support disabled")
41 endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050042else()
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060043 # not needed on windows
44 set(M_LIBRARY "")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050045endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060046
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050047# COMMAND LINE OPTIONS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050048if(DEFINED PNG_SHARED)
49 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
50else()
51 option(PNG_SHARED "Build shared lib" ON)
52endif()
53if(DEFINED PNG_STATIC)
54 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
55else()
56 option(PNG_STATIC "Build static lib" ON)
57endif()
58
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050059if(MINGW)
60 option(PNG_TESTS "Build pngtest" NO)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060061else()
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050062 option(PNG_TESTS "Build pngtest" YES)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060063endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050064
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050065option(PNG_NO_CONSOLE_IO "FIXME" YES)
66option(PNG_NO_STDIO "FIXME" YES)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050067option(PNG_DEBUG "Build with debug output" NO)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050068option(PNGARG "FIXME" YES)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060069#TODO:
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060070# PNG_CONSOLE_IO_SUPPORTED
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060071
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050072# maybe needs improving, but currently I don't know when we can enable what :)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060073set(png_asm_tmp "OFF")
74if(NOT WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060075 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
76 if(uname_executable)
77 exec_program(${uname_executable}
78 ARGS --machine OUTPUT_VARIABLE uname_output)
79 if("uname_output" MATCHES "^.*i[1-9]86.*$")
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050080 set(png_asm_tmp "ON")
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060081 else("uname_output" MATCHES "^.*i[1-9]86.*$")
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050082 set(png_asm_tmp "OFF")
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060083 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
84 endif(uname_executable)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050085else()
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060086 # this env var is normally only set on win64
87 set(TEXT "ProgramFiles(x86)")
88 if("$ENV{${TEXT}}" STREQUAL "")
89 set(png_asm_tmp "ON")
90 endif("$ENV{${TEXT}}" STREQUAL "")
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050091endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060092
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050093# SET LIBNAME
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -050094set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060095
96# to distinguish between debug and release lib
97set(CMAKE_DEBUG_POSTFIX "d")
98
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060099
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500100# OUR SOURCES
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600101set(libpng_sources
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600102 png.h
103 pngconf.h
Glenn Randers-Pehrsond00bbb22010-03-14 09:15:49 -0500104 pngpriv.h
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600105 png.c
106 pngerror.c
107 pngget.c
108 pngmem.c
109 pngpread.c
110 pngread.c
111 pngrio.c
112 pngrtran.c
113 pngrutil.c
114 pngset.c
115 pngtrans.c
116 pngwio.c
117 pngwrite.c
118 pngwtran.c
119 pngwutil.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600120)
121set(pngtest_sources
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600122 pngtest.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600123)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500124# SOME NEEDED DEFINITIONS
Glenn Randers-Pehrson69b0bc02009-11-07 12:02:48 -0600125
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600126if(MSVC)
Glenn Randers-Pehrsond00bbb22010-03-14 09:15:49 -0500127 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600128endif(MSVC)
129
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500130if(PNG_SHARED OR NOT MSVC)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600131 #if building msvc static this has NOT to be defined
132 add_definitions(-DZLIB_DLL)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500133endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600134
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600135
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500136if(PNG_CONSOLE_IO_SUPPORTED)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600137 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500138endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500139
140if(PNG_NO_CONSOLE_IO)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600141 add_definitions(-DPNG_NO_CONSOLE_IO)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500142endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500143
144if(PNG_NO_STDIO)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600145 add_definitions(-DPNG_NO_STDIO)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500146endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500147
148if(PNG_DEBUG)
Glenn Randers-Pehrsond00bbb22010-03-14 09:15:49 -0500149 add_definitions(-DPNG_DEBUG=1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500150endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500151
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500152if(NOT M_LIBRARY AND NOT WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600153 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500154endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500155
156# NOW BUILD OUR TARGET
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600157include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600158
159if(PNG_SHARED)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600160 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
161 if(MSVC)
162 # msvc does not append 'lib' - do it here to have consistent name
163 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
164 endif()
165 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500166endif()
167
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500168if(PNG_STATIC)
169# does not work without changing name
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600170 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
171 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
172 if(MSVC)
173 # msvc does not append 'lib' - do it here to have consistent name
174 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
175 endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500176endif()
177
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600178
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600179if(PNG_SHARED AND WIN32)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600180 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500181endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600182
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500183if(PNG_TESTS AND PNG_SHARED)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600184 # does not work with msvc due to png_lib_ver issue
185 add_executable(pngtest ${pngtest_sources})
186 target_link_libraries(pngtest ${PNG_LIB_NAME})
187 add_test(pngtest pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500188endif()
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600189
190
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500191# CREATE PKGCONFIG FILES
192# we use the same files like ./configure, so we have to set its vars
193set(prefix ${CMAKE_INSTALL_PREFIX})
194set(exec_prefix ${CMAKE_INSTALL_PREFIX})
195set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
196set(includedir ${CMAKE_INSTALL_PREFIX}/include)
197
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600198configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
199 ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
200configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
201 ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
202configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
203 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc)
204configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
205 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500206
207# SET UP LINKS
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500208if(PNG_SHARED)
209 set_target_properties(${PNG_LIB_NAME} PROPERTIES
Glenn Randers-Pehrson18b897d2010-04-24 13:03:14 -0500210# VERSION 15.${PNGLIB_RELEASE}.1.5.0beta19
Glenn Randers-Pehrsonf1eb9182010-02-08 15:36:41 -0600211 VERSION 15.${PNGLIB_RELEASE}.0
212 SOVERSION 15
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600213 CLEAN_DIRECT_OUTPUT 1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500214endif()
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500215if(PNG_STATIC)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500216 if(NOT WIN32)
217 # that's uncool on win32 - it overwrites our static import lib...
218 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600219 OUTPUT_NAME ${PNG_LIB_NAME}
220 CLEAN_DIRECT_OUTPUT 1)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500221 endif()
222endif()
223
224# INSTALL
225if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600226 if(PNG_SHARED)
227 install(TARGETS ${PNG_LIB_NAME}
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500228 RUNTIME DESTINATION bin
229 LIBRARY DESTINATION lib
230 ARCHIVE DESTINATION lib)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600231 endif()
232 if(PNG_STATIC)
233 install(TARGETS ${PNG_LIB_NAME_STATIC}
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500234 LIBRARY DESTINATION lib
235 ARCHIVE DESTINATION lib)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600236 endif()
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500237endif()
238
239if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600240 install(FILES png.h pngconf.h DESTINATION include)
241 install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME})
Glenn Randers-Pehrsonee35abb2009-10-30 15:42:54 -0500242endif()
243if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600244 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
245 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
246 DESTINATION bin)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500247endif()
248if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600249 # Install man pages
250 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
251 install(FILES png.5 DESTINATION man/man5)
252 # Install pkg-config files
253 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
254 DESTINATION lib/pkgconfig)
255 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
256 DESTINATION bin)
257 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
258 DESTINATION lib/pkgconfig)
259 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
260 DESTINATION bin)
Glenn Randers-Pehrson38e467e2009-08-27 15:59:40 -0500261endif()
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500262
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600263# what's with libpng.txt and all the extra files?
264
265
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500266# UNINSTALL
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600267# do we need this?
268
269
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500270# DIST
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600271# do we need this?
272
273# to create msvc import lib for mingw compiled shared lib
274# pexports libpng.dll > libpng.def
275# lib /def:libpng.def /machine:x86
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500276