1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2026-01-26 21:41:34 +03:00

CMake: Fix dlopen check

Systems can have dlopen symbol in various libraries. For example, on
Haiku, dlopen is in 'root' library, which is linked by default.

The CMAKE_DL_LIBS variable is automatically set by CMake and contains
the name of the library or libraries that contain dynamic loading
functionality. CMakePushCheckState checks for the symbol in isolation,
so the required libraries variable can be modified.
This commit is contained in:
Peter Kokot
2025-07-17 16:01:11 +02:00
parent 4d69f91b25
commit a3d2c17713

View File

@@ -20,6 +20,7 @@ include(CheckStructHasMember)
include(CheckSymbolExists)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(CMakePushCheckState)
include(FindPkgConfig)
include(GNUInstallDirs)
@@ -323,10 +324,13 @@ target_include_directories(
)
if(LIBXML2_WITH_MODULES)
check_library_exists(dl dlopen "" HAVE_DLOPEN)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN)
cmake_pop_check_state()
if(HAVE_DLOPEN)
target_link_libraries(LibXml2 PRIVATE dl)
set(MODULE_LIBS "-ldl")
target_link_libraries(LibXml2 PRIVATE ${CMAKE_DL_LIBS})
list(TRANSFORM CMAKE_DL_LIBS PREPEND "-l" OUTPUT_VARIABLE MODULE_LIBS)
else()
check_library_exists(dld shl_load "" HAVE_SHLLOAD)
if(HAVE_SHLLOAD)