Skip to content

FetchContent_Declare does not honor GIT_SUBMODULES argument

When FetchContent_Declare is called with a GIT_SUBMODULES argument, it is not honored. Instead, FetchContent_MakeAvailable() will clone the declared git repository's submodules recursively, even if the named content was declared with GIT_SUBMODULES "".

Steps to reproduce

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)

include(CMakePrintHelpers)
include(FetchContent)

# cmake_policy(GET CMP0097 CMP_0097_POLICY_STATUS)
# cmake_print_variables(CMP_0097_POLICY_STATUS)

project(my_project LANGUAGES CXX)

FetchContent_Declare(pybind11
    GIT_REPOSITORY https://github.com/pybind/pybind11.git
    GIT_TAG v2.5.0
    GIT_SUBMODULES ""
)

FetchContent_MakeAvailable(pybind11)

After creating the file above:

mkdir -p build
(cd build && cmake ..)

Expected result

The documentation for FetchContent_Declare describes its arguments this way:

The <contentOptions> can be any of the download or update/patch options that the ExternalProject_Add() command understands.

The documentation for ExternalProject_Add describes the parameter this way:

GIT_SUBMODULES <module>:

Specific git submodules that should also be updated. If this option is not provided, all git submodules will be updated. When CMP0097 is set to NEW if this value is set to an empty string then no submodules are initialized or updated.

As a result, I expected the pybind11 clone process to not be recursive, and that source directory for pybind11 would not contain that repo's submodule. (The pybind11 repository contains one submodule, in its tools/clang directory.)

Actual result

The clone process initiated in FetchContent_MakeAvailable is recursive. The clone step clones pybind11's submodule into the repo's tools/clang subdirectory.

I used pybind11 as an example because its submodule is optional for library users.

Notes

I confirmed that CMP0097 is set to NEW when I use CMake 3.16 (in commented code above).

If I invoke ExternalProject_Add directly:

include(ExternalProject)
ExternalProject_Add(alt-pybind11
    GIT_REPOSITORY https://github.com/pybind/pybind11.git
    GIT_TAG v2.5.0
    GIT_SUBMODULES ""
)

The behavior is as expected: the repo's submodule is not cloned.

Edited by Nicholas Musolino
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information