Skip to content
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

replace deprecated calls to FetchContent_Populate #570

Merged
34 changes: 30 additions & 4 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,36 @@ function(CPMAddPackage)
)

if(NOT CPM_SKIP_FETCH)
# CMake 3.28 added EXCLUDE and SYSTEM(3.25) to FetchContent_Declare.
# Calling FetchContent_MakeAvailable will than call add_subdirectory internally with the EXCLUDE
# and SYSTEM flags. No need for CPM to do this manually anymore.
set(fetchContentDeclareExtraArgs "")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
if(${CPM_ARGS_EXCLUDE_FROM_ALL})
list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL)
endif()
if(${CPM_ARGS_SYSTEM})
list(APPEND fetchContentDeclareExtraArgs SYSTEM)
endif()
# For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory
if(CPM_ARGS_OPTIONS)
foreach(OPTION ${CPM_ARGS_OPTIONS})
cpm_parse_option("${OPTION}")
set(${OPTION_KEY} "${OPTION_VALUE}")
endforeach()
endif()
endif()
cpm_declare_fetch(
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
"${CPM_ARGS_NAME}"
${fetchContentDeclareExtraArgs}
"${CPM_ARGS_UNPARSED_ARGUMENTS}"
)

cpm_fetch_package("${CPM_ARGS_NAME}" populated)
if(CPM_SOURCE_CACHE AND download_directory)
file(LOCK ${download_directory}/../cmake.lock RELEASE)
endif()
if(${populated})
if(${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.28.0")
cpm_add_subdirectory(
"${CPM_ARGS_NAME}"
"${DOWNLOAD_ONLY}"
Expand Down Expand Up @@ -980,7 +1002,7 @@ function(CPMGetPackageVersion PACKAGE OUTPUT)
endfunction()

# declares a package in FetchContent_Declare
function(cpm_declare_fetch PACKAGE VERSION INFO)
function(cpm_declare_fetch PACKAGE)
if(${CPM_DRY_RUN})
cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)")
return()
Expand Down Expand Up @@ -1071,7 +1093,11 @@ function(cpm_fetch_package PACKAGE populated)
string(TOLOWER "${PACKAGE}" lower_case_name)

if(NOT ${lower_case_name}_POPULATED)
FetchContent_Populate(${PACKAGE})
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
FetchContent_MakeAvailable(${PACKAGE})
else()
FetchContent_Populate(${PACKAGE})
endif()
set(${populated}
TRUE
PARENT_SCOPE
Expand Down
Loading