@@ -663,6 +663,7 @@ function(CPMAddPackage)
663663 NO_CACHE
664664 SYSTEM
665665 GIT_SHALLOW
666+ GIT_SUBMODULES
666667 EXCLUDE_FROM_ALL
667668 SOURCE_SUBDIR
668669 CUSTOM_CACHE_KEY
@@ -689,6 +690,22 @@ function(CPMAddPackage)
689690
690691 cmake_parse_arguments (CPM_ARGS "" "${oneValueArgs} " "${multiValueArgs} " "${ARGN} " )
691692
693+ set (NO_SUBMODULES FALSE )
694+ list (FIND ARGN GIT_SUBMODULES _git_submodules_index)
695+ if (NOT _git_submodules_index EQUAL -1)
696+ if (DEFINED CPM_ARGS_GIT_SUBMODULES)
697+ list (APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SUBMODULES ${CPM_ARGS_GIT_SUBMODULES} )
698+ else ()
699+ # cmake's FetchContent function will skip initializing submodules if
700+ # GIT_SUBMODULES is set to "". CPM has issues passing a variable when it
701+ # has a value of "" (when lists are made/copied variables in them with a
702+ # value of "" are considered NOT DEFINED). To work around this, we set
703+ # NO_SUBMODULES to TRUE here and have it later tell the FetchContent call
704+ # to set GIT_SUBMODULES to "".
705+ set (NO_SUBMODULES TRUE )
706+ endif ()
707+ endif ()
708+
692709 # Set default values for arguments
693710 if (NOT DEFINED CPM_ARGS_VERSION)
694711 if (DEFINED CPM_ARGS_GIT_TAG)
@@ -983,7 +1000,7 @@ function(CPMAddPackage)
9831000 endif ()
9841001 endif ()
9851002 cpm_declare_fetch(
986- "${CPM_ARGS_NAME} " ${fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS} "
1003+ "${CPM_ARGS_NAME} " ${NO_SUBMODULES} ${ fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS} "
9871004 )
9881005
9891006 cpm_fetch_package("${CPM_ARGS_NAME} " ${DOWNLOAD_ONLY} populated ${CPM_ARGS_UNPARSED_ARGUMENTS} )
@@ -1101,13 +1118,18 @@ function(CPMGetPackageVersion PACKAGE OUTPUT)
11011118endfunction ()
11021119
11031120# declares a package in FetchContent_Declare
1104- function (cpm_declare_fetch PACKAGE)
1121+ function (cpm_declare_fetch PACKAGE NO_SUBMODULES )
11051122 if (${CPM_DRY_RUN} )
11061123 cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)" )
11071124 return ()
11081125 endif ()
11091126
1110- FetchContent_Declare(${PACKAGE} ${ARGN} )
1127+ if (${NO_SUBMODULES} )
1128+ cpm_message(STATUS "${CPM_INDENT} ${PACKAGE} : Not cloning submodules" )
1129+ FetchContent_Declare(${PACKAGE} ${ARGN} GIT_SUBMODULES "" )
1130+ else ()
1131+ FetchContent_Declare(${PACKAGE} ${ARGN} )
1132+ endif ()
11111133endfunction ()
11121134
11131135# returns properties for a package previously defined by cpm_declare_fetch
0 commit comments