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

Last change on this file since 729 was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

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