Index: lld/CMakeLists.txt =================================================================== --- lld/CMakeLists.txt +++ lld/CMakeLists.txt @@ -55,6 +55,10 @@ find_package(ZLIB) endif() + if(LLVM_ENABLE_LIBXML2) + find_package(LibXml2) + endif() + include(AddLLVM) include(TableGen) include(HandleLLVMOptions) Index: lld/test/CMakeLists.txt =================================================================== --- lld/test/CMakeLists.txt +++ lld/test/CMakeLists.txt @@ -6,7 +6,7 @@ llvm_canonicalize_cmake_booleans( LLVM_ENABLE_ZLIB - LLVM_LIBXML2_ENABLED + LLVM_ENABLE_LIBXML2 ) configure_lit_site_cfg( Index: lld/test/lit.cfg.py =================================================================== --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -88,10 +88,10 @@ # cvtres, which always accompanies it. Alternatively, check if we can use # libxml2 to merge manifests. if (lit.util.which('cvtres', config.environment['PATH']) or - config.llvm_libxml2_enabled): + config.have_libxml2): config.available_features.add('manifest_tool') -if config.llvm_libxml2_enabled: +if config.have_libxml2: config.available_features.add('libxml2') if config.have_dia_sdk: Index: lld/test/lit.site.cfg.py.in =================================================================== --- lld/test/lit.site.cfg.py.in +++ lld/test/lit.site.cfg.py.in @@ -7,7 +7,6 @@ config.llvm_obj_root = "@LLVM_BINARY_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_libs_dir = "@LLVM_LIBS_DIR@" -config.llvm_libxml2_enabled = @LLVM_LIBXML2_ENABLED@ config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.lld_obj_root = "@LLD_BINARY_DIR@" config.lld_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@" @@ -15,6 +14,7 @@ config.target_triple = "@TARGET_TRIPLE@" config.python_executable = "@Python3_EXECUTABLE@" config.have_zlib = @LLVM_ENABLE_ZLIB@ +config.have_libxml2 = @LLVM_ENABLE_LIBXML2@ config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@ # Support substitution of the tools and libs dirs with user parameters. This is Index: llvm/cmake/config-ix.cmake =================================================================== --- llvm/cmake/config-ix.cmake +++ llvm/cmake/config-ix.cmake @@ -149,25 +149,17 @@ endif() find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c) - set(LLVM_LIBXML2_ENABLED 0) - set(LIBXML2_FOUND 0) if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE)) - find_package(LibXml2) - if (LIBXML2_FOUND) - set(LLVM_LIBXML2_ENABLED 1) - if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})) - include_directories(${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}) - else() - include_directories(${LIBXML2_INCLUDE_DIR}) - endif() + if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON) + find_package(LibXml2 REQUIRED) + else() + find_package(LibXml2) endif() + set(LLVM_ENABLE_LIBXML2 "${LIBXML2_FOUND}") endif() else() set(LLVM_ENABLE_ZLIB FALSE) -endif() - -if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED) - message(FATAL_ERROR "Failed to congifure libxml2") + set(LLVM_ENABLE_LIBXML2 FALSE) endif() check_library_exists(xar xar_open "" HAVE_LIBXAR) Index: llvm/cmake/modules/LLVMConfig.cmake.in =================================================================== --- llvm/cmake/modules/LLVMConfig.cmake.in +++ llvm/cmake/modules/LLVMConfig.cmake.in @@ -51,7 +51,7 @@ set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@) -set(LLVM_LIBXML2_ENABLED @LLVM_LIBXML2_ENABLED@) +set(LLVM_ENABLE_LIBXML2 @LLVM_ENABLE_LIBXML2@) set(LLVM_WITH_Z3 @LLVM_WITH_Z3@) Index: llvm/include/llvm/Config/config.h.cmake =================================================================== --- llvm/include/llvm/Config/config.h.cmake +++ llvm/include/llvm/Config/config.h.cmake @@ -297,7 +297,7 @@ #cmakedefine01 LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO /* Define if libxml2 is supported on this platform. */ -#cmakedefine LLVM_LIBXML2_ENABLED ${LLVM_LIBXML2_ENABLED} +#cmakedefine LLVM_ENABLE_LIBXML2 ${LLVM_ENABLE_LIBXML2} /* Define to the extension used for shared libraries, say, ".so". */ #cmakedefine LTDL_SHLIB_EXT "${LTDL_SHLIB_EXT}" Index: llvm/lib/WindowsManifest/CMakeLists.txt =================================================================== --- llvm/lib/WindowsManifest/CMakeLists.txt +++ llvm/lib/WindowsManifest/CMakeLists.txt @@ -1,23 +1,31 @@ +if(LLVM_ENABLE_LIBXML2) + set(imported_libs LibXml2::LibXml2) +endif() + add_llvm_component_library(LLVMWindowsManifest WindowsManifestMerger.cpp ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/WindowsManifest - ${Backtrace_INCLUDE_DIRS}) - -if(LIBXML2_LIBRARIES) - target_link_libraries(LLVMWindowsManifest PUBLIC ${LIBXML2_LIBRARIES}) + ${Backtrace_INCLUDE_DIRS} + LINK_LIBS ${imported_libs}) - get_filename_component(xml2_library ${LIBXML2_LIBRARIES} NAME) - if (CMAKE_STATIC_LIBRARY_PREFIX AND - xml2_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$") - string(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" xml2_library ${xml2_library}) - string(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" xml2_library ${xml2_library}) - elseif (CMAKE_SHARED_LIBRARY_PREFIX AND - xml2_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$") - string(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" xml2_library ${xml2_library}) - string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" xml2_library ${xml2_library}) +if(LLVM_ENABLE_LIBXML2) + string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) + get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION_${build_type}) + if(NOT libxml2_library) + get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION) + endif() + get_filename_component(libxml2_library ${libxml2_library} NAME) + if(CMAKE_STATIC_LIBRARY_PREFIX AND CMAKE_STATIC_LIBRARY_SUFFIX AND + libxml2_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$") + string(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" libxml2_library ${libxml2_library}) + string(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" libxml2_library ${libxml2_library}) + endif() + if(CMAKE_SHARED_LIBRARY_PREFIX AND CMAKE_SHARED_LIBRARY_SUFFIX AND + libxml2_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$") + string(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" libxml2_library ${libxml2_library}) + string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" libxml2_library ${libxml2_library}) endif() - set_property(TARGET LLVMWindowsManifest PROPERTY - LLVM_SYSTEM_LIBS ${xml2_library}) + set_property(TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS ${libxml2_library}) endif() Index: llvm/lib/WindowsManifest/WindowsManifestMerger.cpp =================================================================== --- llvm/lib/WindowsManifest/WindowsManifestMerger.cpp +++ llvm/lib/WindowsManifest/WindowsManifestMerger.cpp @@ -16,7 +16,7 @@ #include -#if LLVM_LIBXML2_ENABLED +#if LLVM_ENABLE_LIBXML2 #include #endif @@ -41,7 +41,7 @@ private: static void errorCallback(void *Ctx, const char *Format, ...); Error getParseError(); -#if LLVM_LIBXML2_ENABLED +#if LLVM_ENABLE_LIBXML2 xmlDocPtr CombinedDoc = nullptr; std::vector MergedDocs; @@ -56,7 +56,7 @@ bool ParseErrorOccurred = false; }; -#if LLVM_LIBXML2_ENABLED +#if LLVM_ENABLE_LIBXML2 static constexpr std::pair MtNsHrefsPrefixes[] = { {"urn:schemas-microsoft-com:asm.v1", "ms_asmv1"}, Index: llvm/test/CMakeLists.txt =================================================================== --- llvm/test/CMakeLists.txt +++ llvm/test/CMakeLists.txt @@ -7,8 +7,8 @@ LLVM_ENABLE_FFI LLVM_ENABLE_THREADS LLVM_ENABLE_ZLIB + LLVM_ENABLE_LIBXML2 LLVM_INCLUDE_GO_TESTS - LLVM_LIBXML2_ENABLED LLVM_LINK_LLVM_DYLIB LLVM_TOOL_LTO_BUILD LLVM_USE_INTEL_JITEVENTS Index: llvm/test/lit.cfg.py =================================================================== --- llvm/test/lit.cfg.py +++ llvm/test/lit.cfg.py @@ -356,7 +356,7 @@ if config.enable_threads: config.available_features.add('thread_support') -if config.llvm_libxml2_enabled: +if config.have_libxml2: config.available_features.add('libxml2') if config.have_opt_viewer_modules: Index: llvm/test/lit.site.cfg.py.in =================================================================== --- llvm/test/lit.site.cfg.py.in +++ llvm/test/lit.site.cfg.py.in @@ -35,13 +35,13 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" config.have_zlib = @LLVM_ENABLE_ZLIB@ config.have_libxar = @HAVE_LIBXAR@ +config.have_libxml2 = @LLVM_ENABLE_LIBXML2@ config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@ config.enable_ffi = @LLVM_ENABLE_FFI@ config.build_examples = @LLVM_BUILD_EXAMPLES@ config.enable_threads = @LLVM_ENABLE_THREADS@ config.build_shared_libs = @BUILD_SHARED_LIBS@ config.link_llvm_dylib = @LLVM_LINK_LLVM_DYLIB@ -config.llvm_libxml2_enabled = @LLVM_LIBXML2_ENABLED@ config.llvm_host_triple = '@LLVM_HOST_TRIPLE@' config.host_arch = "@HOST_ARCH@" config.have_opt_viewer_modules = @LLVM_HAVE_OPT_VIEWER_MODULES@ Index: llvm/utils/gn/secondary/lld/test/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/lld/test/BUILD.gn +++ llvm/utils/gn/secondary/lld/test/BUILD.gn @@ -43,9 +43,9 @@ } if (llvm_enable_libxml2) { - extra_values += [ "LLVM_LIBXML2_ENABLED=1" ] + extra_values += [ "LLVM_ENABLE_LIBXML2=1" ] } else { - extra_values += [ "LLVM_LIBXML2_ENABLED=0" ] # Must be 0. + extra_values += [ "LLVM_ENABLE_LIBXML2=0" ] # Must be 0. } if (llvm_enable_zlib) { Index: llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -302,9 +302,9 @@ } if (llvm_enable_libxml2) { - values += [ "LLVM_LIBXML2_ENABLED=1" ] + values += [ "LLVM_ENABLE_LIBXML2=1" ] } else { - values += [ "LLVM_LIBXML2_ENABLED=" ] + values += [ "LLVM_ENABLE_LIBXML2=" ] } } Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/test/BUILD.gn +++ llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -162,9 +162,9 @@ } if (llvm_enable_libxml2) { - extra_values += [ "LLVM_LIBXML2_ENABLED=1" ] + extra_values += [ "LLVM_ENABLE_LIBXML2=1" ] } else { - extra_values += [ "LLVM_LIBXML2_ENABLED=0" ] # Must be 0. + extra_values += [ "LLVM_ENABLE_LIBXML2=0" ] # Must be 0. } if (llvm_enable_threads) {