diff --git a/CMakeLists.txt b/CMakeLists.txt index a372918c..b0b691bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,12 +99,28 @@ set(PACKAGE_TARNAME "libxml2") set(PACKAGE_URL "https://gitlab.gnome.org/GNOME/libxml2") set(PACKAGE_VERSION ${VERSION}) +if(LIBXML2_WITH_ICONV) + find_package(Iconv REQUIRED) +endif() + +if(LIBXML2_WITH_ICU) + find_package(ICU REQUIRED COMPONENTS data i18n uc) +endif() + +if(LIBXML2_WITH_LZMA) + find_package(LibLZMA REQUIRED) +endif() + if(LIBXML2_WITH_THREADS) find_package(Threads REQUIRED) set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT}) list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads) endif() +if(LIBXML2_WITH_ZLIB) + find_package(ZLIB REQUIRED) +endif() + if (NOT MSVC) check_c_source_compiles(" void __attribute__((destructor)) @@ -361,7 +377,6 @@ if(WIN32) endif() if(LIBXML2_WITH_ICONV) - find_package(Iconv REQUIRED) target_link_libraries(LibXml2 PUBLIC Iconv::Iconv) if(NOT Iconv_IS_BUILT_IN) set(ICONV_LIBS "-liconv") @@ -369,35 +384,31 @@ if(LIBXML2_WITH_ICONV) endif() if(LIBXML2_WITH_ICU) - pkg_check_modules(ICU IMPORTED_TARGET icu-i18n) - if(ICU_FOUND) - target_link_libraries(LibXml2 PRIVATE PkgConfig::ICU) - list(APPEND XML_PC_REQUIRES icu-i18n) + target_link_libraries(LibXml2 PRIVATE ICU::data ICU::i18n ICU::uc) + if(WIN32) + set(ICU_LDFLAGS "-licudt -licuin -licuuc") else() - find_package(ICU REQUIRED COMPONENTS data i18n uc) - target_link_libraries(LibXml2 PRIVATE ICU::data ICU::i18n ICU::uc) - if(WIN32) - set(ICU_LDFLAGS "-licudt -licuin -licuuc") - else() - set(ICU_LDFLAGS "-licudata -licui18n -licuuc") - endif() - list(APPEND XML_PC_LIBS "${ICU_LDFLAGS}") + set(ICU_LDFLAGS "-licudata -licui18n -licuuc") endif() list(APPEND XML_PRIVATE_LIBS "${ICU_LDFLAGS}") + pkg_check_modules(ICU_PC IMPORTED_TARGET icu-i18n) + if(ICU_PC_FOUND) + list(APPEND XML_PC_REQUIRES icu-i18n) + else() + list(APPEND XML_PC_LIBS "${ICU_LDFLAGS}") + endif() endif() if(LIBXML2_WITH_LZMA) - pkg_check_modules(LibLZMA IMPORTED_TARGET liblzma) - if(LibLZMA_FOUND) - target_link_libraries(LibXml2 PRIVATE PkgConfig::LibLZMA) + target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA) + set(LibLZMA_LDFLAGS "-llzma") + list(APPEND XML_PRIVATE_LIBS "${LibLZMA_LDFLAGS}") + pkg_check_modules(LibLZMA_PC IMPORTED_TARGET liblzma) + if(LibLZMA_PC_FOUND) list(APPEND XML_PC_REQUIRES liblzma) else() - find_package(LibLZMA REQUIRED) - target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA) - set(LibLZMA_LDFLAGS "-llzma") list(APPEND XML_PC_LIBS "${LibLZMA_LDFLAGS}") endif() - list(APPEND XML_PRIVATE_LIBS "${LibLZMA_LDFLAGS}") endif() if(LIBXML2_WITH_THREADS) @@ -405,17 +416,15 @@ if(LIBXML2_WITH_THREADS) endif() if(LIBXML2_WITH_ZLIB) - pkg_check_modules(ZLIB IMPORTED_TARGET zlib) - if(ZLIB_FOUND) - target_link_libraries(LibXml2 PRIVATE PkgConfig::ZLIB) + target_link_libraries(LibXml2 PRIVATE ZLIB::ZLIB) + set(ZLIB_LDFLAGS "-lz") + list(APPEND XML_PRIVATE_LIBS "${ZLIB_LDFLAGS}") + pkg_check_modules(ZLIB_PC IMPORTED_TARGET zlib) + if(ZLIB_PC_FOUND) list(APPEND XML_PC_REQUIRES zlib) else() - find_package(ZLIB REQUIRED) - target_link_libraries(LibXml2 PRIVATE ZLIB::ZLIB) - set(ZLIB_LDFLAGS "-lz") list(APPEND XML_PC_LIBS "${ZLIB_LDFLAGS}") endif() - list(APPEND XML_PRIVATE_LIBS "${ZLIB_LDFLAGS}") endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")