Skip to content

Commit afeba46

Browse files
BuildUtils: make GIT_SUBMODULES optional in FetchContent_DeclareShallowGit
1 parent 46cf513 commit afeba46

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

BuildTools/CMake/BuildUtils.cmake

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,31 @@ endfunction()
535535

536536
# The GIT_SHALLOW option in FetchContent is buggy and does not actually perform
537537
# a shallow clone. This macro fixes that. Also, we do not want to clone all
538-
# submodules to reduce download time, therefore we add an option GIT_SUBMODULES
539-
# to specify which submodules should be cloned (if any).
540-
macro(FetchContent_DeclareShallowGit Name GIT_REPOSITORY GitRepository GIT_TAG GitTag GIT_SUBMODULES GitSubmodules)
538+
# submodules to reduce download time, therefore an optional GIT_SUBMODULES
539+
# argument specifies which submodules should be cloned (if omitted, all of them).
540+
macro(FetchContent_DeclareShallowGit Name)
541+
set(oneValueArgs GIT_REPOSITORY GIT_TAG)
542+
set(multiValueArgs GIT_SUBMODULES)
543+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
544+
541545
include(FetchContent)
542546

543547
# This is what it'd look like if GIT_SHALLOW was indeed working:
544-
#GIT_REPOSITORY "${GitRepository}"
545-
#GIT_TAG "${GitTag}"
548+
#GIT_REPOSITORY "${ARG_GIT_REPOSITORY}"
549+
#GIT_TAG "${ARG_GIT_TAG}"
546550
#GIT_SHALLOW ON
547-
#GIT_SUBMODULES "${GitSubmodules}"
551+
#GIT_SUBMODULES "${ARG_GIT_SUBMODULES}"
548552

549553
# Manual download mode instead:
550554
FetchContent_Declare(
551555
${Name}
552556
DOWNLOAD_COMMAND
553557
cd "${FETCHCONTENT_BASE_DIR}/${Name}-src" &&
554558
git init &&
555-
git remote add origin "${GitRepository}" &&
556-
git fetch --depth=1 origin "${GitTag}" &&
559+
git remote add origin "${ARG_GIT_REPOSITORY}" &&
560+
git fetch --depth=1 origin "${ARG_GIT_TAG}" &&
557561
git checkout FETCH_HEAD &&
558-
git submodule update --init --recursive --depth=1 ${GitSubmodules}
562+
git submodule update --init --recursive --depth=1 ${ARG_GIT_SUBMODULES}
559563
)
560564
endmacro()
561565

0 commit comments

Comments
 (0)