1 | cmake_minimum_required(VERSION 3.18)
|
---|
2 |
|
---|
3 | file(STRINGS "configure.ac" CONFIGURE_AC_LINES)
|
---|
4 | foreach(line ${CONFIGURE_AC_LINES})
|
---|
5 | if(line MATCHES [[^m4_define\(\[(MAJOR_VERSION|MINOR_VERSION|MICRO_VERSION)\],[ \t]*([0-9]+)\)$]])
|
---|
6 | set(LIBXML_${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
---|
7 | elseif(line MATCHES "^(LIBXML_MAJOR_VERSION|LIBXML_MINOR_VERSION|LIBXML_MICRO_VERSION)=([0-9]+)$")
|
---|
8 | set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
---|
9 | endif()
|
---|
10 | endforeach()
|
---|
11 | set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}")
|
---|
12 |
|
---|
13 | project(libxml2 VERSION ${VERSION} LANGUAGES C)
|
---|
14 |
|
---|
15 | include(CheckCSourceCompiles)
|
---|
16 | include(CheckFunctionExists)
|
---|
17 | include(CheckIncludeFiles)
|
---|
18 | include(CheckLibraryExists)
|
---|
19 | include(CheckLinkerFlag)
|
---|
20 | include(CheckStructHasMember)
|
---|
21 | include(CheckSymbolExists)
|
---|
22 | include(CMakePackageConfigHelpers)
|
---|
23 | include(FindPkgConfig)
|
---|
24 | include(GNUInstallDirs)
|
---|
25 |
|
---|
26 | option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
---|
27 | set(LIBXML2_WITH_AUTOMATA ON)
|
---|
28 | option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON)
|
---|
29 | option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON)
|
---|
30 | option(LIBXML2_WITH_DEBUG "Add the debugging module" ON)
|
---|
31 | set(LIBXML2_WITH_EXPR ON)
|
---|
32 | option(LIBXML2_WITH_FTP "Add the FTP support" OFF)
|
---|
33 | option(LIBXML2_WITH_HTML "Add the HTML support" ON)
|
---|
34 | option(LIBXML2_WITH_HTTP "Add the HTTP support" OFF)
|
---|
35 | option(LIBXML2_WITH_ICONV "Add ICONV support" ON)
|
---|
36 | option(LIBXML2_WITH_ICU "Add ICU support" OFF)
|
---|
37 | option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON)
|
---|
38 | option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" OFF)
|
---|
39 | option(LIBXML2_WITH_LZMA "Use liblzma" OFF)
|
---|
40 | option(LIBXML2_WITH_MODULES "Add the dynamic modules support" ON)
|
---|
41 | option(LIBXML2_WITH_OUTPUT "Add the serialization support" ON)
|
---|
42 | option(LIBXML2_WITH_PATTERN "Add the xmlPattern selection interface" ON)
|
---|
43 | option(LIBXML2_WITH_PROGRAMS "Build programs" ON)
|
---|
44 | option(LIBXML2_WITH_PUSH "Add the PUSH parser interfaces" ON)
|
---|
45 | option(LIBXML2_WITH_PYTHON "Build Python bindings" ON)
|
---|
46 | option(LIBXML2_WITH_READER "Add the xmlReader parsing interface" ON)
|
---|
47 | option(LIBXML2_WITH_REGEXPS "Add Regular Expressions support" ON)
|
---|
48 | option(LIBXML2_WITH_SAX1 "Add the older SAX1 interface" ON)
|
---|
49 | option(LIBXML2_WITH_SCHEMAS "Add Relax-NG and Schemas support" ON)
|
---|
50 | option(LIBXML2_WITH_SCHEMATRON "Add Schematron support" ON)
|
---|
51 | option(LIBXML2_WITH_TESTS "Build tests" ON)
|
---|
52 | option(LIBXML2_WITH_THREADS "Add multithread support" ON)
|
---|
53 | option(LIBXML2_WITH_THREAD_ALLOC "Add per-thread memory" OFF)
|
---|
54 | option(LIBXML2_WITH_TLS "Enable thread-local storage" OFF)
|
---|
55 | option(LIBXML2_WITH_TREE "Add the DOM like tree manipulation APIs" ON)
|
---|
56 | set(LIBXML2_WITH_UNICODE ON)
|
---|
57 | option(LIBXML2_WITH_VALID "Add the DTD validation support" ON)
|
---|
58 | option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON)
|
---|
59 | option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON)
|
---|
60 | option(LIBXML2_WITH_XPATH "Add the XPATH support" ON)
|
---|
61 | option(LIBXML2_WITH_XPTR "Add the XPointer support" ON)
|
---|
62 | option(LIBXML2_WITH_XPTR_LOCS "Add support for XPointer locations" OFF)
|
---|
63 | option(LIBXML2_WITH_ZLIB "Use libz" OFF)
|
---|
64 | set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite")
|
---|
65 |
|
---|
66 | if(LIBXML2_WITH_PYTHON)
|
---|
67 | check_include_files(unistd.h HAVE_UNISTD_H)
|
---|
68 | check_symbol_exists(F_GETFL fcntl.h HAVE_F_GETFL)
|
---|
69 | find_package(Python COMPONENTS Interpreter Development REQUIRED)
|
---|
70 | #set(LIBXML2_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory")
|
---|
71 | set(LIBXML2_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python"
|
---|
72 | CACHE PATH "Python bindings install directory")
|
---|
73 | endif()
|
---|
74 |
|
---|
75 | foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_EXPR WITH_FTP WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LEGACY WITH_LZMA WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_XPTR_LOCS WITH_ZLIB)
|
---|
76 | if(LIBXML2_${VARIABLE})
|
---|
77 | set(${VARIABLE} 1)
|
---|
78 | else()
|
---|
79 | set(${VARIABLE} 0)
|
---|
80 | endif()
|
---|
81 | endforeach()
|
---|
82 |
|
---|
83 | set(LIBXML_VERSION ${VERSION})
|
---|
84 | set(LIBXML_VERSION_EXTRA "")
|
---|
85 | math(EXPR LIBXML_VERSION_NUMBER "
|
---|
86 | ${LIBXML_MAJOR_VERSION} * 10000 +
|
---|
87 | ${LIBXML_MINOR_VERSION} * 100 +
|
---|
88 | ${LIBXML_MICRO_VERSION}
|
---|
89 | ")
|
---|
90 |
|
---|
91 | set(MODULE_EXTENSION "${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
---|
92 |
|
---|
93 | set(PACKAGE "libxml2")
|
---|
94 | set(PACKAGE_NAME "libxml2")
|
---|
95 | set(PACKAGE_STRING "libxml2 ${VERSION}")
|
---|
96 | set(PACKAGE_TARNAME "libxml2")
|
---|
97 | set(PACKAGE_URL "https://gitlab.gnome.org/GNOME/libxml2")
|
---|
98 | set(PACKAGE_VERSION ${VERSION})
|
---|
99 |
|
---|
100 | if(LIBXML2_WITH_ICONV)
|
---|
101 | find_package(Iconv REQUIRED)
|
---|
102 | endif()
|
---|
103 |
|
---|
104 | if(LIBXML2_WITH_ICU)
|
---|
105 | find_package(ICU REQUIRED COMPONENTS data i18n uc)
|
---|
106 | endif()
|
---|
107 |
|
---|
108 | if(LIBXML2_WITH_LZMA)
|
---|
109 | find_package(LibLZMA REQUIRED)
|
---|
110 | endif()
|
---|
111 |
|
---|
112 | if(LIBXML2_WITH_THREADS)
|
---|
113 | find_package(Threads REQUIRED)
|
---|
114 | set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
---|
115 | list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
|
---|
116 | endif()
|
---|
117 |
|
---|
118 | if(LIBXML2_WITH_ZLIB)
|
---|
119 | find_package(ZLIB REQUIRED)
|
---|
120 | endif()
|
---|
121 |
|
---|
122 | if (NOT MSVC)
|
---|
123 | check_c_source_compiles("
|
---|
124 | void __attribute__((destructor))
|
---|
125 | f(void) {}
|
---|
126 | int main(void) { return 0; }
|
---|
127 | " HAVE_ATTRIBUTE_DESTRUCTOR)
|
---|
128 | if(HAVE_ATTRIBUTE_DESTRUCTOR)
|
---|
129 | set(ATTRIBUTE_DESTRUCTOR "__attribute__((destructor))")
|
---|
130 | endif()
|
---|
131 | check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
|
---|
132 | check_function_exists(class HAVE_CLASS)
|
---|
133 | check_include_files(dlfcn.h HAVE_DLFCN_H)
|
---|
134 | check_library_exists(dl dlopen "" HAVE_DLOPEN)
|
---|
135 | check_include_files(dl.h HAVE_DL_H)
|
---|
136 | check_include_files(fcntl.h HAVE_FCNTL_H)
|
---|
137 | check_function_exists(fpclass HAVE_FPCLASS)
|
---|
138 | check_function_exists(ftime HAVE_FTIME)
|
---|
139 | check_function_exists(getentropy HAVE_GETENTROPY)
|
---|
140 | check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
|
---|
141 | check_library_exists(history append_history "" HAVE_LIBHISTORY)
|
---|
142 | check_library_exists(readline readline "" HAVE_LIBREADLINE)
|
---|
143 | check_function_exists(mmap HAVE_MMAP)
|
---|
144 | check_function_exists(munmap HAVE_MUNMAP)
|
---|
145 | check_include_files(netdb.h HAVE_NETDB_H)
|
---|
146 | check_include_files(netinet/in.h HAVE_NETINET_IN_H)
|
---|
147 | check_include_files(poll.h HAVE_POLL_H)
|
---|
148 | check_library_exists(dld shl_load "" HAVE_SHLLOAD)
|
---|
149 | check_function_exists(stat HAVE_STAT)
|
---|
150 | check_include_files(stdint.h HAVE_STDINT_H)
|
---|
151 | check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
|
---|
152 | check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
|
---|
153 | check_include_files(sys/select.h HAVE_SYS_SELECT_H)
|
---|
154 | check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
|
---|
155 | check_include_files(sys/stat.h HAVE_SYS_STAT_H)
|
---|
156 | check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H)
|
---|
157 | check_include_files(sys/time.h HAVE_SYS_TIME_H)
|
---|
158 | check_include_files(unistd.h HAVE_UNISTD_H)
|
---|
159 | check_c_source_compiles("
|
---|
160 | #include <stddef.h>
|
---|
161 | #include <sys/socket.h>
|
---|
162 | int main() { (void) getsockopt(1, 1, 1, NULL, (socklen_t*) NULL); return 0; }
|
---|
163 | " XML_SOCKLEN_T_SOCKLEN_T)
|
---|
164 | if(XML_SOCKLEN_T_SOCKLEN_T)
|
---|
165 | set(XML_SOCKLEN_T socklen_t)
|
---|
166 | else()
|
---|
167 | check_c_source_compiles("
|
---|
168 | #include <stddef.h>
|
---|
169 | #include <sys/socket.h>
|
---|
170 | int main() { (void) getsockopt(1, 1, 1, NULL, (size_t*) NULL); return 0; }
|
---|
171 | " XML_SOCKLEN_T_SIZE_T)
|
---|
172 | if(XML_SOCKLEN_T_SIZE_T)
|
---|
173 | set(XML_SOCKLEN_T size_t)
|
---|
174 | else()
|
---|
175 | check_c_source_compiles("
|
---|
176 | #include <stddef.h>
|
---|
177 | #include <sys/socket.h>
|
---|
178 | int main() { (void) getsockopt (1, 1, 1, NULL, (int*) NULL); return 0; }
|
---|
179 | " XML_SOCKLEN_T_INT)
|
---|
180 | set(XML_SOCKLEN_T int)
|
---|
181 | endif()
|
---|
182 | endif()
|
---|
183 | endif()
|
---|
184 |
|
---|
185 | if(LIBXML2_WITH_TLS)
|
---|
186 | check_c_source_compiles(
|
---|
187 | "_Thread_local int v; int main(){return 0;}"
|
---|
188 | XML_THREAD_LOCAL_C11
|
---|
189 | )
|
---|
190 | if (XML_THREAD_LOCAL_C11)
|
---|
191 | set(XML_THREAD_LOCAL "_Thread_local")
|
---|
192 | else()
|
---|
193 | check_c_source_compiles(
|
---|
194 | "__thread int v; int main(){return 0;}"
|
---|
195 | XML_THREAD_LOCAL_THREAD
|
---|
196 | )
|
---|
197 | if (XML_THREAD_LOCAL_THREAD)
|
---|
198 | set(XML_THREAD_LOCAL "__thread")
|
---|
199 | else()
|
---|
200 | check_c_source_compiles(
|
---|
201 | "__declspec(thread) int v; int main(){return 0;}"
|
---|
202 | XML_THREAD_LOCAL_DECLSPEC
|
---|
203 | )
|
---|
204 | if (XML_THREAD_LOCAL_DECLSPEC)
|
---|
205 | set(XML_THREAD_LOCAL "__declspec(thread)")
|
---|
206 | endif()
|
---|
207 | endif()
|
---|
208 | endif()
|
---|
209 | endif()
|
---|
210 |
|
---|
211 | set(
|
---|
212 | LIBXML2_HDRS
|
---|
213 | include/libxml/c14n.h
|
---|
214 | include/libxml/catalog.h
|
---|
215 | include/libxml/chvalid.h
|
---|
216 | include/libxml/debugXML.h
|
---|
217 | include/libxml/dict.h
|
---|
218 | include/libxml/encoding.h
|
---|
219 | include/libxml/entities.h
|
---|
220 | include/libxml/globals.h
|
---|
221 | include/libxml/hash.h
|
---|
222 | include/libxml/HTMLparser.h
|
---|
223 | include/libxml/HTMLtree.h
|
---|
224 | include/libxml/list.h
|
---|
225 | include/libxml/nanoftp.h
|
---|
226 | include/libxml/nanohttp.h
|
---|
227 | include/libxml/parser.h
|
---|
228 | include/libxml/parserInternals.h
|
---|
229 | include/libxml/pattern.h
|
---|
230 | include/libxml/relaxng.h
|
---|
231 | include/libxml/SAX.h
|
---|
232 | include/libxml/SAX2.h
|
---|
233 | include/libxml/schemasInternals.h
|
---|
234 | include/libxml/schematron.h
|
---|
235 | include/libxml/threads.h
|
---|
236 | include/libxml/tree.h
|
---|
237 | include/libxml/uri.h
|
---|
238 | include/libxml/valid.h
|
---|
239 | include/libxml/xinclude.h
|
---|
240 | include/libxml/xlink.h
|
---|
241 | include/libxml/xmlIO.h
|
---|
242 | include/libxml/xmlautomata.h
|
---|
243 | include/libxml/xmlerror.h
|
---|
244 | include/libxml/xmlexports.h
|
---|
245 | include/libxml/xmlmemory.h
|
---|
246 | include/libxml/xmlmodule.h
|
---|
247 | include/libxml/xmlreader.h
|
---|
248 | include/libxml/xmlregexp.h
|
---|
249 | include/libxml/xmlsave.h
|
---|
250 | include/libxml/xmlschemas.h
|
---|
251 | include/libxml/xmlschemastypes.h
|
---|
252 | include/libxml/xmlstring.h
|
---|
253 | include/libxml/xmlunicode.h
|
---|
254 | include/libxml/xmlwriter.h
|
---|
255 | include/libxml/xpath.h
|
---|
256 | include/libxml/xpathInternals.h
|
---|
257 | include/libxml/xpointer.h
|
---|
258 | )
|
---|
259 |
|
---|
260 | set(
|
---|
261 | LIBXML2_SRCS
|
---|
262 | buf.c
|
---|
263 | c14n.c
|
---|
264 | catalog.c
|
---|
265 | chvalid.c
|
---|
266 | debugXML.c
|
---|
267 | dict.c
|
---|
268 | encoding.c
|
---|
269 | entities.c
|
---|
270 | error.c
|
---|
271 | globals.c
|
---|
272 | hash.c
|
---|
273 | HTMLparser.c
|
---|
274 | HTMLtree.c
|
---|
275 | legacy.c
|
---|
276 | list.c
|
---|
277 | nanoftp.c
|
---|
278 | nanohttp.c
|
---|
279 | parser.c
|
---|
280 | parserInternals.c
|
---|
281 | pattern.c
|
---|
282 | relaxng.c
|
---|
283 | SAX.c
|
---|
284 | SAX2.c
|
---|
285 | schematron.c
|
---|
286 | threads.c
|
---|
287 | tree.c
|
---|
288 | uri.c
|
---|
289 | valid.c
|
---|
290 | xinclude.c
|
---|
291 | xlink.c
|
---|
292 | xmlIO.c
|
---|
293 | xmlmemory.c
|
---|
294 | xmlmodule.c
|
---|
295 | xmlreader.c
|
---|
296 | xmlregexp.c
|
---|
297 | xmlsave.c
|
---|
298 | xmlschemas.c
|
---|
299 | xmlschemastypes.c
|
---|
300 | xmlstring.c
|
---|
301 | xmlunicode.c
|
---|
302 | xmlwriter.c
|
---|
303 | xpath.c
|
---|
304 | xpointer.c
|
---|
305 | xzlib.c
|
---|
306 | )
|
---|
307 |
|
---|
308 | if(WIN32)
|
---|
309 | list(APPEND LIBXML2_SRCS win32/libxml2.rc)
|
---|
310 | file(
|
---|
311 | WRITE
|
---|
312 | ${CMAKE_CURRENT_BINARY_DIR}/rcVersion.h
|
---|
313 | "#define LIBXML_MAJOR_VERSION ${LIBXML_MAJOR_VERSION}\n"
|
---|
314 | "#define LIBXML_MINOR_VERSION ${LIBXML_MINOR_VERSION}\n"
|
---|
315 | "#define LIBXML_MICRO_VERSION ${LIBXML_MICRO_VERSION}\n"
|
---|
316 | "#define LIBXML_DOTTED_VERSION \"${VERSION}\"\n"
|
---|
317 | )
|
---|
318 | endif()
|
---|
319 |
|
---|
320 | add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS})
|
---|
321 | add_library(LibXml2::LibXml2 ALIAS LibXml2)
|
---|
322 |
|
---|
323 | target_compile_definitions(LibXml2 PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
|
---|
324 |
|
---|
325 | if(LIBXML2_WITH_THREADS)
|
---|
326 | if(NOT WIN32)
|
---|
327 | check_include_files(pthread.h HAVE_PTHREAD_H)
|
---|
328 | endif()
|
---|
329 | endif()
|
---|
330 |
|
---|
331 | target_include_directories(
|
---|
332 | LibXml2
|
---|
333 | PUBLIC
|
---|
334 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
---|
335 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
---|
336 | $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/libxml2>
|
---|
337 | )
|
---|
338 |
|
---|
339 | if(LIBXML2_WITH_MODULES)
|
---|
340 | if(HAVE_DLOPEN)
|
---|
341 | target_link_libraries(LibXml2 PRIVATE dl)
|
---|
342 | set(MODULE_PLATFORM_LIBS "-ldl")
|
---|
343 | endif()
|
---|
344 |
|
---|
345 | if(HAVE_SHLLOAD)
|
---|
346 | target_link_libraries(LibXml2 PRIVATE dld)
|
---|
347 | set(MODULE_PLATFORM_LIBS "-ldld")
|
---|
348 | endif()
|
---|
349 | endif()
|
---|
350 |
|
---|
351 | if(UNIX)
|
---|
352 | target_link_libraries(LibXml2 PRIVATE m)
|
---|
353 | set(LIBM "-lm")
|
---|
354 | endif()
|
---|
355 |
|
---|
356 | if(WIN32)
|
---|
357 | target_link_libraries(LibXml2 PRIVATE ws2_32)
|
---|
358 | set(WINSOCK_LIBS "-lws2_32")
|
---|
359 | target_link_libraries(LibXml2 PRIVATE bcrypt)
|
---|
360 | set(CRYPTO_LIBS "-lbcrypt")
|
---|
361 | endif()
|
---|
362 |
|
---|
363 | if(LIBXML2_WITH_ICONV)
|
---|
364 | target_link_libraries(LibXml2 PUBLIC Iconv::Iconv)
|
---|
365 | if(NOT Iconv_IS_BUILT_IN)
|
---|
366 | set(ICONV_LIBS "-liconv")
|
---|
367 | endif()
|
---|
368 | endif()
|
---|
369 |
|
---|
370 | if(LIBXML2_WITH_ICU)
|
---|
371 | target_link_libraries(LibXml2 PRIVATE ICU::data ICU::i18n ICU::uc)
|
---|
372 | if(WIN32)
|
---|
373 | set(ICU_LDFLAGS "-licudt -licuin -licuuc")
|
---|
374 | else()
|
---|
375 | set(ICU_LDFLAGS "-licudata -licui18n -licuuc")
|
---|
376 | endif()
|
---|
377 | list(APPEND XML_PRIVATE_LIBS "${ICU_LDFLAGS}")
|
---|
378 | pkg_check_modules(ICU_PC IMPORTED_TARGET icu-i18n)
|
---|
379 | if(ICU_PC_FOUND)
|
---|
380 | list(APPEND XML_PC_REQUIRES icu-i18n)
|
---|
381 | else()
|
---|
382 | list(APPEND XML_PC_LIBS "${ICU_LDFLAGS}")
|
---|
383 | endif()
|
---|
384 | endif()
|
---|
385 |
|
---|
386 | if(LIBXML2_WITH_LZMA)
|
---|
387 | target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA)
|
---|
388 | set(LibLZMA_LDFLAGS "-llzma")
|
---|
389 | list(APPEND XML_PRIVATE_LIBS "${LibLZMA_LDFLAGS}")
|
---|
390 | pkg_check_modules(LibLZMA_PC IMPORTED_TARGET liblzma)
|
---|
391 | if(LibLZMA_PC_FOUND)
|
---|
392 | list(APPEND XML_PC_REQUIRES liblzma)
|
---|
393 | else()
|
---|
394 | list(APPEND XML_PC_LIBS "${LibLZMA_LDFLAGS}")
|
---|
395 | endif()
|
---|
396 | endif()
|
---|
397 |
|
---|
398 | if(LIBXML2_WITH_THREADS)
|
---|
399 | target_link_libraries(LibXml2 PRIVATE Threads::Threads)
|
---|
400 | endif()
|
---|
401 |
|
---|
402 | if(LIBXML2_WITH_ZLIB)
|
---|
403 | target_link_libraries(LibXml2 PRIVATE ZLIB::ZLIB)
|
---|
404 | set(ZLIB_LDFLAGS "-lz")
|
---|
405 | list(APPEND XML_PRIVATE_LIBS "${ZLIB_LDFLAGS}")
|
---|
406 | pkg_check_modules(ZLIB_PC IMPORTED_TARGET zlib)
|
---|
407 | if(ZLIB_PC_FOUND)
|
---|
408 | list(APPEND XML_PC_REQUIRES zlib)
|
---|
409 | else()
|
---|
410 | list(APPEND XML_PC_LIBS "${ZLIB_LDFLAGS}")
|
---|
411 | endif()
|
---|
412 | endif()
|
---|
413 |
|
---|
414 | if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
---|
415 | # These compiler flags can break the checks above so keep them here.
|
---|
416 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wshadow \
|
---|
417 | -Wpointer-arith -Wcast-align -Wwrite-strings \
|
---|
418 | -Wstrict-prototypes -Wmissing-prototypes \
|
---|
419 | -Wno-long-long -Wno-format-extra-args")
|
---|
420 |
|
---|
421 | if(BUILD_SHARED_LIBS AND UNIX AND NOT APPLE)
|
---|
422 | check_linker_flag(C "LINKER:--undefined-version" FLAG_UNDEFINED_VERSION)
|
---|
423 | if (FLAG_UNDEFINED_VERSION)
|
---|
424 | target_link_options(LibXml2 PRIVATE "LINKER:--undefined-version")
|
---|
425 | endif()
|
---|
426 | target_link_options(LibXml2 PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libxml2.syms")
|
---|
427 | endif()
|
---|
428 | endif()
|
---|
429 |
|
---|
430 | set_target_properties(
|
---|
431 | LibXml2
|
---|
432 | PROPERTIES
|
---|
433 | IMPORT_PREFIX lib
|
---|
434 | OUTPUT_NAME xml2
|
---|
435 | POSITION_INDEPENDENT_CODE ON
|
---|
436 | PREFIX lib
|
---|
437 | VERSION ${PROJECT_VERSION}
|
---|
438 | SOVERSION ${LIBXML_MAJOR_VERSION}
|
---|
439 | )
|
---|
440 |
|
---|
441 | if(MSVC)
|
---|
442 | if(BUILD_SHARED_LIBS)
|
---|
443 | set_target_properties(
|
---|
444 | LibXml2
|
---|
445 | PROPERTIES
|
---|
446 | DEBUG_POSTFIX d
|
---|
447 | )
|
---|
448 | else()
|
---|
449 | set_target_properties(
|
---|
450 | LibXml2
|
---|
451 | PROPERTIES
|
---|
452 | DEBUG_POSTFIX sd
|
---|
453 | MINSIZEREL_POSTFIX s
|
---|
454 | RELEASE_POSTFIX s
|
---|
455 | RELWITHDEBINFO_POSTFIX s
|
---|
456 | )
|
---|
457 | endif()
|
---|
458 | endif()
|
---|
459 |
|
---|
460 | install(FILES ${LIBXML2_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
|
---|
461 |
|
---|
462 | install(
|
---|
463 | TARGETS LibXml2
|
---|
464 | EXPORT LibXml2
|
---|
465 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development
|
---|
466 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_COMPONENT development
|
---|
467 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
|
---|
468 | )
|
---|
469 |
|
---|
470 | if(MSVC AND BUILD_SHARED_LIBS)
|
---|
471 | install(FILES $<TARGET_PDB_FILE:LibXml2> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
|
---|
472 | endif()
|
---|
473 |
|
---|
474 | if(LIBXML2_WITH_PROGRAMS)
|
---|
475 | set(
|
---|
476 | PROGRAMS
|
---|
477 | xmlcatalog
|
---|
478 | xmllint
|
---|
479 | )
|
---|
480 | foreach(PROGRAM ${PROGRAMS})
|
---|
481 | add_executable(${PROGRAM} ${PROGRAM}.c)
|
---|
482 | add_executable(LibXml2::${PROGRAM} ALIAS ${PROGRAM})
|
---|
483 | target_compile_definitions(${PROGRAM} PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
|
---|
484 | target_link_libraries(${PROGRAM} LibXml2)
|
---|
485 | if(HAVE_LIBHISTORY)
|
---|
486 | target_link_libraries(${PROGRAM} history)
|
---|
487 | endif()
|
---|
488 | if(HAVE_LIBREADLINE)
|
---|
489 | target_link_libraries(${PROGRAM} readline)
|
---|
490 | endif()
|
---|
491 | install(TARGETS ${PROGRAM} EXPORT LibXml2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs)
|
---|
492 | endforeach()
|
---|
493 | endif()
|
---|
494 |
|
---|
495 | if(LIBXML2_WITH_TESTS)
|
---|
496 | enable_testing()
|
---|
497 | set(
|
---|
498 | TESTS
|
---|
499 | runtest
|
---|
500 | runxmlconf
|
---|
501 | runsuite
|
---|
502 | testapi
|
---|
503 | testchar
|
---|
504 | testdict
|
---|
505 | testModule
|
---|
506 | testlimits
|
---|
507 | testparser
|
---|
508 | testrecurse
|
---|
509 | testThreads
|
---|
510 | )
|
---|
511 | foreach(TEST ${TESTS})
|
---|
512 | add_executable(${TEST} ${TEST}.c)
|
---|
513 | target_compile_definitions(${TEST} PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
|
---|
514 | target_link_libraries(${TEST} LibXml2)
|
---|
515 | endforeach()
|
---|
516 | if(Threads_FOUND)
|
---|
517 | foreach(TEST runtest testThreads)
|
---|
518 | target_link_libraries(${TEST} Threads::Threads)
|
---|
519 | endforeach()
|
---|
520 | endif()
|
---|
521 | add_test(NAME runtest COMMAND runtest --out ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
---|
522 | add_test(NAME runsuite COMMAND runsuite WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
---|
523 | if(EXISTS ${LIBXML2_XMLCONF_WORKING_DIR}/xmlconf/xmlconf.xml)
|
---|
524 | add_test(NAME runxmlconf COMMAND runxmlconf WORKING_DIRECTORY ${LIBXML2_XMLCONF_WORKING_DIR})
|
---|
525 | endif()
|
---|
526 | if(NOT WIN32)
|
---|
527 | add_test(NAME testapi COMMAND testapi)
|
---|
528 | endif()
|
---|
529 | add_test(NAME testchar COMMAND testchar)
|
---|
530 | add_test(NAME testdict COMMAND testdict)
|
---|
531 | add_test(NAME testparser COMMAND testparser)
|
---|
532 | add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
---|
533 | add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
---|
534 | endif()
|
---|
535 |
|
---|
536 | if(LIBXML2_WITH_PYTHON)
|
---|
537 | execute_process(
|
---|
538 | COMMAND
|
---|
539 | ${Python_EXECUTABLE}
|
---|
540 | ${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py
|
---|
541 | ${CMAKE_CURRENT_SOURCE_DIR}/doc/libxml2-api.xml
|
---|
542 | ${CMAKE_CURRENT_SOURCE_DIR}/python/libxml2-python-api.xml
|
---|
543 | WORKING_DIRECTORY
|
---|
544 | ${CMAKE_CURRENT_BINARY_DIR}
|
---|
545 | )
|
---|
546 | file(READ python/libxml.py LIBXML_PY)
|
---|
547 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML_PY}")
|
---|
548 | file(READ ${CMAKE_CURRENT_BINARY_DIR}/libxml2class.py LIBXML2CLASS_PY)
|
---|
549 | file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML2CLASS_PY}")
|
---|
550 | configure_file(${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in libxml2.py COPYONLY)
|
---|
551 | add_library(
|
---|
552 | LibXml2Mod
|
---|
553 | libxml2-py.c
|
---|
554 | libxml2-py.h
|
---|
555 | python/libxml.c
|
---|
556 | python/libxml_wrap.h
|
---|
557 | python/types.c
|
---|
558 | )
|
---|
559 | target_include_directories(
|
---|
560 | LibXml2Mod
|
---|
561 | PUBLIC
|
---|
562 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python>
|
---|
563 | )
|
---|
564 | target_link_libraries(LibXml2Mod LibXml2 Python::Python)
|
---|
565 | set_target_properties(
|
---|
566 | LibXml2Mod
|
---|
567 | PROPERTIES
|
---|
568 | IMPORT_PREFIX lib
|
---|
569 | OUTPUT_NAME xml2mod
|
---|
570 | PREFIX lib
|
---|
571 | VERSION ${PROJECT_VERSION}
|
---|
572 | )
|
---|
573 | if (WIN32)
|
---|
574 | set_target_properties(LibXml2Mod PROPERTIES SUFFIX ".pyd")
|
---|
575 | endif()
|
---|
576 | install(
|
---|
577 | TARGETS LibXml2Mod
|
---|
578 | ARCHIVE DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT development
|
---|
579 | LIBRARY DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime NAMELINK_COMPONENT development
|
---|
580 | RUNTIME DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime
|
---|
581 | )
|
---|
582 | if(MSVC AND BUILD_SHARED_LIBS)
|
---|
583 | install(FILES $<TARGET_PDB_FILE:LibXml2Mod> DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
|
---|
584 | endif()
|
---|
585 | install(FILES python/drv_libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime)
|
---|
586 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime)
|
---|
587 | endif()
|
---|
588 |
|
---|
589 | install(FILES doc/xml2-config.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
|
---|
590 | install(FILES doc/xmlcatalog.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
|
---|
591 | install(FILES doc/xmllint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
|
---|
592 | install(DIRECTORY doc/ DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT documentation
|
---|
593 | PATTERN "Makefile.*" EXCLUDE
|
---|
594 | PATTERN "*.1" EXCLUDE
|
---|
595 | PATTERN "*.py" EXCLUDE
|
---|
596 | PATTERN "*.res" EXCLUDE
|
---|
597 | PATTERN "*.xml" EXCLUDE
|
---|
598 | PATTERN "*.xsl" EXCLUDE)
|
---|
599 |
|
---|
600 | configure_package_config_file(
|
---|
601 | libxml2-config.cmake.cmake.in libxml2-config.cmake
|
---|
602 | INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
|
---|
603 | )
|
---|
604 |
|
---|
605 | install(
|
---|
606 | FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config.cmake
|
---|
607 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
|
---|
608 | COMPONENT development
|
---|
609 | )
|
---|
610 |
|
---|
611 | write_basic_package_version_file(
|
---|
612 | ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
|
---|
613 | VERSION ${PROJECT_VERSION}
|
---|
614 | COMPATIBILITY ExactVersion
|
---|
615 | )
|
---|
616 |
|
---|
617 | install(
|
---|
618 | FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
|
---|
619 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
|
---|
620 | COMPONENT development
|
---|
621 | )
|
---|
622 |
|
---|
623 | install(
|
---|
624 | EXPORT LibXml2
|
---|
625 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
|
---|
626 | NAMESPACE LibXml2::
|
---|
627 | FILE libxml2-export.cmake
|
---|
628 | COMPONENT development
|
---|
629 | )
|
---|
630 |
|
---|
631 | if(MSVC)
|
---|
632 | configure_file(include/win32config.h config.h COPYONLY)
|
---|
633 | else()
|
---|
634 | configure_file(config.h.cmake.in config.h)
|
---|
635 | endif()
|
---|
636 | configure_file(include/libxml/xmlversion.h.in libxml/xmlversion.h)
|
---|
637 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
|
---|
638 |
|
---|
639 | if(LIBXML2_WITH_PYTHON)
|
---|
640 | set(prefix "${CMAKE_INSTALL_PREFIX}")
|
---|
641 | configure_file(python/setup.py.in setup.py @ONLY)
|
---|
642 | endif()
|
---|
643 |
|
---|
644 | set(NON_PC_LIBS "${THREAD_LIBS} ${ICONV_LIBS} ${LIBM} ${WINSOCK_LIBS} ${CRYPTO_LIBS}")
|
---|
645 | list(APPEND XML_PC_LIBS "${NON_PC_LIBS}")
|
---|
646 | list(APPEND XML_PRIVATE_LIBS "${NON_PC_LIBS}")
|
---|
647 | list(REMOVE_DUPLICATES XML_PC_LIBS)
|
---|
648 | list(REMOVE_DUPLICATES XML_PRIVATE_LIBS)
|
---|
649 |
|
---|
650 | list(JOIN XML_PC_REQUIRES " " XML_PC_REQUIRES)
|
---|
651 | list(JOIN XML_PC_LIBS " " XML_PC_LIBS)
|
---|
652 | list(JOIN XML_PRIVATE_LIBS " " XML_PRIVATE_LIBS)
|
---|
653 |
|
---|
654 | set(XML_INCLUDEDIR "-I\${includedir}/libxml2")
|
---|
655 | set(XML_LIBDIR "-L\${libdir}")
|
---|
656 | set(XML_LIBS "-lxml2")
|
---|
657 |
|
---|
658 | if(BUILD_SHARED_LIBS)
|
---|
659 | set(XML_PC_PRIVATE ".private")
|
---|
660 | set(XML_PC_LIBS_PRIVATE "
|
---|
661 | Libs.private:")
|
---|
662 | else()
|
---|
663 | target_compile_definitions(LibXml2 PUBLIC LIBXML_STATIC)
|
---|
664 | set(XML_CFLAGS "-DLIBXML_STATIC")
|
---|
665 | set(XML_PRIVATE_LIBS_NO_SHARED "${XML_PRIVATE_LIBS}")
|
---|
666 | endif()
|
---|
667 |
|
---|
668 | file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
|
---|
669 | string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")
|
---|
670 |
|
---|
671 | if(WIN32)
|
---|
672 | set(prefix "\${pcfiledir}/${PACKAGE_RELATIVE_PATH}")
|
---|
673 | else()
|
---|
674 | set(prefix "${CMAKE_INSTALL_PREFIX}")
|
---|
675 | endif()
|
---|
676 | set(exec_prefix "\${prefix}")
|
---|
677 | set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
|
---|
678 | set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
---|
679 | configure_file(libxml-2.0.pc.in libxml-2.0.pc @ONLY)
|
---|
680 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml-2.0.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT development)
|
---|
681 |
|
---|
682 | if(WIN32)
|
---|
683 | set(prefix "\$(cd \"\$(dirname \"\$0\")\"; pwd -P)/..")
|
---|
684 | endif()
|
---|
685 | configure_file(xml2-config.in xml2-config @ONLY)
|
---|
686 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xml2-config DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT development)
|
---|
687 |
|
---|
688 | if(UNIX)
|
---|
689 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libxml.m4 DESTINATION ${CMAKE_INSTALL_DATADIR}/aclocal)
|
---|
690 | endif()
|
---|
691 |
|
---|
692 | set(XML_INCLUDEDIR "-I${CMAKE_INSTALL_FULL_INCLUDEDIR}/libxml2")
|
---|
693 | set(XML_LIBDIR "-L${CMAKE_INSTALL_FULL_LIBDIR}")
|
---|
694 |
|
---|
695 | set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)
|
---|
696 | set(CPACK_COMPONENT_PROGRAMS_DEPENDS runtime)
|
---|
697 | set(CPACK_DEB_COMPONENT_INSTALL ON)
|
---|
698 | set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
|
---|
699 | set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "${PACKAGE_TARNAME}-dev")
|
---|
700 | set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel")
|
---|
701 | set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PACKAGE_URL})
|
---|
702 | set(CPACK_DEBIAN_PACKAGE_NAME ${PACKAGE_TARNAME})
|
---|
703 | set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
---|
704 | set(CPACK_DEBIAN_PROGRAMS_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
|
---|
705 | set(CPACK_DEBIAN_PROGRAMS_PACKAGE_NAME "${PACKAGE_TARNAME}-utils")
|
---|
706 | set(CPACK_DEBIAN_PROGRAMS_PACKAGE_SECTION "utils")
|
---|
707 | set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME ${PACKAGE_TARNAME})
|
---|
708 | set(CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "${PACKAGE_TARNAME}-utils")
|
---|
709 | set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs")
|
---|
710 | set(CPACK_NSIS_PACKAGE_NAME ${PACKAGE_STRING})
|
---|
711 | set(CPACK_NSIS_URL_INFO_ABOUT ${PACKAGE_URL})
|
---|
712 | set(CPACK_PACKAGE_DISPLAY_NAME ${PACKAGE_STRING})
|
---|
713 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PACKAGE_TARNAME}-${PACKAGE_VERSION}")
|
---|
714 | set(CPACK_PACKAGE_NAME ${PACKAGE_TARNAME})
|
---|
715 | set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
|
---|
716 | set(CPACK_PACKAGE_VERSION_MAJOR ${LIBXML_MAJOR_VERSION})
|
---|
717 | set(CPACK_PACKAGE_VERSION_MINOR ${LIBXML_MINOR_VERSION})
|
---|
718 | set(CPACK_PACKAGE_VERSION_PATCH ${LIBXML_MICRO_VERSION})
|
---|
719 | set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/Copyright)
|
---|
720 | set(CPACK_RPM_COMPONENT_INSTALL ON)
|
---|
721 | set(CPACK_RPM_development_PACKAGE_NAME "${PACKAGE_NAME}-devel")
|
---|
722 | set(CPACK_RPM_development_PACKAGE_REQUIRES "${PACKAGE_NAME}")
|
---|
723 | set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
|
---|
724 | set(CPACK_RPM_PACKAGE_NAME ${PACKAGE_TARNAME})
|
---|
725 | set(CPACK_RPM_PACKAGE_URL ${PACKAGE_URL})
|
---|
726 | set(CPACK_RPM_programs_PACKAGE_NAME "${PACKAGE_NAME}-utils")
|
---|
727 | set(CPACK_RPM_programs_PACKAGE_REQUIRES "${PACKAGE_NAME}")
|
---|
728 | set(CPACK_RPM_runtime_PACKAGE_NAME "${PACKAGE_NAME}")
|
---|
729 | set(CPACK_RPM_runtime_PACKAGE_SUGGESTS "${PACKAGE_NAME}-utils")
|
---|
730 |
|
---|
731 | include(CPack)
|
---|