Skip to content

Commit 12b1c7c

Browse files
authored
Use CMake FetchContent for curl (#73)
1 parent 5c53143 commit 12b1c7c

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

CMakeLists.txt

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
3838
endif ()
3939
endif()
4040

41-
include(ProcessorCount)
42-
ProcessorCount(NUM_PROCESSORS)
43-
set(MAKE_JOB_COUNT ${NUM_PROCESSORS} CACHE STRING "Number of jobs to use when building libcurl")
44-
4541
function(add_sanitizers)
4642
add_compile_options(-fsanitize=address)
4743
add_link_options(-fsanitize=address)
@@ -64,17 +60,7 @@ if (BUILD_TESTING)
6460
set(CMAKE_BUILD_TYPE "Debug")
6561
endif()
6662

67-
include (ExternalProject)
68-
ExternalProject_Add(curl
69-
URL "https://github.com/curl/curl/releases/download/curl-7_85_0/curl-7.85.0.tar.gz"
70-
URL_MD5 "4e9eb4f434e9be889e510f038754d3de"
71-
BUILD_IN_SOURCE 1
72-
DOWNLOAD_EXTRACT_TIMESTAMP 0
73-
SOURCE_DIR ${CMAKE_BINARY_DIR}/curl
74-
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
75-
BUILD_COMMAND make -j${MAKE_JOB_COUNT}
76-
INSTALL_COMMAND make install
77-
)
63+
include(cmake/curl.cmake)
7864

7965
if (APPLE)
8066
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
@@ -206,16 +192,13 @@ target_sources(dd_trace_cpp-objects PUBLIC
206192
src/datadog/w3c_propagation.h
207193
)
208194

209-
add_dependencies(dd_trace_cpp-objects curl)
210-
211-
# Make the build libcurl visible.
212-
include_directories(${CMAKE_BINARY_DIR}/include)
195+
add_dependencies(dd_trace_cpp-objects libcurl)
213196

214197
# Linking this library requires libcurl and threads.
215198
find_package(Threads REQUIRED)
216199
target_link_libraries(dd_trace_cpp-objects
217200
PUBLIC
218-
${CMAKE_BINARY_DIR}/lib/libcurl.a
201+
libcurl
219202
PUBLIC
220203
Threads::Threads
221204
${COVERAGE_LIBRARIES}

cmake/curl.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
include(FetchContent)
3+
4+
# No need to build curl executable
5+
SET(BUILD_CURL_EXE OFF)
6+
SET(BUILD_SHARED_LIBS OFF)
7+
SET(BUILD_STATIC_LIBS ON)
8+
9+
# Disables all protocols except HTTP
10+
SET(HTTP_ONLY ON)
11+
SET(CURL_ENABLE_SSL OFF)
12+
SET(CURL_BROTLI OFF)
13+
SET(CURL_ZSTD OFF)
14+
SET(USE_ZLIB OFF)
15+
SET(USE_LIBIDN2 OFF)
16+
SET(CURL_USE_LIBSSH2 OFF)
17+
SET(CURL_USE_LIBPSL OFF)
18+
SET(CURL_DISABLE_HSTS ON)
19+
20+
FetchContent_Declare(
21+
curl
22+
URL "https://github.com/curl/curl/releases/download/curl-7_85_0/curl-7.85.0.tar.gz"
23+
URL_MD5 "4e9eb4f434e9be889e510f038754d3de"
24+
)
25+
26+
FetchContent_MakeAvailable(curl)

0 commit comments

Comments
 (0)