source: trunk/src/3rdparty/libpng/CMakeLists.txt@ 890

Last change on this file since 890 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.0 KB
Line 
1cmake_minimum_required(VERSION 2.4.3)
2if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
3 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of
4 build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
5 Release RelWithDebInfo MinSizeRel.")
6endif()
7
8project(PNG C)
9enable_testing()
10
11# Copyright (C) 2007-2010 Glenn Randers-Pehrson
12
13# This code is released under the libpng license.
14# For conditions of distribution and use, see the disclaimer
15# and license in png.h
16
17set(PNGLIB_MAJOR 1)
18set(PNGLIB_MINOR 4)
19set(PNGLIB_RELEASE 0)
20set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
21set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
22
23set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
24
25# needed packages
26find_package(ZLIB REQUIRED)
27include_directories(${ZLIB_INCLUDE_DIR})
28
29if(NOT WIN32)
30 find_library(M_LIBRARY
31 NAMES m
32 PATHS /usr/lib /usr/local/lib
33 )
34 if(NOT M_LIBRARY)
35 message(STATUS
36 "math library 'libm' not found - floating point support disabled")
37 endif()
38else()
39 # not needed on windows
40 set(M_LIBRARY "")
41endif()
42
43# COMMAND LINE OPTIONS
44if(DEFINED PNG_SHARED)
45 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
46else()
47 option(PNG_SHARED "Build shared lib" ON)
48endif()
49if(DEFINED PNG_STATIC)
50 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
51else()
52 option(PNG_STATIC "Build static lib" ON)
53endif()
54
55if(MINGW)
56 option(PNG_TESTS "Build pngtest" NO)
57else(MINGW)
58 option(PNG_TESTS "Build pngtest" YES)
59endif(MINGW)
60
61option(PNG_NO_CONSOLE_IO "FIXME" YES)
62option(PNG_NO_STDIO "FIXME" YES)
63option(PNG_DEBUG "Build with debug output" NO)
64option(PNGARG "FIXME" YES)
65#TODO:
66# PNG_CONSOLE_IO_SUPPORTED
67
68# maybe needs improving, but currently I don't know when we can enable what :)
69set(png_asm_tmp "OFF")
70if(NOT WIN32)
71 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
72 if(uname_executable)
73 EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
74 if("uname_output" MATCHES "^.*i[1-9]86.*$")
75 set(png_asm_tmp "ON")
76 else("uname_output" MATCHES "^.*i[1-9]86.*$")
77 set(png_asm_tmp "OFF")
78 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
79 endif(uname_executable)
80else()
81 # this env var is normally only set on win64
82 SET(TEXT "ProgramFiles(x86)")
83 if("$ENV{${TEXT}}" STREQUAL "")
84 set(png_asm_tmp "ON")
85 endif("$ENV{${TEXT}}" STREQUAL "")
86endif()
87
88# SET LIBNAME
89set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
90
91# to distinguish between debug and release lib
92set(CMAKE_DEBUG_POSTFIX "d")
93
94
95# OUR SOURCES
96set(libpng_sources
97 png.h
98 pngconf.h
99 pngpriv.h
100 png.c
101 pngerror.c
102 pngget.c
103 pngmem.c
104 pngpread.c
105 pngread.c
106 pngrio.c
107 pngrtran.c
108 pngrutil.c
109 pngset.c
110 pngtrans.c
111 pngwio.c
112 pngwrite.c
113 pngwtran.c
114 pngwutil.c
115)
116set(pngtest_sources
117 pngtest.c
118)
119# SOME NEEDED DEFINITIONS
120
121add_definitions(-DPNG_CONFIGURE_LIBPNG)
122
123if(MSVC)
124 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
125endif(MSVC)
126
127if(PNG_SHARED OR NOT MSVC)
128 #if building msvc static this has NOT to be defined
129 add_definitions(-DZLIB_DLL)
130endif()
131
132if(PNG_CONSOLE_IO_SUPPORTED)
133 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
134endif()
135
136if(PNG_NO_CONSOLE_IO)
137 add_definitions(-DPNG_NO_CONSOLE_IO)
138endif()
139
140if(PNG_NO_STDIO)
141 add_definitions(-DPNG_NO_STDIO)
142endif()
143
144if(PNG_DEBUG)
145 add_definitions(-DPNG_DEBUG)
146endif()
147
148if(NOT M_LIBRARY AND NOT WIN32)
149 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
150endif()
151
152# NOW BUILD OUR TARGET
153include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
154
155if(PNG_SHARED)
156 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
157 if(MSVC)
158 # msvc does not append 'lib' - do it here to have consistent name
159 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
160 endif()
161 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
162endif()
163
164if(PNG_STATIC)
165# does not work without changing name
166 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
167 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
168 if(MSVC)
169 # msvc does not append 'lib' - do it here to have consistent name
170 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
171 endif()
172endif()
173
174
175if(PNG_SHARED AND WIN32)
176 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
177endif()
178
179if(PNG_TESTS AND PNG_SHARED)
180# does not work with msvc due to png_lib_ver issue
181 add_executable(pngtest ${pngtest_sources})
182 target_link_libraries(pngtest ${PNG_LIB_NAME})
183 add_test(pngtest pngtest ${PNG_SOURCE_DIR}/pngtest.png)
184endif()
185
186
187# CREATE PKGCONFIG FILES
188# we use the same files like ./configure, so we have to set its vars
189set(prefix ${CMAKE_INSTALL_PREFIX})
190set(exec_prefix ${CMAKE_INSTALL_PREFIX})
191set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
192set(includedir ${CMAKE_INSTALL_PREFIX}/include)
193
194configure_file(${PNG_SOURCE_DIR}/libpng.pc.in
195 ${PNG_BINARY_DIR}/libpng.pc)
196configure_file(${PNG_SOURCE_DIR}/libpng-config.in
197 ${PNG_BINARY_DIR}/libpng-config)
198configure_file(${PNG_SOURCE_DIR}/libpng.pc.in
199 ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
200configure_file(${PNG_SOURCE_DIR}/libpng-config.in
201 ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
202
203# SET UP LINKS
204if(PNG_SHARED)
205 set_target_properties(${PNG_LIB_NAME} PROPERTIES
206# VERSION 14.${PNGLIB_RELEASE}.1.4.0
207 VERSION 14.${PNGLIB_RELEASE}.0
208 SOVERSION 14
209 CLEAN_DIRECT_OUTPUT 1)
210endif()
211if(PNG_STATIC)
212 if(NOT WIN32)
213 # that's uncool on win32 - it overwrites our static import lib...
214 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
215 OUTPUT_NAME ${PNG_LIB_NAME}
216 CLEAN_DIRECT_OUTPUT 1)
217 endif()
218endif()
219
220# INSTALL
221if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
222 if(PNG_SHARED)
223 install(TARGETS ${PNG_LIB_NAME}
224 RUNTIME DESTINATION bin
225 LIBRARY DESTINATION lib
226 ARCHIVE DESTINATION lib)
227 endif()
228 if(PNG_STATIC)
229 install(TARGETS ${PNG_LIB_NAME_STATIC}
230 LIBRARY DESTINATION lib
231 ARCHIVE DESTINATION lib)
232 endif()
233endif()
234
235if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
236 install(FILES png.h pngconf.h pngpriv.h DESTINATION include)
237 install(FILES png.h pngconf.h pngpriv.h DESTINATION include/${PNGLIB_NAME})
238endif()
239if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
240 install(PROGRAMS ${PNG_BINARY_DIR}/libpng-config DESTINATION bin)
241 install(PROGRAMS ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
242endif()
243if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
244 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
245 install(FILES png.5 DESTINATION man/man5)
246 install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig)
247 install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin)
248 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig)
249 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
250endif()
251
252# what's with libpng.txt and all the extra files?
253
254
255# UNINSTALL
256# do we need this?
257
258
259# DIST
260# do we need this?
261
262# to create msvc import lib for mingw compiled shared lib
263# pexports libpng.dll > libpng.def
264# lib /def:libpng.def /machine:x86
265
Note: See TracBrowser for help on using the repository browser.