Skip to content

Commit

Permalink
Update CPM.cmake from 0.40.0 to 0.40.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Sep 28, 2024
1 parent a1ff010 commit 3c8e398
Showing 1 changed file with 55 additions and 11 deletions.
66 changes: 55 additions & 11 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if(NOT COMMAND cpm_message)
endfunction()
endif()

set(CURRENT_CPM_VERSION 0.40.0)
set(CURRENT_CPM_VERSION 0.40.2)

get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
if(CPM_DIRECTORY)
Expand Down Expand Up @@ -477,13 +477,16 @@ function(cpm_add_patches)
find_program(PATCH_EXECUTABLE patch)
if(WIN32 AND NOT PATCH_EXECUTABLE)
# The Windows git executable is distributed with patch.exe. Find the path to the executable, if
# it exists, then search `../../usr/bin` for patch.exe.
# it exists, then search `../usr/bin` and `../../usr/bin` for patch.exe.
find_package(Git QUIET)
if(GIT_EXECUTABLE)
get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY)
get_filename_component(extra_search_path ${extra_search_path} DIRECTORY)
get_filename_component(extra_search_path ${extra_search_path} DIRECTORY)
find_program(PATCH_EXECUTABLE patch HINTS "${extra_search_path}/usr/bin")
get_filename_component(extra_search_path_1up ${extra_search_path} DIRECTORY)
get_filename_component(extra_search_path_2up ${extra_search_path_1up} DIRECTORY)
find_program(
PATCH_EXECUTABLE patch HINTS "${extra_search_path_1up}/usr/bin"
"${extra_search_path_2up}/usr/bin"
)
endif()
endif()
if(NOT PATCH_EXECUTABLE)
Expand Down Expand Up @@ -862,14 +865,38 @@ function(CPMAddPackage)
)

if(NOT CPM_SKIP_FETCH)
# CMake 3.28 added EXCLUDE, SYSTEM (3.25), and SOURCE_SUBDIR (3.18) to FetchContent_Declare.
# Calling FetchContent_MakeAvailable will then internally forward these options to
# add_subdirectory. Up until these changes, we had to call FetchContent_Populate and
# add_subdirectory separately, which is no longer necessary and has been deprecated as of 3.30.
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()
if(DEFINED CPM_ARGS_SOURCE_SUBDIR)
list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR})
endif()
# For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory
if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY)
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)

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()
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 +1007,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 @@ -1056,7 +1083,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 @@ -1071,7 +1098,24 @@ 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")
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()
set(${populated}
TRUE
PARENT_SCOPE
Expand Down

0 comments on commit 3c8e398

Please sign in to comment.