From 51715474d7ba8617138f9e22b8aee3b2dbfdddcb Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 15 Jul 2025 08:12:36 +1000 Subject: [PATCH] CMake: Improve handling of dl. --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f1959a..f9bea30f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,10 +457,12 @@ endif() set(COMMON_LINK_LIBRARIES) if (UNIX) - if(NOT CMAKE_SYSTEM_NAME STREQUAL "NetBSD") - list(APPEND COMMON_LINK_LIBRARIES dl) # For dlopen(), etc. Most compilers will link to this by default, but some may not. + # Not all platforms actually use a separate "dl" library, notably NetBSD and OpenBSD. + find_library(LIB_DL "dl") + if(LIB_DL) + list(APPEND COMMON_LINK_LIBRARIES dl) # For dlopen(), etc. Most compilers will link to this by default, but some may not. endif() - + list(APPEND COMMON_LINK_LIBRARIES pthread) # Some compilers will not link to pthread by default so list it here just in case. list(APPEND COMMON_LINK_LIBRARIES m)