Skip to content

Commit

Permalink
Use CMake FetchContent for curl
Browse files Browse the repository at this point in the history
Add and expose curl as a cmake target
  • Loading branch information
dmehala committed Dec 1, 2023
1 parent 5c53143 commit b55655c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,7 @@ if (BUILD_TESTING)
set(CMAKE_BUILD_TYPE "Debug")
endif()

include (ExternalProject)
ExternalProject_Add(curl
URL "https://github.com/curl/curl/releases/download/curl-7_85_0/curl-7.85.0.tar.gz"
URL_MD5 "4e9eb4f434e9be889e510f038754d3de"
BUILD_IN_SOURCE 1
DOWNLOAD_EXTRACT_TIMESTAMP 0
SOURCE_DIR ${CMAKE_BINARY_DIR}/curl
CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/curl/configure --prefix=${CMAKE_BINARY_DIR} --disable-ftp --disable-ldap --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-smtp --disable-gopher --without-ssl --disable-crypto-auth --without-axtls --without-zlib --disable-rtsp --enable-shared=no --enable-static=yes --with-pic --without-brotli --without-libidn2
BUILD_COMMAND make -j${MAKE_JOB_COUNT}
INSTALL_COMMAND make install
)
include(cmake/curl.cmake)

if (APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
Expand Down Expand Up @@ -206,16 +196,13 @@ target_sources(dd_trace_cpp-objects PUBLIC
src/datadog/w3c_propagation.h
)

add_dependencies(dd_trace_cpp-objects curl)

# Make the build libcurl visible.
include_directories(${CMAKE_BINARY_DIR}/include)
add_dependencies(dd_trace_cpp-objects libcurl)

# Linking this library requires libcurl and threads.
find_package(Threads REQUIRED)
target_link_libraries(dd_trace_cpp-objects
PUBLIC
${CMAKE_BINARY_DIR}/lib/libcurl.a
libcurl
PUBLIC
Threads::Threads
${COVERAGE_LIBRARIES}
Expand Down
23 changes: 23 additions & 0 deletions cmake/curl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

include(FetchContent)

# No need to build curl executable
SET(BUILD_CURL_EXE OFF)
SET(BUILD_SHARED_LIBS OFF)
SET(BUILD_STATIC_LIBS ON)

# Disables all protocols except HTTP
SET(HTTP_ONLY ON)
SET(CURL_ENABLE_SSL OFF)
SET(CURL_BROTLI OFF)
SET(CURL_ZSTD OFF)
SET(USE_ZLIB OFF)
SET(USE_LIBIDN2 OFF)

FetchContent_Declare(
curl
URL "https://github.com/curl/curl/releases/download/curl-7_85_0/curl-7.85.0.tar.gz"
URL_MD5 "4e9eb4f434e9be889e510f038754d3de"
)

FetchContent_MakeAvailable(curl)

0 comments on commit b55655c

Please sign in to comment.