Skip to content

Fix getting CURL via FetchContent #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ add_subdirectory(extras)
# Seems simple.

message(STATUS "Looking for CURL")
find_package(CURL REQUIRED)
find_package(CURL)

if(CURL_FOUND)
message(STATUS "Found CURL version: ${CURL_VERSION_STRING}")
Expand All @@ -79,7 +79,24 @@ else()
message(STATUS "Fetching CURL")
include(FetchContent)
FetchContent_Declare(CURL GIT_REPOSITORY https://github.com/curl/curl.git)
FetchContent_MakeAvailable(CURL)
FetchContent_GetProperties(CURL)
if(NOT CURL_POPULATED)
FetchContent_Populate(CURL)
set(BUILD_CURL_EXE OFF CACHE BOOL "Disable building CURL executable")
set(BUILD_STATIC_CURL ON CACHE BOOL "Build CURL staticly")

set(BUILD_SHARED_LIBS_PREV ${BUILD_SHARED_LIBS})
set(BUILD_STATIC_LIBS_PREV ${BUILD_STATIC_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable building shared libs")
set(BUILD_STATIC_LIBS ON CACHE BOOL "Enable building static libs")
add_subdirectory(${curl_SOURCE_DIR} ${curl_BINARY_DIR})
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_PREV} CACHE BOOL "Restore BUILD_SHARED_LIBS" FORCE)
set(BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS_PREV} CACHE BOOL "Restore BUILD_STATIC_LIBS" FORCE)
unset(BUILD_SHARED_LIBS_PREV)
unset(BUILD_STATIC_LIBS_PREV)
endif()
set(CURL_INCLUDE_DIRS "${curl_SOURCE_DIR}/include")
set(CURL_LIBRARIES "libcurl")
endif()

# All following targets should search these directories for headers
Expand Down