VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/CMakeLists.txt@ 105589

Last change on this file since 105589 was 105420, checked in by vboxsync, 4 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

File size: 24.7 KB
Line 
1cmake_minimum_required(VERSION 3.18)
2
3file(STRINGS "configure.ac" CONFIGURE_AC_LINES)
4foreach(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()
10endforeach()
11set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}")
12
13project(libxml2 VERSION ${VERSION} LANGUAGES C)
14
15include(CheckCSourceCompiles)
16include(CheckFunctionExists)
17include(CheckIncludeFiles)
18include(CheckLibraryExists)
19include(CheckLinkerFlag)
20include(CheckStructHasMember)
21include(CheckSymbolExists)
22include(CMakePackageConfigHelpers)
23include(FindPkgConfig)
24include(GNUInstallDirs)
25
26option(BUILD_SHARED_LIBS "Build shared libraries" ON)
27set(LIBXML2_WITH_AUTOMATA ON)
28option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON)
29option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON)
30option(LIBXML2_WITH_DEBUG "Add the debugging module" ON)
31set(LIBXML2_WITH_EXPR ON)
32option(LIBXML2_WITH_FTP "Add the FTP support" OFF)
33option(LIBXML2_WITH_HTML "Add the HTML support" ON)
34option(LIBXML2_WITH_HTTP "Add the HTTP support" OFF)
35option(LIBXML2_WITH_ICONV "Add ICONV support" ON)
36option(LIBXML2_WITH_ICU "Add ICU support" OFF)
37option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON)
38option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" OFF)
39option(LIBXML2_WITH_LZMA "Use liblzma" OFF)
40option(LIBXML2_WITH_MODULES "Add the dynamic modules support" ON)
41option(LIBXML2_WITH_OUTPUT "Add the serialization support" ON)
42option(LIBXML2_WITH_PATTERN "Add the xmlPattern selection interface" ON)
43option(LIBXML2_WITH_PROGRAMS "Build programs" ON)
44option(LIBXML2_WITH_PUSH "Add the PUSH parser interfaces" ON)
45option(LIBXML2_WITH_PYTHON "Build Python bindings" ON)
46option(LIBXML2_WITH_READER "Add the xmlReader parsing interface" ON)
47option(LIBXML2_WITH_REGEXPS "Add Regular Expressions support" ON)
48option(LIBXML2_WITH_SAX1 "Add the older SAX1 interface" ON)
49option(LIBXML2_WITH_SCHEMAS "Add Relax-NG and Schemas support" ON)
50option(LIBXML2_WITH_SCHEMATRON "Add Schematron support" ON)
51option(LIBXML2_WITH_TESTS "Build tests" ON)
52option(LIBXML2_WITH_THREADS "Add multithread support" ON)
53option(LIBXML2_WITH_THREAD_ALLOC "Add per-thread memory" OFF)
54option(LIBXML2_WITH_TLS "Enable thread-local storage" OFF)
55option(LIBXML2_WITH_TREE "Add the DOM like tree manipulation APIs" ON)
56set(LIBXML2_WITH_UNICODE ON)
57option(LIBXML2_WITH_VALID "Add the DTD validation support" ON)
58option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON)
59option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON)
60option(LIBXML2_WITH_XPATH "Add the XPATH support" ON)
61option(LIBXML2_WITH_XPTR "Add the XPointer support" ON)
62option(LIBXML2_WITH_XPTR_LOCS "Add support for XPointer locations" OFF)
63option(LIBXML2_WITH_ZLIB "Use libz" OFF)
64set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite")
65
66if(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")
73endif()
74
75foreach(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()
81endforeach()
82
83set(LIBXML_VERSION ${VERSION})
84set(LIBXML_VERSION_EXTRA "")
85math(EXPR LIBXML_VERSION_NUMBER "
86 ${LIBXML_MAJOR_VERSION} * 10000 +
87 ${LIBXML_MINOR_VERSION} * 100 +
88 ${LIBXML_MICRO_VERSION}
89")
90
91set(MODULE_EXTENSION "${CMAKE_SHARED_LIBRARY_SUFFIX}")
92
93set(PACKAGE "libxml2")
94set(PACKAGE_NAME "libxml2")
95set(PACKAGE_STRING "libxml2 ${VERSION}")
96set(PACKAGE_TARNAME "libxml2")
97set(PACKAGE_URL "https://gitlab.gnome.org/GNOME/libxml2")
98set(PACKAGE_VERSION ${VERSION})
99
100if(LIBXML2_WITH_ICONV)
101 find_package(Iconv REQUIRED)
102endif()
103
104if(LIBXML2_WITH_ICU)
105 find_package(ICU REQUIRED COMPONENTS data i18n uc)
106endif()
107
108if(LIBXML2_WITH_LZMA)
109 find_package(LibLZMA REQUIRED)
110endif()
111
112if(LIBXML2_WITH_THREADS)
113 find_package(Threads REQUIRED)
114 set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
115 list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
116endif()
117
118if(LIBXML2_WITH_ZLIB)
119 find_package(ZLIB REQUIRED)
120endif()
121
122if (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()
183endif()
184
185if(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()
209endif()
210
211set(
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
260set(
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
308if(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 )
318endif()
319
320add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS})
321add_library(LibXml2::LibXml2 ALIAS LibXml2)
322
323target_compile_definitions(LibXml2 PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
324
325if(LIBXML2_WITH_THREADS)
326 if(NOT WIN32)
327 check_include_files(pthread.h HAVE_PTHREAD_H)
328 endif()
329endif()
330
331target_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
339if(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()
349endif()
350
351if(UNIX)
352 target_link_libraries(LibXml2 PRIVATE m)
353 set(LIBM "-lm")
354endif()
355
356if(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")
361endif()
362
363if(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()
368endif()
369
370if(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()
384endif()
385
386if(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()
396endif()
397
398if(LIBXML2_WITH_THREADS)
399 target_link_libraries(LibXml2 PRIVATE Threads::Threads)
400endif()
401
402if(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()
412endif()
413
414if(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()
428endif()
429
430set_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
441if(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()
458endif()
459
460install(FILES ${LIBXML2_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
461
462install(
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
470if(MSVC AND BUILD_SHARED_LIBS)
471 install(FILES $<TARGET_PDB_FILE:LibXml2> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
472endif()
473
474if(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()
493endif()
494
495if(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})
534endif()
535
536if(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)
587endif()
588
589install(FILES doc/xml2-config.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
590install(FILES doc/xmlcatalog.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
591install(FILES doc/xmllint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
592install(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
600configure_package_config_file(
601 libxml2-config.cmake.cmake.in libxml2-config.cmake
602 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
603)
604
605install(
606 FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config.cmake
607 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
608 COMPONENT development
609)
610
611write_basic_package_version_file(
612 ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
613 VERSION ${PROJECT_VERSION}
614 COMPATIBILITY ExactVersion
615)
616
617install(
618 FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
619 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
620 COMPONENT development
621)
622
623install(
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
631if(MSVC)
632 configure_file(include/win32config.h config.h COPYONLY)
633else()
634 configure_file(config.h.cmake.in config.h)
635endif()
636configure_file(include/libxml/xmlversion.h.in libxml/xmlversion.h)
637install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
638
639if(LIBXML2_WITH_PYTHON)
640 set(prefix "${CMAKE_INSTALL_PREFIX}")
641 configure_file(python/setup.py.in setup.py @ONLY)
642endif()
643
644set(NON_PC_LIBS "${THREAD_LIBS} ${ICONV_LIBS} ${LIBM} ${WINSOCK_LIBS} ${CRYPTO_LIBS}")
645list(APPEND XML_PC_LIBS "${NON_PC_LIBS}")
646list(APPEND XML_PRIVATE_LIBS "${NON_PC_LIBS}")
647list(REMOVE_DUPLICATES XML_PC_LIBS)
648list(REMOVE_DUPLICATES XML_PRIVATE_LIBS)
649
650list(JOIN XML_PC_REQUIRES " " XML_PC_REQUIRES)
651list(JOIN XML_PC_LIBS " " XML_PC_LIBS)
652list(JOIN XML_PRIVATE_LIBS " " XML_PRIVATE_LIBS)
653
654set(XML_INCLUDEDIR "-I\${includedir}/libxml2")
655set(XML_LIBDIR "-L\${libdir}")
656set(XML_LIBS "-lxml2")
657
658if(BUILD_SHARED_LIBS)
659 set(XML_PC_PRIVATE ".private")
660 set(XML_PC_LIBS_PRIVATE "
661Libs.private:")
662else()
663 target_compile_definitions(LibXml2 PUBLIC LIBXML_STATIC)
664 set(XML_CFLAGS "-DLIBXML_STATIC")
665 set(XML_PRIVATE_LIBS_NO_SHARED "${XML_PRIVATE_LIBS}")
666endif()
667
668file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
669string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")
670
671if(WIN32)
672 set(prefix "\${pcfiledir}/${PACKAGE_RELATIVE_PATH}")
673else()
674 set(prefix "${CMAKE_INSTALL_PREFIX}")
675endif()
676set(exec_prefix "\${prefix}")
677set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
678set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
679configure_file(libxml-2.0.pc.in libxml-2.0.pc @ONLY)
680install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml-2.0.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT development)
681
682if(WIN32)
683 set(prefix "\$(cd \"\$(dirname \"\$0\")\"; pwd -P)/..")
684endif()
685configure_file(xml2-config.in xml2-config @ONLY)
686install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xml2-config DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT development)
687
688if(UNIX)
689 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libxml.m4 DESTINATION ${CMAKE_INSTALL_DATADIR}/aclocal)
690endif()
691
692set(XML_INCLUDEDIR "-I${CMAKE_INSTALL_FULL_INCLUDEDIR}/libxml2")
693set(XML_LIBDIR "-L${CMAKE_INSTALL_FULL_LIBDIR}")
694
695set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)
696set(CPACK_COMPONENT_PROGRAMS_DEPENDS runtime)
697set(CPACK_DEB_COMPONENT_INSTALL ON)
698set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
699set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "${PACKAGE_TARNAME}-dev")
700set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel")
701set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PACKAGE_URL})
702set(CPACK_DEBIAN_PACKAGE_NAME ${PACKAGE_TARNAME})
703set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
704set(CPACK_DEBIAN_PROGRAMS_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
705set(CPACK_DEBIAN_PROGRAMS_PACKAGE_NAME "${PACKAGE_TARNAME}-utils")
706set(CPACK_DEBIAN_PROGRAMS_PACKAGE_SECTION "utils")
707set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME ${PACKAGE_TARNAME})
708set(CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "${PACKAGE_TARNAME}-utils")
709set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs")
710set(CPACK_NSIS_PACKAGE_NAME ${PACKAGE_STRING})
711set(CPACK_NSIS_URL_INFO_ABOUT ${PACKAGE_URL})
712set(CPACK_PACKAGE_DISPLAY_NAME ${PACKAGE_STRING})
713set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PACKAGE_TARNAME}-${PACKAGE_VERSION}")
714set(CPACK_PACKAGE_NAME ${PACKAGE_TARNAME})
715set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
716set(CPACK_PACKAGE_VERSION_MAJOR ${LIBXML_MAJOR_VERSION})
717set(CPACK_PACKAGE_VERSION_MINOR ${LIBXML_MINOR_VERSION})
718set(CPACK_PACKAGE_VERSION_PATCH ${LIBXML_MICRO_VERSION})
719set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/Copyright)
720set(CPACK_RPM_COMPONENT_INSTALL ON)
721set(CPACK_RPM_development_PACKAGE_NAME "${PACKAGE_NAME}-devel")
722set(CPACK_RPM_development_PACKAGE_REQUIRES "${PACKAGE_NAME}")
723set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
724set(CPACK_RPM_PACKAGE_NAME ${PACKAGE_TARNAME})
725set(CPACK_RPM_PACKAGE_URL ${PACKAGE_URL})
726set(CPACK_RPM_programs_PACKAGE_NAME "${PACKAGE_NAME}-utils")
727set(CPACK_RPM_programs_PACKAGE_REQUIRES "${PACKAGE_NAME}")
728set(CPACK_RPM_runtime_PACKAGE_NAME "${PACKAGE_NAME}")
729set(CPACK_RPM_runtime_PACKAGE_SUGGESTS "${PACKAGE_NAME}-utils")
730
731include(CPack)
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette