I am building curl
and curlpp
from source in my CMakeLists.txt
using FetchContent
to use in an executable later in my CMakeLists.txt
.
cmake_minimum_required(VERSION 3.17)
project(myproject VERSION 1.0.0)
include(FetchContent)
include(CMakePrintHelpers)
cmake_print_variables(CMAKE_CXX_FLAGS)
if (WIN32)
set(CMAKE_USE_SCHANNEL ON)
endif()
# --- CURL
FetchContent_Declare(curl
URL https://github.com/curl/curl/releases/download/curl-7_75_0/curl-7.75.0.tar.xz
URL_HASH SHA256=fe0c49d8468249000bda75bcfdf9e30ff7e9a86d35f1a21f428d79c389d55675 # the file hash for curl-7.75.0.tar.xz
USES_TERMINAL_DOWNLOAD TRUE)
FetchContent_MakeAvailable(curl)
add_library(curl_int INTERFACE)
target_link_libraries(curl_int INTERFACE libcurl)
target_include_directories(curl_int INTERFACE ${curl_SOURCE_DIR}/include ${curl_BINARY_DIR}/include/curl)
add_library(CURL::mylibcurl ALIAS curl_int)
set(CURL_INCLUDE_DIR
${curl_SOURCE_DIR}/include
)
# --- CURL C++
FetchContent_Declare(curlpp
GIT_REPOSITORY https://github.com/jpbarrette/curlpp.git
)
FetchContent_MakeAvailable(curlpp) # ----> Error occurs here
cmake_print_variables(curlpp_SOURCE_DIR curlpp_BINARY_DIR)
add_library(curlpp_int INTERFACE)
target_link_libraries(curlpp_int INTERFACE libcurlpp CURL::mylibcurl)
target_include_directories(curlpp_int INTERFACE ${curlpp_SOURCE_DIR}/include ${curlpp_BINARY_DIR}/include/curl)
add_library(CURLPP::mylibcurlpp ALIAS curlpp_int)
set(CURLPP_INCLUDE_DIR
${curlpp_SOURCE_DIR}/include
)
set(CURLPP_LIB_DIR
${curlpp_BINARY_DIR})
cmake_print_variables(CURLPP_LIB_DIR)
cmake_print_variables(CURLPP::mylibcurlpp)
# The rest of CMakeLists.txt is omitted
However, during cmake build, when it executes FetchContent_MakeAvailable(curlpp)
, I get a complaint about
Could NOT find CURL (missing: CURL_LIBRARY)
I am linking curlpp
with curl
by target_link_libraries(curlpp_int INTERFACE libcurlpp CURL::mylibcurl)
and was expecting it to be able to find it.
How could I solve this?
In the CMake of curlpp, the CURL library is required and fetched if not available:
I could think of two problems here, but also more information might be helpful, for example, if your error is thrown in line 72 or above that.