From 323ab8810e882fe465f773904e46e0b9ea8cfb43 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 14 Sep 2025 15:50:50 +0100 Subject: [PATCH] cmake: consolidate non-linux library handling Move the handling to the top-level, adding it _once_ to EXTRA_LIBS. Thus avoiding some duplication across the board. Note that final handling varies a bit, namely: - OpenBSD/intl should be handled via the existing cmake/FindGettext.cmake - Darwin/resolv should not be needed since commit e98a32373 ("core: check if res_init requires linking with libresolv") - the backtrace/execinfo handling has been consolidated and moved In the unlikely case of unwanted over-linking, the platforms can add `-Wl,--as-needed` to their linker flags. Something which is strongly encouraged and has been the default across multiple (linux) distros for years. Alternatively, if move quirks are needed they should be handled in a single place. Signed-off-by: Emil Velikov --- CMakeLists.txt | 19 +++++++++++++++++++ src/core/CMakeLists.txt | 8 -------- src/gui/curses/CMakeLists.txt | 16 ---------------- tests/fuzz/CMakeLists.txt | 21 --------------------- tests/unit/CMakeLists.txt | 11 ----------- 5 files changed, 19 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80e213221..67f43d123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,6 +311,25 @@ else() add_custom_target(translations COMMAND true) endif() +if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + find_library(EXECINFO_LIB_PATH execinfo /usr/local/lib) + set(CMAKE_REQUIRED_LIBRARIES "${EXECINFO_LIB_PATH}") + check_function_exists(backtrace HAVE_BACKTRACE) + list(APPEND EXTRA_LIBS "execinfo") +else() + check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE) +endif() + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") + list(APPEND EXTRA_LIBS "network") +else() + list(APPEND EXTRA_LIBS "pthread") +endif() + +if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") + list(APPEND EXTRA_LIBS "socket" "nsl") +endif() + list(APPEND EXTRA_LIBS "m") add_subdirectory(src) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 07ab0cc79..0f5747aeb 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -81,14 +81,6 @@ set(LIB_CORE_SRC include(CheckSymbolExists) check_symbol_exists(flock "sys/file.h" HAVE_FLOCK) -if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - find_library(EXECINFO_LIB_PATH execinfo /usr/local/lib) - set(CMAKE_REQUIRED_LIBRARIES "${EXECINFO_LIB_PATH}") - check_function_exists(backtrace HAVE_BACKTRACE) -else() - check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE) -endif() - if(ENABLE_ZSTD) include_directories(${LIBZSTD_INCLUDE_DIRS}) endif() diff --git a/src/gui/curses/CMakeLists.txt b/src/gui/curses/CMakeLists.txt index 1ec67614b..822504435 100644 --- a/src/gui/curses/CMakeLists.txt +++ b/src/gui/curses/CMakeLists.txt @@ -21,22 +21,6 @@ # along with WeeChat. If not, see . # -if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND HAVE_BACKTRACE) - list(APPEND EXTRA_LIBS "execinfo") -endif() - -if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") - list(APPEND EXTRA_LIBS "socket" "nsl") -endif() - -if(${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") - list(APPEND EXTRA_LIBS "network") -endif() - -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") - list(APPEND EXTRA_LIBS "pthread") -endif() - if(ENABLE_NCURSES) subdirs(normal) endif() diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 8d11137e6..a6f591ee3 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -40,27 +40,6 @@ if(NOT CYGWIN) add_definitions(-fPIC) endif() -if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND HAVE_BACKTRACE) - list(APPEND EXTRA_LIBS "execinfo") -endif() - -if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") - list(APPEND EXTRA_LIBS "socket" "nsl") -endif() - -if(${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") - list(APPEND EXTRA_LIBS "network") -endif() - -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") - list(APPEND EXTRA_LIBS "pthread") -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # link with resolv lib on macOS - list(APPEND EXTRA_LIBS "resolv") -endif() - list(APPEND FUZZ_TARGET_LINK weechat_core weechat_plugins diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index d54ca35de..f06b3006d 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -206,17 +206,6 @@ endif() add_library(weechat_unit_tests_plugins MODULE ${LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC}) -if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - list(APPEND EXTRA_LIBS "intl") - if(HAVE_BACKTRACE) - list(APPEND EXTRA_LIBS "execinfo") - endif() -endif() - -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") - list(APPEND EXTRA_LIBS "pthread") -endif() - # binary to run tests set(WEECHAT_TESTS_SRC tests.cpp tests.h