]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | project(PNG) | |
3 | ||
4 | # Copyright (C) 2007 Glenn Randers-Pehrson | |
5 | # For conditions of distribution and use, see copyright notice in png.h | |
6 | ||
7 | set(PNGLIB_MAJOR 1) | |
8 | set(PNGLIB_MINOR 2) | |
9 | set(PNGLIB_RELEASE 20) | |
10 | set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) | |
11 | set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) | |
12 | ||
13 | # needed packages | |
14 | find_package(ZLIB REQUIRED) | |
15 | if(NOT WIN32) | |
16 | find_library(M_LIBRARY | |
17 | NAMES m | |
18 | PATHS /usr/lib /usr/local/lib | |
19 | ) | |
20 | if(NOT M_LIBRARY) | |
21 | message(STATUS | |
22 | "math library 'libm' not found - floating point support disabled") | |
23 | endif(NOT M_LIBRARY) | |
24 | else(NOT WIN32) | |
25 | # not needed on windows | |
26 | set(M_LIBRARY "") | |
27 | endif(NOT WIN32) | |
28 | ||
29 | ||
30 | # COMMAND LINE OPTIONS | |
31 | option(PNG_SHARED "Build shared lib" YES) | |
32 | option(PNG_STATIC "Build static lib" YES) | |
33 | if(MINGW) | |
34 | option(PNG_TESTS "Build pngtest" NO) | |
35 | else(MINGW) | |
36 | option(PNG_TESTS "Build pngtest" YES) | |
37 | endif(MINGW) | |
38 | option(PNG_NO_CONSOLE_IO "FIXME" YES) | |
39 | option(PNG_NO_STDIO "FIXME" YES) | |
40 | option(PNG_DEBUG "Build with debug output" YES) | |
41 | option(PNGARG "FIXME" YES) | |
42 | #TODO: | |
43 | # PNG_CONSOLE_IO_SUPPORTED | |
44 | ||
45 | # maybe needs improving, but currently I don't know when we can enable what :) | |
46 | set(png_asm_tmp "OFF") | |
47 | if(NOT WIN32) | |
48 | find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin) | |
49 | if(uname_executable) | |
50 | EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output) | |
51 | if("uname_output" MATCHES "^.*i[1-9]86.*$") | |
52 | set(png_asm_tmp "ON") | |
53 | else("uname_output" MATCHES "^.*i[1-9]86.*$") | |
54 | set(png_asm_tmp "OFF") | |
55 | endif("uname_output" MATCHES "^.*i[1-9]86.*$") | |
56 | endif(uname_executable) | |
57 | else(NOT WIN32) | |
58 | # this env var is normally only set on win64 | |
59 | SET(TEXT "ProgramFiles(x86)") | |
60 | if("$ENV{${TEXT}}" STREQUAL "") | |
61 | set(png_asm_tmp "ON") | |
62 | endif("$ENV{${TEXT}}" STREQUAL "") | |
63 | endif(NOT WIN32) | |
64 | ||
65 | # SET LIBNAME | |
66 | # msvc does not append 'lib' - do it here to have consistent name | |
67 | if(MSVC) | |
68 | set(PNG_LIB_NAME lib) | |
69 | endif(MSVC) | |
70 | set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR}) | |
71 | ||
72 | # to distinguish between debug and release lib | |
73 | set(CMAKE_DEBUG_POSTFIX "d") | |
74 | ||
75 | ||
76 | # OUR SOURCES | |
77 | set(libpng_sources | |
78 | png.h | |
79 | pngconf.h | |
80 | png.c | |
81 | pngerror.c | |
82 | pngget.c | |
83 | pngmem.c | |
84 | pngpread.c | |
85 | pngread.c | |
86 | pngrio.c | |
87 | pngrtran.c | |
88 | pngrutil.c | |
89 | pngset.c | |
90 | pngtrans.c | |
91 | pngwio.c | |
92 | pngwrite.c | |
93 | pngwtran.c | |
94 | pngwutil.c | |
95 | ) | |
96 | set(pngtest_sources | |
97 | pngtest.c | |
98 | ) | |
99 | # SOME NEEDED DEFINITIONS | |
100 | if(MSVC) | |
101 | add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE) | |
102 | endif(MSVC) | |
103 | ||
104 | add_definitions(-DZLIB_DLL) | |
105 | ||
106 | add_definitions(-DLIBPNG_NO_MMX) | |
107 | add_definitions(-DPNG_NO_MMX_CODE) | |
108 | ||
109 | if(PNG_CONSOLE_IO_SUPPORTED) | |
110 | add_definitions(-DPNG_CONSOLE_IO_SUPPORTED) | |
111 | endif(PNG_CONSOLE_IO_SUPPORTED) | |
112 | ||
113 | if(PNG_NO_CONSOLE_IO) | |
114 | add_definitions(-DPNG_NO_CONSOLE_IO) | |
115 | endif(PNG_NO_CONSOLE_IO) | |
116 | ||
117 | if(PNG_NO_STDIO) | |
118 | add_definitions(-DPNG_NO_STDIO) | |
119 | endif(PNG_NO_STDIO) | |
120 | ||
121 | if(PNG_DEBUG) | |
122 | add_definitions(-DPNG_DEBUG) | |
123 | endif(PNG_DEBUG) | |
124 | ||
125 | if(NOT M_LIBRARY AND NOT WIN32) | |
126 | add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED) | |
127 | endif(NOT M_LIBRARY AND NOT WIN32) | |
128 | ||
129 | # NOW BUILD OUR TARGET | |
130 | include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) | |
131 | ||
132 | if(PNG_SHARED) | |
133 | add_library(${PNG_LIB_NAME} SHARED ${libpng_sources}) | |
134 | target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY}) | |
135 | endif(PNG_SHARED) | |
136 | if(PNG_STATIC) | |
137 | # does not work without changing name | |
138 | set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) | |
139 | add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) | |
140 | endif(PNG_STATIC) | |
141 | ||
142 | if(PNG_SHARED AND WIN32) | |
143 | set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) | |
144 | endif(PNG_SHARED AND WIN32) | |
145 | ||
146 | if(PNG_TESTS) | |
147 | # does not work with msvc due to png_lib_ver issue | |
148 | add_executable(pngtest ${pngtest_sources}) | |
149 | target_link_libraries(pngtest ${PNG_LIB_NAME}) | |
150 | # add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png) | |
151 | endif(PNG_TESTS) | |
152 | ||
153 | ||
154 | # CREATE PKGCONFIG FILES | |
155 | # we use the same files like ./configure, so we have to set its vars | |
156 | set(prefix ${CMAKE_INSTALL_PREFIX}) | |
157 | set(exec_prefix ${CMAKE_INSTALL_PREFIX}) | |
158 | set(libdir ${CMAKE_INSTALL_PREFIX}/lib) | |
159 | set(includedir ${CMAKE_INSTALL_PREFIX}/include) | |
160 | ||
161 | configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in | |
162 | ${PNG_BINARY_DIR}/libpng.pc) | |
163 | configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in | |
164 | ${PNG_BINARY_DIR}/libpng-config) | |
165 | configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in | |
166 | ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc) | |
167 | configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in | |
168 | ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config) | |
169 | ||
170 | # SET UP LINKS | |
171 | set_target_properties(${PNG_LIB_NAME} PROPERTIES | |
172 | # VERSION 0.${PNGLIB_RELEASE}.1.2.20 | |
173 | VERSION 0.${PNGLIB_RELEASE}.0 | |
174 | SOVERSION 0 | |
175 | CLEAN_DIRECT_OUTPUT 1) | |
176 | if(NOT WIN32) | |
177 | # that's uncool on win32 - it overwrites our static import lib... | |
178 | set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES | |
179 | OUTPUT_NAME ${PNG_LIB_NAME} | |
180 | CLEAN_DIRECT_OUTPUT 1) | |
181 | endif(NOT WIN32) | |
182 | # INSTALL | |
183 | install_targets(/lib ${PNG_LIB_NAME}) | |
184 | if(PNG_STATIC) | |
185 | install_targets(/lib ${PNG_LIB_NAME_STATIC}) | |
186 | endif(PNG_STATIC) | |
187 | ||
188 | install(FILES png.h pngconf.h DESTINATION include) | |
189 | install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME}) | |
190 | install(FILES libpng.3 libpngpf.3 DESTINATION man/man3) | |
191 | install(FILES png.5 DESTINATION man/man5) | |
192 | install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig) | |
193 | install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin) | |
194 | install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig) | |
195 | install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) | |
196 | ||
197 | # what's with libpng.txt and all the extra files? | |
198 | ||
199 | ||
200 | # UNINSTALL | |
201 | # do we need this? | |
202 | ||
203 | ||
204 | # DIST | |
205 | # do we need this? | |
206 | ||
207 | # to create msvc import lib for mingw compiled shared lib | |
208 | # pexports libpng.dll > libpng.def | |
209 | # lib /def:libpng.def /machine:x86 | |
210 |