Skip to content

Commit

Permalink
fix: DOWNLOAD_ONLY test
Browse files Browse the repository at this point in the history
  • Loading branch information
Avus-c committed Jul 18, 2024
1 parent 77dc92f commit 6f2cf67
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ function(CPMAddPackage)
"${CPM_ARGS_NAME}" ${fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS}"
)

cpm_fetch_package("${CPM_ARGS_NAME}" populated)
cpm_fetch_package("${CPM_ARGS_NAME}" ${DOWNLOAD_ONLY} populated ${CPM_ARGS_UNPARSED_ARGUMENTS})
if(CPM_SOURCE_CACHE AND download_directory)
file(LOCK ${download_directory}/../cmake.lock RELEASE)
endif()
Expand Down Expand Up @@ -1080,7 +1080,7 @@ endfunction()

# downloads a previously declared package via FetchContent and exports the variables
# `${PACKAGE}_SOURCE_DIR` and `${PACKAGE}_BINARY_DIR` to the parent scope
function(cpm_fetch_package PACKAGE populated)
function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated)
set(${populated}
FALSE
PARENT_SCOPE
Expand All @@ -1096,7 +1096,20 @@ function(cpm_fetch_package PACKAGE populated)

if(NOT ${lower_case_name}_POPULATED)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
FetchContent_MakeAvailable(${PACKAGE})
if(DOWNLOAD_ONLY)
# MakeAvailable will call add_subdirectory internally which is not what we want when
# DOWNLOAD_ONLY is set. Populate will only download the dependency without adding it to the
# build
FetchContent_Populate(
${PACKAGE}
SOURCE_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-src"
BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild"
${ARGN}
)
else()
FetchContent_MakeAvailable(${PACKAGE})
endif()
else()
FetchContent_Populate(${PACKAGE})
endif()
Expand Down

0 comments on commit 6f2cf67

Please sign in to comment.