Skip to content

Commit

Permalink
Handle static CURL
Browse files Browse the repository at this point in the history
(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
  • Loading branch information
Flamefire committed May 17, 2024
1 parent 02dd2a3 commit fa68764
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit fa68764

Please sign in to comment.