project (libxml2) cmake_minimum_required(VERSION 3.13) add_library (libxml2 "") if (BUILD_SHARED_LIBS) message (STATUS "Building shared library libxml2") else (BUILD_SHARED_LIBS) message (STATUS "Building static library libxml2") target_compile_definitions (libxml2 PUBLIC LIBXML_STATIC) endif (BUILD_SHARED_LIBS) if (WIN32) target_compile_definitions (libxml2 PRIVATE NOLIBTOOL) endif (WIN32) #Options that control the behaviour of the library option (WITH_TRIO "TRIO" OFF) option (WITH_THREADS "Threads" OFF) option (WITH_THREAD_ALLOC "ThreadAlloc" OFF) option (WITH_TREE "Tree" ON) option (WITH_OUTPUT "Output" ON) option (WITH_PUSH "Push" ON) option (WITH_READER "Reader" ON) option (WITH_WRITER "Writer" ON) option (WITH_SAX1 "SAX1" ON) option (WITH_FTP "FTP" ON) option (WITH_HTTP "HTTP" ON) option (WITH_VALID "Valid" ON) option (WITH_HTML "HTML" ON) option (WITH_LEGACY "Legacy" ON) option (WITH_C14N "C14N" ON) option (WITH_CATALOG "Catalog" ON) option (WITH_DOCB "SGML docbook support" ON) option (WITH_XPATH "Xpath" ON) option (WITH_XPTR "Xptr" ON) option (WITH_XINCLUDE "XInclude" ON) option (WITH_ICONV "iconv" ON) option (WITH_ICU "icu support" OFF) option (WITH_ISO8859X "ISO-8859-X" OFF) option (WITH_DEBUG "Debugging" ON) option (WITH_MEM_DEBUG "Memory debugging" OFF) option (WITH_RUN_DEBUG "Runtime debugging" OFF) option (WITH_REGEXPS "Regular expressions" ON) option (WITH_SCHEMAS "Schema validation" ON) option (WITH_SCHEMATRON "Schematron validation" ON) option (WITH_MODULES "Modules interface" ON) option (WITH_ZLIB "Zlib support" OFF) option (WITH_LZMA "Lzma support" OFF) option (WITH_WALKER "Walker" ON) option (WITH_PATTERN "Pattern" ON) if (WITH_THREADS) target_compile_definitions (libxml2 PRIVATE _REENTRANT) endif (WITH_THREADS) #Generate config.h include (CheckIncludeFiles) include (CheckFunctionExists) include (CheckCSourceCompiles) check_include_files (arpa/inet.h HAVE_ARPA_INET_H) check_include_files (arpa/nameser.h HAVE_ARPA_NAMESER_H) check_include_files (ctype.h HAVE_CTYPE_H) check_include_files (dirent.h HAVE_DIRENT_H) check_include_files (dlfcn.h HAVE_DLFCN_H) check_include_files (dl.h HAVE_DL_H) check_include_files (errno.h HAVE_ERRNO_H) check_include_files (fcntl.h HAVE_FCNTL_H) check_include_files (float.h HAVE_FLOAT_H) check_include_files (fp_class.h HAVE_FP_CLASS_H) check_include_files (ieeefp.h HAVE_IEEEFP_H) check_include_files (inttypes.h HAVE_INTTYPES_H) check_include_files (limits.h HAVE_LIMITS_H) check_include_files (lzma.h HAVE_LZMA_H) check_include_files (malloc.h HAVE_MALLOC_H) check_include_files (math.h HAVE_MATH_H) check_include_files (memory.h HAVE_MEMORY_H) check_include_files (nan.h HAVE_NAN_H) check_include_files (ndir.h HAVE_NDIR_H) check_include_files (netdb.h HAVE_NETDB_H) check_include_files (netinet/in.h HAVE_NETINET_IN_H) check_include_files (poll.h HAVE_POLL_H) check_include_files (pthread.h HAVE_PTHREAD_H) check_include_files (resolv.h HAVE_RESOLV_H) check_include_files (signal.h HAVE_SIGNAL_H) check_include_files (stdarg.h HAVE_STDARG_H) check_include_files (stdint.h HAVE_STDINT_H) check_include_files (stdlib.h HAVE_STDLIB_H) check_include_files (strings.h HAVE_STRINGS_H) check_include_files (string.h HAVE_STRING_H) check_include_files (sys/dir.h HAVE_SYS_DIR_H) check_include_files (sys/mman.h HAVE_SYS_MMAN_H) check_include_files (sys/ndir.h HAVE_SYS_NDIR_H) check_include_files (sys/select.h HAVE_SYS_SELECT_H) check_include_files (sys/socket.h HAVE_SYS_SOCKET_H) check_include_files (sys/stat.h HAVE_SYS_STAT_H) check_include_files (sys/timeb.h HAVE_SYS_TIMEB_H) check_include_files (sys/time.h HAVE_SYS_TIME_H) check_include_files (sys/types.h HAVE_SYS_TYPES_H) check_include_files (time.h HAVE_TIME_H) check_include_files (unistd.h HAVE_UNISTD_H) check_include_files (zlib.h HAVE_ZLIB_H) check_include_files ("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) check_function_exists (dlopen HAVE_DLOPEN) check_function_exists (finite HAVE_FINITE) check_function_exists (fpclass HAVE_FPCLASS) check_function_exists (fprintf HAVE_FPRINTF) check_function_exists (fp_class HAVE_FP_CLASS) check_function_exists (ftime HAVE_FTIME) check_function_exists (getaddrinfo HAVE_GETADDRINFO) check_function_exists (gettimeofday HAVE_GETTIMEOFDAY) check_function_exists (isascii HAVE_ISASCII) check_function_exists (isinf HAVE_ISINF) check_function_exists (isnan HAVE_ISNAN) check_function_exists (isnand HAVE_ISNAND) check_function_exists (localtime HAVE_LOCALTIME) check_function_exists (mmap HAVE_MMAP) check_function_exists (munmap HAVE_MUNMAP) check_function_exists (printf HAVE_PRINTF) check_function_exists (putenv HAVE_PUTENV) check_function_exists (rand HAVE_RAND) check_function_exists (rand_r HAVE_RAND_R) check_function_exists (shl_load HAVE_SHLLOAD) check_function_exists (signal HAVE_SIGNAL) check_function_exists (snprintf HAVE_SNPRINTF) check_function_exists (sprintf HAVE_SPRINTF) check_function_exists (srand HAVE_SRAND) check_function_exists (sscanf HAVE_SSCANF) check_function_exists (strdup HAVE_STRDUP) check_function_exists (strerror HAVE_STRERROR) check_function_exists (strftime HAVE_STRFTIME) check_function_exists (strndup HAVE_STRNDUP) check_function_exists (time HAVE_TIME) check_function_exists (va_copy HAVE_VA_COPY) check_function_exists (vfprintf HAVE_VFPRINTF) check_function_exists (vsnprintf HAVE_VSNPRINTF) check_function_exists (vsprintf HAVE_VSPRINTF) check_function_exists (_stat HAVE__STAT) check_function_exists (__va_copy HAVE___VA_COPY) check_c_source_compiles(" #include void a(va_list* ap) {}; int main() { va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1; return 0; } " VA_LIST_IS_ARRAY_TEST) if(VA_LIST_IS_ARRAY_TEST) set(VA_LIST_IS_ARRAY FALSE) else() set(VA_LIST_IS_ARRAY TRUE) endif() configure_file ( ${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h ) #BEGIN variables used by configure_file set (VERSION "2.9.3") set (LIBXML_VERSION_NUMBER "20903") set (LIBXML_VERSION_EXTRA "NONE") #END variables used by configure_file configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/include/libxml/xmlversion.h.in ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h ) target_include_directories (libxml2 PRIVATE $ PUBLIC $ $ ) if (MSVC) #With C89 we're forced to use non-secure functions target_compile_definitions (libxml2 PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE ) endif (MSVC) #Header files which form the public interface to the library. #They should be installed by "make install". #We must take care to use $ generator expressions in #order to prevent conversion to absolute paths as done by cmake 3.13 and #later. Absolute paths would conflict with our use of install(EXPORT...). #See cmake policy CMP0076 for the gory details. target_sources (libxml2 PUBLIC $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ) target_sources (libxml2 PRIVATE buf.h config.h elfgcchack.h enc.h save.h timsort.h trio.h triodef.h trionan.h triop.h triostr.h xzlib.h ) target_sources (libxml2 PRIVATE buf.c c14n.c catalog.c chvalid.c debugXML.c dict.c DOCBparser.c encoding.c entities.c error.c globals.c hash.c HTMLparser.c HTMLtree.c legacy.c list.c nanoftp.c nanohttp.c parser.c parserInternals.c pattern.c relaxng.c SAX2.c SAX.c schematron.c threads.c tree.c uri.c valid.c xinclude.c xlink.c xmlIO.c xmlmemory.c xmlreader.c xmlregexp.c xmlmodule.c xmlsave.c xmlschemas.c xmlschemastypes.c xmlunicode.c xmlwriter.c xpath.c xpointer.c xmlstring.c ) if (WITH_THREADS) find_package(Threads REQUIRED) endif (WITH_THREADS) if (WITH_ICONV) find_package (Iconv REQUIRED) target_link_libraries (libxml2 PUBLIC Iconv::Iconv) endif (WITH_ICONV) if (WITH_ICU) find_package (ICU REQUIRED) target_link_libraries (libxml2 ${ICU_LIBRARIES}) target_include_directories (libxml2 PRIVATE ${ICU_INCLUDE_DIRS}) endif (WITH_ICU) if (WITH_ZLIB) find_package (ZLIB REQUIRED) target_link_libraries (libxml2 PRIVATE zlib::zlib) endif (WITH_ZLIB) if (WITH_LZMA) find_package (LibLZMA REQUIRED) target_link_libraries (libxml2 PRIVATE ${LIBLZMA_LIBRARIES}) target_include_directories (libxml2 ${LIBLZMA_INCLUDE_DIRS}) endif (WITH_LZMA) install (TARGETS libxml2 EXPORT libxml-config ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include) install (EXPORT libxml-config DESTINATION cmake NAMESPACE libxml2::) install (FILES $ ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h DESTINATION include/libxml)