Implement lazy-loaded libcurl

- Uses `dlopen` to load libcurl at runtime for better portability.
- Replaces the FETCH_AVAILABLE macro with download_available() check.
- Provides descriptive error messages when libcurl is missing.
This commit is contained in:
Manuel Barrio Linares
2026-02-09 12:56:31 -03:00
committed by Christoffer Lerno
parent c5d7a03859
commit de8a733c77
8 changed files with 131 additions and 60 deletions

View File

@@ -129,9 +129,6 @@ if(C3_USE_MIMALLOC)
)
FetchContent_MakeAvailable(mimalloc)
endif()
if (NOT WIN32)
find_package(CURL)
endif()
find_package(Git QUIET)
if(C3_USE_TB AND GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
@@ -606,12 +603,11 @@ if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,8388608")
endif ()
if (CURL_FOUND)
target_link_libraries(c3c ${CURL_LIBRARIES})
target_include_directories(c3c PRIVATE ${CURL_INCLUDE_DIRS})
target_compile_definitions(c3c PUBLIC CURL_FOUND=1)
else()
target_compile_definitions(c3c PUBLIC CURL_FOUND=0)
if (NOT WIN32)
# For dlopen support
if (CMAKE_DL_LIBS)
target_link_libraries(c3c ${CMAKE_DL_LIBS})
endif()
endif()