|
1 cmake_minimum_required(VERSION 2.4.3) |
|
2 if(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.") |
|
6 endif() |
|
7 |
|
8 project(PNG C) |
|
9 enable_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 |
|
17 set(PNGLIB_MAJOR 1) |
|
18 set(PNGLIB_MINOR 4) |
|
19 set(PNGLIB_RELEASE 0) |
|
20 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
|
21 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) |
|
22 |
|
23 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) |
|
24 |
|
25 # needed packages |
|
26 find_package(ZLIB REQUIRED) |
|
27 include_directories(${ZLIB_INCLUDE_DIR}) |
|
28 |
|
29 if(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() |
|
38 else() |
|
39 # not needed on windows |
|
40 set(M_LIBRARY "") |
|
41 endif() |
|
42 |
|
43 # COMMAND LINE OPTIONS |
|
44 if(DEFINED PNG_SHARED) |
|
45 option(PNG_SHARED "Build shared lib" ${PNG_SHARED}) |
|
46 else() |
|
47 option(PNG_SHARED "Build shared lib" ON) |
|
48 endif() |
|
49 if(DEFINED PNG_STATIC) |
|
50 option(PNG_STATIC "Build static lib" ${PNG_STATIC}) |
|
51 else() |
|
52 option(PNG_STATIC "Build static lib" ON) |
|
53 endif() |
|
54 |
|
55 if(MINGW) |
|
56 option(PNG_TESTS "Build pngtest" NO) |
|
57 else(MINGW) |
|
58 option(PNG_TESTS "Build pngtest" YES) |
|
59 endif(MINGW) |
|
60 |
|
61 option(PNG_NO_CONSOLE_IO "FIXME" YES) |
|
62 option(PNG_NO_STDIO "FIXME" YES) |
|
63 option(PNG_DEBUG "Build with debug output" NO) |
|
64 option(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 :) |
|
69 set(png_asm_tmp "OFF") |
|
70 if(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) |
|
80 else() |
|
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 "") |
|
86 endif() |
|
87 |
|
88 # SET LIBNAME |
|
89 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
|
90 |
|
91 # to distinguish between debug and release lib |
|
92 set(CMAKE_DEBUG_POSTFIX "d") |
|
93 |
|
94 |
|
95 # OUR SOURCES |
|
96 set(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 ) |
|
116 set(pngtest_sources |
|
117 pngtest.c |
|
118 ) |
|
119 # SOME NEEDED DEFINITIONS |
|
120 |
|
121 add_definitions(-DPNG_CONFIGURE_LIBPNG) |
|
122 |
|
123 if(MSVC) |
|
124 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE) |
|
125 endif(MSVC) |
|
126 |
|
127 if(PNG_SHARED OR NOT MSVC) |
|
128 #if building msvc static this has NOT to be defined |
|
129 add_definitions(-DZLIB_DLL) |
|
130 endif() |
|
131 |
|
132 if(PNG_CONSOLE_IO_SUPPORTED) |
|
133 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED) |
|
134 endif() |
|
135 |
|
136 if(PNG_NO_CONSOLE_IO) |
|
137 add_definitions(-DPNG_NO_CONSOLE_IO) |
|
138 endif() |
|
139 |
|
140 if(PNG_NO_STDIO) |
|
141 add_definitions(-DPNG_NO_STDIO) |
|
142 endif() |
|
143 |
|
144 if(PNG_DEBUG) |
|
145 add_definitions(-DPNG_DEBUG) |
|
146 endif() |
|
147 |
|
148 if(NOT M_LIBRARY AND NOT WIN32) |
|
149 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED) |
|
150 endif() |
|
151 |
|
152 # NOW BUILD OUR TARGET |
|
153 include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) |
|
154 |
|
155 if(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}) |
|
162 endif() |
|
163 |
|
164 if(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() |
|
172 endif() |
|
173 |
|
174 |
|
175 if(PNG_SHARED AND WIN32) |
|
176 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) |
|
177 endif() |
|
178 |
|
179 if(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) |
|
184 endif() |
|
185 |
|
186 |
|
187 # CREATE PKGCONFIG FILES |
|
188 # we use the same files like ./configure, so we have to set its vars |
|
189 set(prefix ${CMAKE_INSTALL_PREFIX}) |
|
190 set(exec_prefix ${CMAKE_INSTALL_PREFIX}) |
|
191 set(libdir ${CMAKE_INSTALL_PREFIX}/lib) |
|
192 set(includedir ${CMAKE_INSTALL_PREFIX}/include) |
|
193 |
|
194 configure_file(${PNG_SOURCE_DIR}/libpng.pc.in |
|
195 ${PNG_BINARY_DIR}/libpng.pc) |
|
196 configure_file(${PNG_SOURCE_DIR}/libpng-config.in |
|
197 ${PNG_BINARY_DIR}/libpng-config) |
|
198 configure_file(${PNG_SOURCE_DIR}/libpng.pc.in |
|
199 ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc) |
|
200 configure_file(${PNG_SOURCE_DIR}/libpng-config.in |
|
201 ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config) |
|
202 |
|
203 # SET UP LINKS |
|
204 if(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) |
|
210 endif() |
|
211 if(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() |
|
218 endif() |
|
219 |
|
220 # INSTALL |
|
221 if(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() |
|
233 endif() |
|
234 |
|
235 if(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}) |
|
238 endif() |
|
239 if(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) |
|
242 endif() |
|
243 if(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) |
|
250 endif() |
|
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 |