Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/cmake/caches/Release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)

set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
set_final_stage_var(LLVM_USE_STATIC_LIBXML2 "ON" BOOL)
if (LLVM_RELEASE_ENABLE_LTO)
set_final_stage_var(LLVM_ENABLE_FATLTO "ON" BOOL)
set_final_stage_var(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/release_cpack_pre_build_strip_lto.cmake" STRING)
Expand Down
7 changes: 6 additions & 1 deletion lldb/source/Host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ set(EXTRA_LIBS)
if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
list(APPEND EXTRA_LIBS kvm)
endif()
if (LLDB_ENABLE_LIBXML2)
if (LLDB_ENABLE_LIBXML2 AND NOT LLVM_USE_STATIC_LIBXML2)
list(APPEND EXTRA_LIBS LibXml2::LibXml2)
endif()
if (HAVE_LIBDL)
Expand Down Expand Up @@ -190,3 +190,8 @@ add_lldb_library(lldbHost NO_PLUGIN_DEPENDENCIES
${LLDB_LIBEDIT_LIBS}
)

if (LLDB_ENABLE_LIBXML2 AND LLVM_USE_STATIC_LIBXML2)
target_link_libraries(lldbHost PRIVATE ${LIBXML2_LIBRARIES})
target_include_directories(lldbHost PUBLIC ${LIBXML2_INCLUDE_DIRS})
add_dependencies(lldbHost libxml2)
endif()
Comment on lines +193 to +197
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of using the interface libraries (like LibXml2::LibXml2) is to simplify our CMake code where we don't need to manually update the list include directories and link libraries and can instead depend on a single target, but this negates that benefit, even worse now we have to both depend on the interface target and manually update the list include directories and link libraries everywhere where we depend on libxml2.

2 changes: 2 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ set(LLVM_TARGET_ARCH "host"

set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")

set(LLVM_USE_STATIC_LIBXML2 "OFF" CACHE BOOL "Use static version of libxml2. Can be ON, or OFF")

option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)

option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
Expand Down
39 changes: 24 additions & 15 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,31 @@ if(LLVM_ENABLE_ZSTD)
endif()

if(LLVM_ENABLE_LIBXML2)
if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON)
find_package(LibXml2 REQUIRED)
elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
find_package(LibXml2)
if(APPLE)
set(LLVM_USE_STATIC_LIBXML2 OFF)
endif()
if(LibXml2_FOUND)
# Check if libxml2 we found is usable; for example, we may have found a 32-bit
# library on a 64-bit system which would result in a link-time failure.
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES})
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS})
check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)
cmake_pop_check_state()
if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2)
message(FATAL_ERROR "Failed to configure libxml2")

if(LLVM_USE_STATIC_LIBXML2)
include(LibXml2)
set(HAVE_LIBXML2 1)
else()
if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON)
find_package(LibXml2 REQUIRED)
elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
find_package(LibXml2)
endif()
if(LibXml2_FOUND)
# Check if libxml2 we found is usable; for example, we may have found a 32-bit
# library on a 64-bit system which would result in a link-time failure.
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES})
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS})
check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)
cmake_pop_check_state()
if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2)
message(FATAL_ERROR "Failed to configure libxml2")
endif()
endif()
endif()
set(LLVM_ENABLE_LIBXML2 "${HAVE_LIBXML2}")
Expand Down
31 changes: 31 additions & 0 deletions llvm/cmake/modules/LibXml2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include(ExternalProject)

if (NOT LIBXML2_PREFIX)
set (LIBXML2_PREFIX libxml2)
endif()

set(LIBXML2_PATH ${CMAKE_CURRENT_BINARY_DIR}/${LIBXML2_PREFIX}/src/${LIBXML2_PREFIX})
set(LIBXML2_LIB_PATH ${LIBXML2_PATH}-build/libxml2.a)

ExternalProject_Add(${LIBXML2_PREFIX}
PREFIX ${LIBXML2_PREFIX}
GIT_REPOSITORY https://github.com/GNOME/libxml2.git
GIT_TAG v2.15.1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=OFF
-DLIBXML2_WITH_PYTHON=OFF
-DLIBXML2_WITH_PROGRAMS=OFF
-DLIBXML2_WITH_TESTS=OFF
-DLIBXML2_WITH_LZMA=OFF
-DLIBXML2_WITH_ZLIB=OFF
CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
BUILD_BYPRODUCTS ${LIBXML2_LIB_PATH}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
)
Comment on lines +10 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want the build system to automatically clone and build a dependency without my approval (and what's worse, control this behavior by a flag such as LLVM_USE_STATIC_LIBXML2). This won't work on machines don't allow internet access during build stage (our bots actually fall into that category, and they statically link libxml2 already). I may also want to reuse an existing build of libxml2 or configure it in a specific way (for example enabling the zlib support or enabling LTO) which this implementation doesn't let me.


set(LIBXML2_INCLUDE_DIRS ${LIBXML2_PATH}/include ${LIBXML2_PATH}-build)
set(LIBXML2_LIBRARIES ${LIBXML2_LIB_PATH})
set(LIBXML2_DEFINITIONS "")
29 changes: 20 additions & 9 deletions llvm/lib/WindowsManifest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(GetLibraryName)

if(LLVM_ENABLE_LIBXML2)
if(LLVM_ENABLE_LIBXML2 AND NOT LLVM_USE_STATIC_LIBXML2)
set(imported_libs LibXml2::LibXml2)
endif()

Expand All @@ -18,17 +18,28 @@ add_llvm_component_library(LLVMWindowsManifest
Support
)

if(LLVM_ENABLE_LIBXML2 AND LLVM_USE_STATIC_LIBXML2)
target_link_libraries(LLVMWindowsManifest PRIVATE ${LIBXML2_LIBRARIES})
target_include_directories(LLVMWindowsManifest PRIVATE ${LIBXML2_INCLUDE_DIRS})
add_dependencies(LLVMWindowsManifest libxml2)
endif()

# This block is only needed for llvm-config. When we deprecate llvm-config and
# move to using CMake export, this block can be removed.
if(LLVM_ENABLE_LIBXML2)
# CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION_${build_type})
endif()
if(NOT libxml2_library)
get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION)
if(LLVM_USE_STATIC_LIBXML2)
# When using static libxml2 built via ExternalProject, use the library path directly
get_library_name(${LIBXML2_LIBRARIES} libxml2_library)
else()
# CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION_${build_type})
endif()
if(NOT libxml2_library)
get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION)
endif()
get_library_name(${libxml2_library} libxml2_library)
endif()
get_library_name(${libxml2_library} libxml2_library)
set_property(TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS ${libxml2_library})
endif()
Loading