From fa6876488fda3f8ba3be0771e65fc0917b7f1a95 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 17 May 2024 14:16:11 +0200 Subject: [PATCH] Handle static CURL (Especially) on Windows we need to define `CURL_STATICLIB` when linking to the static curl library or we get errors such as: > unresolved external symbol __imp__curl_free Check if the CURL target from the CMake config file (of CURL) was used and trust them to set that define. Otherwise apply a heuristic to detect whether static CURL was found and set the define in that case --- src/CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15fbd18..c6cfd11 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,8 +14,20 @@ endif() rttr_set_output_dir(RUNTIME ${RTTR_EXTRA_BINDIR}) add_executable(s25update ${_sources}) -target_include_directories(s25update SYSTEM PRIVATE ${CURL_INCLUDE_DIRS}) -target_link_libraries(s25update PRIVATE s25util::common ${CURL_LIBRARIES} BZip2::BZip2 Boost::filesystem Boost::nowide Boost::disable_autolinking) + +if (TARGET CURL::libcurl AND CURL_CONFIG) + target_link_libraries(s25update PRIVATE CURL::libcurl) +else() + target_include_directories(s25update SYSTEM PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(s25update PRIVATE ${CURL_LIBRARIES}) + # Heuristic if CURL is a static library and we need to add the define + if(CURL_LIBRARIES MATCHES "\.a$" OR CURL_LIBRARIES MATCHES "curl_a" OR (WIN32 AND NOT CURL_LIBRARIES MATCHES "_imp\.lib")) + target_compile_definitions(s25update PRIVATE "CURL_STATICLIB") + endif() +endif() + +target_include_directories(s25update SYSTEM PRIVATE) +target_link_libraries(s25update PRIVATE s25util::common BZip2::BZip2 Boost::filesystem Boost::nowide Boost::disable_autolinking) target_compile_features(s25update PRIVATE cxx_std_17) if(NOT PLATFORM_NAME OR NOT PLATFORM_ARCH) message(FATAL_ERROR "PLATFORM_NAME or PLATFORM_ARCH not set")