diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 950b2dc74a..3514d1614a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -446,32 +446,7 @@ if(NOT MINIMAL_BUILD) # libxml2 is required for IFCXML (optional) and SVGFILL (mandatory) clear_wasm_sysroot() if(IFCXML_SUPPORT) - if((NOT LIBXML2_INCLUDE_DIR AND NOT LIBXML2_LIBRARIES)) - # First try config mode (probably works with vcpkg, Conan, macOS brew installs, but not on ubuntu 22.04) - # CONFIG is provided using root path, so no need to clear sysroot here. - restore_wasm_sysroot() - find_package(LibXml2 QUIET CONFIG) - clear_wasm_sysroot() - - if(NOT LibXml2_FOUND) - # Fallback to CMake's builtin FindLibXml2 module (works on Ubuntu) - find_package(LibXml2 REQUIRED) - else() - message(STATUS "Found LibXml2 config: ${LibXml2_DIR}") - endif() - - if(TARGET LibXml2::LibXml2) - # Config mode already gives us the target - set(LIBXML2_LIBRARIES LibXml2::LibXml2) - get_target_property(LIBXML2_INCLUDE_DIR LibXml2::LibXml2 INTERFACE_INCLUDE_DIRECTORIES) - else() - # Module mode (Ubuntu) - set(LIBXML2_LIBRARIES ${LibXml2_LIBRARIES}) - set(LIBXML2_INCLUDE_DIR ${LibXml2_INCLUDE_DIRS}) - endif() - else() - find_package(LibXml2 REQUIRED) - endif() + find_package(LibXml2 REQUIRED) endif() restore_wasm_sysroot() endif() diff --git a/cmake/FindLibXml2.cmake b/cmake/FindLibXml2.cmake new file mode 100644 index 0000000000..86be2f565b --- /dev/null +++ b/cmake/FindLibXml2.cmake @@ -0,0 +1,44 @@ +# +# Input variables: +# - `LIBXML2_INCLUDE_DIR` +# - `LIBXML2_LIBRARIES` +# If input variables are not specified, try to find LibXml2 config. +# Input variables could also be provided as environment variables. +# +# Output variables: +# - `LIBXML2_INCLUDE_DIR` +# - `LIBXML2_LIBRARIES` +# + +# To avoid cyclic calls to this file +list(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}) + +if((NOT LIBXML2_INCLUDE_DIR AND NOT LIBXML2_LIBRARIES)) + # First try config mode (probably works with vcpkg, Conan, macOS brew installs, but not on ubuntu 22.04) + # CONFIG is provided using root path, so no need to clear sysroot here. + restore_wasm_sysroot() + find_package(LibXml2 QUIET CONFIG) + clear_wasm_sysroot() + + if(NOT LibXml2_FOUND) + # Fallback to CMake's builtin FindLibXml2 module (works on Ubuntu) + find_package(LibXml2 REQUIRED) + else() + message(STATUS "Found LibXml2 config: ${LibXml2_DIR}") + endif() + + if(TARGET LibXml2::LibXml2) + # Config mode already gives us the target + set(LIBXML2_LIBRARIES LibXml2::LibXml2) + get_target_property(LIBXML2_INCLUDE_DIR LibXml2::LibXml2 INTERFACE_INCLUDE_DIRECTORIES) + else() + # Module mode (Ubuntu) + set(LIBXML2_LIBRARIES ${LibXml2_LIBRARIES}) + set(LIBXML2_INCLUDE_DIR ${LibXml2_INCLUDE_DIRS}) + endif() +else() + find_package(LibXml2 REQUIRED) +endif() + +# Restore module path. +list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})