From 15c4871c0a07a200d363262410733adec8d64c89 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 21 May 2025 15:11:07 +0200 Subject: [PATCH] build: fix Descent3 program link failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case httplibConfig.cmake is absent, there is still a link failure because -lcpp-httplib appears nowhere on the command-line. ``` /usr/include/c++/14/bits/unique_ptr.h:1077:(.text+0x7ae9): undefined reference to `httplib::Client::Client(std::__cxx11::basic_string, std::allocator > const&)' /usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: /usr/include/c++/14/bits/unique_ptr.h:93:(.text+0x7b0b): undefined reference to `httplib::Client::~Client()' ``` A header is not enough to get the build job done. But… it turns out cpp-httplib can either be built as a classic header + library combo, or installed in a header-only fashion. *sigh* Deal with it. Fixes: 88e487c724e6811f70c1a74dbbbb2944aad0c81e --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6129cb..870b87be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,9 +186,16 @@ if (TARGET httplib::httplib) else() # Some Linux distributions do not package httplibConfig.cmake, so find the header manually find_file(CPP_HTTPLIB_HEADER httplib.h REQUIRED) + find_library(CPP_HTTPLIB_LIB cpp-httplib QUIET) # The target httplib::httplib cannot be created manually, so rename it add_library(httplib INTERFACE ${CPP_HTTPLIB_HEADER}) + + # And some Linux distributions build httplib as header-only, + # and some as header+library. What a mess! + if (NOT ${CPP_HTTPLIB_LIB} STREQUAL "CPP_HTTPLIB_LIB-NOTFOUND") + target_link_libraries(httplib INTERFACE ${CPP_HTTPLIB_LIB}) + endif () endif() find_package(ZLIB REQUIRED) find_package(plog REQUIRED)