1cmake_minimum_required(VERSION 3.15) 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(CheckStructHasMember) 20include(CheckSymbolExists) 21include(CMakePackageConfigHelpers) 22include(GNUInstallDirs) 23 24option(BUILD_SHARED_LIBS "Build shared libraries" ON) 25set(LIBXML2_WITH_AUTOMATA ON) 26option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON) 27option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON) 28option(LIBXML2_WITH_DEBUG "Add the debugging module" ON) 29option(LIBXML2_WITH_DOCB "Add Docbook SGML support" ON) 30set(LIBXML2_WITH_EXPR ON) 31option(LIBXML2_WITH_FTP "Add the FTP support" ON) 32option(LIBXML2_WITH_HTML "Add the HTML support" ON) 33option(LIBXML2_WITH_HTTP "Add the HTTP support" ON) 34option(LIBXML2_WITH_ICONV "Add ICONV support" ON) 35option(LIBXML2_WITH_ICU "Add ICU support" OFF) 36option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON) 37option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" ON) 38option(LIBXML2_WITH_LZMA "Use liblzma" ON) 39option(LIBXML2_WITH_MEM_DEBUG "Add the memory debugging module" 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_RUN_DEBUG "Add the runtime debugging module" OFF) 49option(LIBXML2_WITH_SAX1 "Add the older SAX1 interface" ON) 50option(LIBXML2_WITH_SCHEMAS "Add Relax-NG and Schemas support" ON) 51option(LIBXML2_WITH_SCHEMATRON "Add Schematron support" ON) 52option(LIBXML2_WITH_TESTS "Build tests" ON) 53option(LIBXML2_WITH_THREADS "Add multithread support" ON) 54option(LIBXML2_WITH_THREAD_ALLOC "Add per-thread memory" OFF) 55option(LIBXML2_WITH_TREE "Add the DOM like tree manipulation APIs" ON) 56set(LIBXML2_WITH_TRIO OFF) 57set(LIBXML2_WITH_UNICODE ON) 58option(LIBXML2_WITH_VALID "Add the DTD validation support" ON) 59option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON) 60option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON) 61option(LIBXML2_WITH_XPATH "Add the XPATH support" ON) 62option(LIBXML2_WITH_XPTR "Add the XPointer support" ON) 63option(LIBXML2_WITH_ZLIB "Use libz" ON) 64set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite") 65 66if(LIBXML2_WITH_ICONV) 67 find_package(Iconv REQUIRED) 68endif() 69 70if(LIBXML2_WITH_ICU) 71 find_package(ICU REQUIRED COMPONENTS data i18n uc) 72endif() 73 74if(LIBXML2_WITH_LZMA) 75 find_package(LibLZMA REQUIRED) 76endif() 77 78if(LIBXML2_WITH_PYTHON) 79 check_include_files(unistd.h HAVE_UNISTD_H) 80 check_symbol_exists(F_GETFL fcntl.h HAVE_F_GETFL) 81 if(HAVE_UNISTD_H AND HAVE_F_GETFL) 82 find_package(Python COMPONENTS Interpreter Development REQUIRED) 83 else() 84 find_package(Python2 COMPONENTS Interpreter Development REQUIRED) 85 add_library(Python::Python ALIAS Python2::Python) 86 set(Python_EXECUTABLE ${Python2_EXECUTABLE}) 87 set(Python_SITEARCH ${Python2_SITEARCH}) 88 endif() 89 set(LIBXML2_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory") 90endif() 91 92if(LIBXML2_WITH_THREADS) 93 find_package(Threads REQUIRED) 94endif() 95 96if(LIBXML2_WITH_ZLIB) 97 find_package(ZLIB REQUIRED) 98endif() 99 100foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_DOCB WITH_EXPR WITH_FTP WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LEGACY WITH_LZMA WITH_MEM_DEBUG WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_RUN_DEBUG WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_TRIO WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB) 101 if(LIBXML2_${VARIABLE}) 102 set(${VARIABLE} 1) 103 else() 104 set(${VARIABLE} 0) 105 endif() 106endforeach() 107 108set(LIBXML_VERSION ${LIBXML_MAJOR_VERSION}0${LIBXML_MINOR_VERSION}0${LIBXML_MICRO_VERSION}) 109set(LIBXML_VERSION_STRING "${LIBXML_VERSION}") 110set(LIBXML_VERSION_EXTRA "") 111set(LIBXML_VERSION_NUMBER ${LIBXML_VERSION}) 112 113set(MODULE_EXTENSION "${CMAKE_SHARED_LIBRARY_SUFFIX}") 114 115set(PACKAGE "libxml2") 116set(PACKAGE_BUGREPORT "xml@gnome.org") 117set(PACKAGE_NAME "libxml2") 118set(PACKAGE_STRING "libxml2 ${VERSION}") 119set(PACKAGE_TARNAME "libxml2") 120set(PACKAGE_URL "https://gitlab.gnome.org/GNOME/libxml2") 121set(PACKAGE_VERSION ${VERSION}) 122 123if(LIBLZMA_FOUND) 124 list(APPEND CMAKE_REQUIRED_LIBRARIES LibLZMA::LibLZMA) 125endif() 126 127if(Threads_FOUND) 128 list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads) 129endif() 130 131if(ZLIB_FOUND) 132 list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB) 133endif() 134 135if(MSVC) 136 configure_file(include/win32config.h config.h COPYONLY) 137else() 138 check_c_source_compiles(" 139 void __attribute__((destructor)) 140 f(void) {} 141 int main(void) { return 0; } 142 " HAVE_ATTRIBUTE_DESTRUCTOR) 143 if(HAVE_ATTRIBUTE_DESTRUCTOR) 144 set(ATTRIBUTE_DESTRUCTOR "__attribute__((destructor))") 145 endif() 146 check_c_source_compiles(" 147 #include <netdb.h> 148 int main() { (void) gethostbyname((const char*) \"\"); return 0; } 149 " GETHOSTBYNAME_ARG_CAST_CONST) 150 if(NOT GETHOSTBYNAME_ARG_CAST_CONST) 151 set(GETHOSTBYNAME_ARG_CAST "(char *)") 152 else() 153 set(GETHOSTBYNAME_ARG_CAST "/**/") 154 endif() 155 check_include_files(arpa/inet.h HAVE_ARPA_INET_H) 156 check_include_files(arpa/nameser.h HAVE_ARPA_NAMESER_H) 157 check_struct_has_member("struct sockaddr_storage" ss_family "sys/socket.h;sys/types.h" HAVE_SS_FAMILY) 158 check_struct_has_member("struct sockaddr_storage" __ss_family "sys/socket.h;sys/types.h" HAVE_BROKEN_SS_FAMILY) 159 if(HAVE_BROKEN_SS_FAMILY) 160 set(ss_family __ss_family) 161 endif() 162 check_function_exists(class HAVE_CLASS) 163 check_include_files(ctype.h HAVE_CTYPE_H) 164 check_include_files(dlfcn.h HAVE_DLFCN_H) 165 check_library_exists(dl dlopen "" HAVE_DLOPEN) 166 check_include_files(dl.h HAVE_DL_H) 167 check_include_files(errno.h HAVE_ERRNO_H) 168 check_include_files(fcntl.h HAVE_FCNTL_H) 169 check_include_files(float.h HAVE_FLOAT_H) 170 check_function_exists(fpclass HAVE_FPCLASS) 171 check_function_exists(fprintf HAVE_FPRINTF) 172 check_function_exists(ftime HAVE_FTIME) 173 check_function_exists(getaddrinfo HAVE_GETADDRINFO) 174 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) 175 check_include_files(inttypes.h HAVE_INTTYPES_H) 176 check_function_exists(isascii HAVE_ISASCII) 177 check_library_exists(history append_history "" HAVE_LIBHISTORY) 178 check_library_exists(readline readline "" HAVE_LIBREADLINE) 179 check_include_files(limits.h HAVE_LIMITS_H) 180 check_function_exists(localtime HAVE_LOCALTIME) 181 check_include_files(malloc.h HAVE_MALLOC_H) 182 check_include_files(math.h HAVE_MATH_H) 183 check_function_exists(mmap HAVE_MMAP) 184 check_function_exists(munmap HAVE_MUNMAP) 185 check_include_files(netdb.h HAVE_NETDB_H) 186 check_include_files(netinet/in.h HAVE_NETINET_IN_H) 187 check_include_files(poll.h HAVE_POLL_H) 188 check_function_exists(printf HAVE_PRINTF) 189 check_include_files(pthread.h HAVE_PTHREAD_H) 190 check_function_exists(putenv HAVE_PUTENV) 191 check_function_exists(rand HAVE_RAND) 192 check_function_exists(rand_r HAVE_RAND_R) 193 check_include_files(resolv.h HAVE_RESOLV_H) 194 check_library_exists(dld shl_load "" HAVE_SHLLOAD) 195 check_include_files(signal.h HAVE_SIGNAL_H) 196 check_function_exists(snprintf HAVE_SNPRINTF) 197 check_function_exists(sprintf HAVE_SPRINTF) 198 check_function_exists(srand HAVE_SRAND) 199 check_function_exists(sscanf HAVE_SSCANF) 200 check_function_exists(stat HAVE_STAT) 201 check_include_files(stdarg.h HAVE_STDARG_H) 202 check_include_files(stdint.h HAVE_STDINT_H) 203 check_include_files(stdlib.h HAVE_STDLIB_H) 204 check_function_exists(strftime HAVE_STRFTIME) 205 check_include_files(strings.h HAVE_STRINGS_H) 206 check_include_files(string.h HAVE_STRING_H) 207 check_include_files(sys/mman.h HAVE_SYS_MMAN_H) 208 check_include_files(sys/select.h HAVE_SYS_SELECT_H) 209 check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) 210 check_include_files(sys/stat.h HAVE_SYS_STAT_H) 211 check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H) 212 check_include_files(sys/time.h HAVE_SYS_TIME_H) 213 check_include_files(sys/types.h HAVE_SYS_TYPES_H) 214 check_function_exists(time HAVE_TIME) 215 check_include_files(time.h HAVE_TIME_H) 216 check_include_files(unistd.h HAVE_UNISTD_H) 217 check_function_exists(va_copy HAVE_VA_COPY) 218 check_function_exists(vfprintf HAVE_VFPRINTF) 219 check_function_exists(vsnprintf HAVE_VSNPRINTF) 220 check_function_exists(vsprintf HAVE_VSPRINTF) 221 check_function_exists(__va_copy HAVE___VA_COPY) 222 check_c_source_compiles(" 223 #include <stdlib.h> 224 #include <iconv.h> 225 extern 226 #ifdef __cplusplus 227 \"C\" 228 #endif 229 #if defined(__STDC__) || defined(__cplusplus) 230 size_t iconv(iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft); 231 #else 232 size_t iconv(); 233 #endif 234 int main() { return 0; } 235 " ICONV_CONST_TEST) 236 if(NOT ICONV_CONST_TEST) 237 set(ICONV_CONST "const") 238 endif() 239 set(LT_OBJDIR ".libs/") 240 check_c_source_compiles(" 241 #include <sys/socket.h> 242 #include <sys/types.h> 243 int main() { (void) send(1, (const char*) \"\", 1, 1); return 0; } 244 " SEND_ARG2_CAST_CONST) 245 if(NOT SEND_ARG2_CAST_CONST) 246 set(SEND_ARG2_CAST "(char *)") 247 else() 248 set(SEND_ARG2_CAST "/**/") 249 endif() 250 check_include_files("float.h;stdarg.h;stdlib.h;string.h" STDC_HEADERS) 251 check_c_source_compiles(" 252 #include <stdarg.h> 253 void a(va_list* ap) {}; 254 int main() { va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1; return 0; } 255 " VA_LIST_IS_ARRAY_TEST) 256 if(VA_LIST_IS_ARRAY_TEST) 257 set(VA_LIST_IS_ARRAY FALSE) 258 else() 259 set(VA_LIST_IS_ARRAY TRUE) 260 endif() 261 check_c_source_compiles(" 262 #include <stddef.h> 263 #include <sys/socket.h> 264 #include <sys/types.h> 265 int main() { (void) getsockopt(1, 1, 1, NULL, (socklen_t*) NULL); return 0; } 266 " XML_SOCKLEN_T_SOCKLEN_T) 267 if(XML_SOCKLEN_T_SOCKLEN_T) 268 set(XML_SOCKLEN_T socklen_t) 269 else() 270 check_c_source_compiles(" 271 #include <stddef.h> 272 #include <sys/socket.h> 273 #include <sys/types.h> 274 int main() { (void) getsockopt(1, 1, 1, NULL, (size_t*) NULL); return 0; } 275 " XML_SOCKLEN_T_SIZE_T) 276 if(XML_SOCKLEN_T_SIZE_T) 277 set(XML_SOCKLEN_T size_t) 278 else() 279 check_c_source_compiles(" 280 #include <stddef.h> 281 #include <sys/socket.h> 282 #include <sys/types.h> 283 int main() { (void) getsockopt (1, 1, 1, NULL, (int*) NULL); return 0; } 284 " XML_SOCKLEN_T_INT) 285 set(XML_SOCKLEN_T int) 286 endif() 287 endif() 288 configure_file(config.h.cmake.in config.h) 289endif() 290 291set( 292 LIBXML2_HDRS 293 include/libxml/c14n.h 294 include/libxml/catalog.h 295 include/libxml/chvalid.h 296 include/libxml/debugXML.h 297 include/libxml/dict.h 298 include/libxml/DOCBparser.h 299 include/libxml/encoding.h 300 include/libxml/entities.h 301 include/libxml/globals.h 302 include/libxml/hash.h 303 include/libxml/HTMLparser.h 304 include/libxml/HTMLtree.h 305 include/libxml/list.h 306 include/libxml/nanoftp.h 307 include/libxml/nanohttp.h 308 include/libxml/parser.h 309 include/libxml/parserInternals.h 310 include/libxml/pattern.h 311 include/libxml/relaxng.h 312 include/libxml/SAX.h 313 include/libxml/SAX2.h 314 include/libxml/schemasInternals.h 315 include/libxml/schematron.h 316 include/libxml/threads.h 317 include/libxml/tree.h 318 include/libxml/uri.h 319 include/libxml/valid.h 320 include/libxml/xinclude.h 321 include/libxml/xlink.h 322 include/libxml/xmlIO.h 323 include/libxml/xmlautomata.h 324 include/libxml/xmlerror.h 325 include/libxml/xmlexports.h 326 include/libxml/xmlmemory.h 327 include/libxml/xmlmodule.h 328 include/libxml/xmlreader.h 329 include/libxml/xmlregexp.h 330 include/libxml/xmlsave.h 331 include/libxml/xmlschemas.h 332 include/libxml/xmlschemastypes.h 333 include/libxml/xmlstring.h 334 include/libxml/xmlunicode.h 335 include/libxml/xmlwriter.h 336 include/libxml/xpath.h 337 include/libxml/xpathInternals.h 338 include/libxml/xpointer.h 339) 340 341set( 342 LIBXML2_SRCS 343 buf.c 344 c14n.c 345 catalog.c 346 chvalid.c 347 debugXML.c 348 dict.c 349 encoding.c 350 entities.c 351 error.c 352 globals.c 353 hash.c 354 HTMLparser.c 355 HTMLtree.c 356 legacy.c 357 list.c 358 nanoftp.c 359 nanohttp.c 360 parser.c 361 parserInternals.c 362 pattern.c 363 relaxng.c 364 SAX.c 365 SAX2.c 366 schematron.c 367 threads.c 368 tree.c 369 uri.c 370 valid.c 371 xinclude.c 372 xlink.c 373 xmlIO.c 374 xmlmemory.c 375 xmlmodule.c 376 xmlreader.c 377 xmlregexp.c 378 xmlsave.c 379 xmlschemas.c 380 xmlschemastypes.c 381 xmlstring.c 382 xmlunicode.c 383 xmlwriter.c 384 xpath.c 385 xpointer.c 386 xzlib.c 387) 388 389if(WIN32) 390 list(APPEND LIBXML2_SRCS win32/libxml2.rc) 391 file( 392 WRITE 393 ${CMAKE_CURRENT_BINARY_DIR}/rcVersion.h 394 "#define LIBXML_MAJOR_VERSION ${LIBXML_MAJOR_VERSION}\n" 395 "#define LIBXML_MINOR_VERSION ${LIBXML_MINOR_VERSION}\n" 396 "#define LIBXML_MICRO_VERSION ${LIBXML_MICRO_VERSION}\n" 397 "#define LIBXML_DOTTED_VERSION \"${VERSION}\"\n" 398 ) 399endif() 400 401if(LIBXML2_WITH_SAX1) 402 list(APPEND LIBXML2_SRCS DOCBparser.c) 403endif() 404 405if(LIBXML2_WITH_TRIO) 406 list(APPEND LIBXML2_SRCS trio.c triostr.c) 407endif() 408 409add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS}) 410add_library(LibXml2::LibXml2 ALIAS LibXml2) 411 412if(NOT BUILD_SHARED_LIBS) 413 target_compile_definitions(LibXml2 INTERFACE LIBXML_STATIC) 414 set(XML_CFLAGS "-DLIBXML_STATIC") 415endif() 416 417if(LIBXML2_WITH_THREADS) 418 target_compile_definitions(LibXml2 PRIVATE _REENTRANT) 419 if(WIN32) 420 target_compile_definitions(LibXml2 PRIVATE HAVE_WIN32_THREADS) 421 endif() 422endif() 423 424target_include_directories( 425 LibXml2 426 PUBLIC 427 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 428 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> 429 $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/libxml2> 430) 431 432if(HAVE_DLOPEN) 433 target_link_libraries(LibXml2 PRIVATE dl) 434 set(MODULE_PLATFORM_LIBS "-ldl") 435endif() 436 437if(HAVE_SHLLOAD) 438 target_link_libraries(LibXml2 PRIVATE dld) 439 set(MODULE_PLATFORM_LIBS "-ldld") 440endif() 441 442if(UNIX) 443 target_link_libraries(LibXml2 PRIVATE m) 444 set(M_LIBS "-lm") 445endif() 446 447if(WIN32) 448 target_link_libraries(LibXml2 PRIVATE ws2_32) 449 set(WIN32_EXTRA_LIBADD "-lws2_32") 450endif() 451 452if(LIBXML2_WITH_ICONV) 453 target_link_libraries(LibXml2 PUBLIC Iconv::Iconv) 454 if(NOT Iconv_IS_BUILT_IN) 455 set(ICONV_LIBS "-liconv") 456 endif() 457endif() 458 459if(LIBXML2_WITH_ICU) 460 target_link_libraries(LibXml2 PRIVATE ICU::data ICU::i18n ICU::uc) 461 if(WIN32) 462 set(ICU_LIBS "-licudt -licuin -licuuc") 463 else() 464 set(ICU_LIBS "-licudata -licui18n -licuuc") 465 endif() 466endif() 467 468if(LIBXML2_WITH_LZMA) 469 target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA) 470 set(LZMA_LIBS "-llzma") 471endif() 472 473if(LIBXML2_WITH_THREADS) 474 target_link_libraries(LibXml2 PRIVATE Threads::Threads) 475 set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT}) 476endif() 477 478if(LIBXML2_WITH_ZLIB) 479 target_link_libraries(LibXml2 PRIVATE ZLIB::ZLIB) 480 set(Z_LIBS "-lz") 481endif() 482 483set_target_properties( 484 LibXml2 485 PROPERTIES 486 IMPORT_PREFIX lib 487 OUTPUT_NAME xml2 488 POSITION_INDEPENDENT_CODE ON 489 PREFIX lib 490 VERSION ${PROJECT_VERSION} 491) 492 493if(MSVC) 494 if(BUILD_SHARED_LIBS) 495 set_target_properties( 496 LibXml2 497 PROPERTIES 498 DEBUG_POSTFIX d 499 ) 500 else() 501 set_target_properties( 502 LibXml2 503 PROPERTIES 504 DEBUG_POSTFIX sd 505 MINSIZEREL_POSTFIX s 506 RELEASE_POSTFIX s 507 RELWITHDEBINFO_POSTFIX s 508 ) 509 endif() 510endif() 511 512install(FILES ${LIBXML2_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development) 513 514install( 515 TARGETS LibXml2 516 EXPORT LibXml2 517 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development 518 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_COMPONENT development 519 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime 520) 521 522if(MSVC AND BUILD_SHARED_LIBS) 523 install(FILES $<TARGET_PDB_FILE:LibXml2> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug) 524endif() 525 526if(LIBXML2_WITH_PROGRAMS) 527 set( 528 PROGRAMS 529 xmlcatalog 530 xmllint 531 ) 532 foreach(PROGRAM ${PROGRAMS}) 533 add_executable(${PROGRAM} ${PROGRAM}.c) 534 add_executable(LibXml2::${PROGRAM} ALIAS ${PROGRAM}) 535 target_link_libraries(${PROGRAM} LibXml2) 536 if(HAVE_LIBHISTORY) 537 target_link_libraries(${PROGRAM} history) 538 endif() 539 if(HAVE_LIBREADLINE) 540 target_link_libraries(${PROGRAM} readline) 541 endif() 542 install(TARGETS ${PROGRAM} EXPORT LibXml2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs) 543 endforeach() 544endif() 545 546if(LIBXML2_WITH_TESTS) 547 enable_testing() 548 set( 549 TESTS 550 runxmlconf 551 runsuite 552 testapi 553 testAutomata 554 testC14N 555 testchar 556 testdict 557 testHTML 558 testModule 559 testlimits 560 testReader 561 testrecurse 562 testRegexp 563 testRelax 564 testSAX 565 testSchemas 566 testURI 567 testXPath 568 ) 569 foreach(TEST ${TESTS}) 570 add_executable(${TEST} ${TEST}.c) 571 target_link_libraries(${TEST} LibXml2) 572 endforeach() 573 if(EXISTS ${LIBXML2_XMLCONF_WORKING_DIR}/xmlconf/xmlconf.xml) 574 add_test(NAME runxmlconf COMMAND runxmlconf WORKING_DIRECTORY ${LIBXML2_XMLCONF_WORKING_DIR}) 575 endif() 576 if(NOT WIN32) 577 add_test(NAME testapi COMMAND testapi) 578 endif() 579 add_test(NAME testchar COMMAND testchar) 580 add_test(NAME testdict COMMAND testdict) 581 add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 582 if(Threads_FOUND) 583 set( 584 TESTS_THREADS 585 runtest 586 testThreads 587 ) 588 foreach(TEST ${TESTS_THREADS}) 589 add_executable(${TEST} ${TEST}.c) 590 if(WIN32) 591 target_compile_definitions(${TEST} PRIVATE HAVE_WIN32_THREADS) 592 endif() 593 target_link_libraries(${TEST} LibXml2 Threads::Threads) 594 endforeach() 595 add_test(NAME runtest COMMAND runtest --out ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 596 add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 597 endif() 598endif() 599 600if(LIBXML2_WITH_PYTHON) 601 execute_process( 602 COMMAND 603 ${Python_EXECUTABLE} 604 ${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py 605 ${CMAKE_CURRENT_SOURCE_DIR}/doc/libxml2-api.xml 606 ${CMAKE_CURRENT_SOURCE_DIR}/python/libxml2-python-api.xml 607 WORKING_DIRECTORY 608 ${CMAKE_CURRENT_BINARY_DIR} 609 ) 610 file(READ python/libxml.py LIBXML_PY) 611 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML_PY}") 612 file(READ ${CMAKE_CURRENT_BINARY_DIR}/libxml2class.py LIBXML2CLASS_PY) 613 file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML2CLASS_PY}") 614 configure_file(${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in libxml2.py COPYONLY) 615 add_library( 616 LibXml2Mod 617 libxml2-py.c 618 libxml2-py.h 619 python/libxml.c 620 python/libxml_wrap.h 621 python/types.c 622 ) 623 target_include_directories( 624 LibXml2Mod 625 PUBLIC 626 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python> 627 ) 628 target_link_libraries(LibXml2Mod LibXml2 Python::Python) 629 set_target_properties( 630 LibXml2Mod 631 PROPERTIES 632 IMPORT_PREFIX lib 633 OUTPUT_NAME xml2mod 634 PREFIX lib 635 VERSION ${PROJECT_VERSION} 636 ) 637 install( 638 TARGETS LibXml2Mod 639 ARCHIVE DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT development 640 LIBRARY DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime NAMELINK_COMPONENT development 641 RUNTIME DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime 642 ) 643 if(MSVC AND BUILD_SHARED_LIBS) 644 install(FILES $<TARGET_PDB_FILE:LibXml2Mod> DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug) 645 endif() 646 install(FILES python/drv_libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime) 647 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime) 648endif() 649 650install(FILES libxml.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 COMPONENT documentation) 651install(FILES doc/xmlcatalog.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation) 652install(FILES doc/xmllint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation) 653install(DIRECTORY doc/ DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/libxml2 COMPONENT documentation PATTERN Makefile.* EXCLUDE) 654 655configure_package_config_file( 656 libxml2-config.cmake.cmake.in libxml2-config.cmake 657 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} 658) 659 660install( 661 FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config.cmake 662 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} 663 COMPONENT development 664) 665 666write_basic_package_version_file( 667 ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake 668 VERSION ${PROJECT_VERSION} 669 COMPATIBILITY ExactVersion 670) 671 672install( 673 FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake 674 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} 675 COMPONENT development 676) 677 678install( 679 EXPORT LibXml2 680 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} 681 NAMESPACE LibXml2:: 682 FILE libxml2-export.cmake 683 COMPONENT development 684) 685 686configure_file(include/libxml/xmlversion.h.in libxml/xmlversion.h) 687install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development) 688 689if(LIBXML2_WITH_PYTHON) 690 set(prefix "${CMAKE_INSTALL_PREFIX}") 691 configure_file(python/setup.py.in setup.py @ONLY) 692endif() 693 694set(XML_INCLUDEDIR "-I\${includedir}/libxml2") 695set(XML_LIBDIR "-L\${libdir}") 696set(XML_LIBS "-lxml2") 697set(XML_PRIVATE_LIBS "${Z_LIBS} ${LZMA_LIBS} ${THREAD_LIBS} ${ICONV_LIBS} ${ICU_LIBS} ${M_LIBS}") 698 699file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}") 700string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}") 701 702set(prefix "\${pcfiledir}/${PACKAGE_RELATIVE_PATH}") 703set(exec_prefix "\${prefix}") 704set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") 705set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") 706configure_file(libxml-2.0.pc.in libxml-2.0.pc @ONLY) 707install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml-2.0.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT development) 708 709set(prefix "\$(cd \"\$(dirname \"\$0\")\"; pwd -P)/..") 710configure_file(xml2-config.in xml2-config @ONLY) 711install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xml2-config DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT development) 712 713set(XML_INCLUDEDIR "-I${CMAKE_INSTALL_FULL_INCLUDEDIR}/libxml2") 714set(XML_LIBDIR "-L${CMAKE_INSTALL_FULL_LIBDIR}") 715configure_file(xml2Conf.sh.in xml2Conf.sh @ONLY) 716install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xml2Conf.sh DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development) 717 718set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime) 719set(CPACK_COMPONENT_PROGRAMS_DEPENDS runtime) 720set(CPACK_DEB_COMPONENT_INSTALL ON) 721set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_DEPENDS "${PACKAGE_TARNAME}") 722set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "${PACKAGE_TARNAME}-dev") 723set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel") 724set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PACKAGE_URL}) 725set(CPACK_DEBIAN_PACKAGE_NAME ${PACKAGE_TARNAME}) 726set(CPACK_DEBIAN_PACKAGE_SECTION "devel") 727set(CPACK_DEBIAN_PROGRAMS_PACKAGE_DEPENDS "${PACKAGE_TARNAME}") 728set(CPACK_DEBIAN_PROGRAMS_PACKAGE_NAME "${PACKAGE_TARNAME}-utils") 729set(CPACK_DEBIAN_PROGRAMS_PACKAGE_SECTION "utils") 730set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME ${PACKAGE_TARNAME}) 731set(CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "${PACKAGE_TARNAME}-utils") 732set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs") 733set(CPACK_NSIS_PACKAGE_NAME ${PACKAGE_STRING}) 734set(CPACK_NSIS_URL_INFO_ABOUT ${PACKAGE_URL}) 735set(CPACK_PACKAGE_CONTACT ${PACKAGE_BUGREPORT}) 736set(CPACK_PACKAGE_DISPLAY_NAME ${PACKAGE_STRING}) 737set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PACKAGE_TARNAME}-${PACKAGE_VERSION}") 738set(CPACK_PACKAGE_NAME ${PACKAGE_TARNAME}) 739set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) 740set(CPACK_PACKAGE_VERSION_MAJOR ${LIBXML_MAJOR_VERSION}) 741set(CPACK_PACKAGE_VERSION_MINOR ${LIBXML_MINOR_VERSION}) 742set(CPACK_PACKAGE_VERSION_PATCH ${LIBXML_MICRO_VERSION}) 743set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/Copyright) 744set(CPACK_RPM_COMPONENT_INSTALL ON) 745set(CPACK_RPM_development_PACKAGE_NAME "${PACKAGE_NAME}-devel") 746set(CPACK_RPM_development_PACKAGE_REQUIRES "${PACKAGE_NAME}") 747set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") 748set(CPACK_RPM_PACKAGE_NAME ${PACKAGE_TARNAME}) 749set(CPACK_RPM_PACKAGE_URL ${PACKAGE_URL}) 750set(CPACK_RPM_programs_PACKAGE_NAME "${PACKAGE_NAME}-utils") 751set(CPACK_RPM_programs_PACKAGE_REQUIRES "${PACKAGE_NAME}") 752set(CPACK_RPM_runtime_PACKAGE_NAME "${PACKAGE_NAME}") 753set(CPACK_RPM_runtime_PACKAGE_SUGGESTS "${PACKAGE_NAME}-utils") 754 755include(CPack) 756