# FetchContent\_Declare: should it re-fetch when the GIT\_SUBMODULES param changes?

**URL:** <https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636>\
**Category:** Code\
**Created:** [May 9, 2022, 3:48pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636 "2022-05-09T15:48:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [May 9, 2022, 3:48pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636/1 "2022-05-09T15:48:46Z")

</div>

I am modifying slightly a project called boost-cmake that I found on Github. In his project he grabs the boost tarball from [jfrog.io](http://jfrog.io), but I am instead using git to pull the overall project and selected submodules. Here’s the gist of what I do:

```auto
set(BOOST_URL "https://github.com/boostorg/boost.git")
set(BOOST_REQD_SUBMODULES
    "libs/multiprecision;libs/config" # leave value empty if all submodules wanted
    "libs/mpl;libs/preprocessor;libs/type_traits"
)

include(FetchContent)
FetchContent_Declare(
    Boost
    GIT_REPOSITORY ${BOOST_URL}
    GIT_TAG boost-1.75.0 # v1.75.0
    GIT_SUBMODULES ${BOOST_REQD_SUBMODULES}
    GIT_PROGRESS TRUE
    CONFIGURE_COMMAND "" # tell CMake it's not a cmake project
)
FetchContent_GetProperties(Boost)

if(NOT Boost_POPULATED)
  message(STATUS "Fetching Boost")
  FetchContent_Populate(Boost)
  message(STATUS "Fetching Boost - done")
  set(BOOST_SOURCE ${boost_SOURCE_DIR})
endif()

```

As I add submodules to my variable `${BOOST_REQD_SUBMODULES}` the Fetch is not re-executed. Actually, to clarify: The message “Fetching Boost” _always_ appears, but when the GIT\_SUBMODULES value changes it does not add to \_deps the additional Boost submodule. I have to manually clear the \_deps folder in the build folder and then it will get the added submodule when I run CMake again. I’m wondering if this is a FetchContent flaw or the way it is designed. I’m designing this to only download modules we depend on now but want the flexibility to add boost modules down the road. I’d like to make this as seamless as possible for users so if I could avoid having to instruct them they need to manually remove the \_deps folder when a new submodule gets added that would be ideal.

Any suggestions? I ask about the GIT\_SUBMODULES param because I thought I saw somewhere else that modifying the GIT\_TAG would force a re-fetch.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 9, 2022, 4:08pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636/2 "2022-05-09T16:08:33Z")

</div>

Sounds like the “is the source out-of-date” detection needs to take the submodule list into account. FYI @craig.scott

---

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [May 9, 2022, 4:10pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636/3 "2022-05-09T16:10:31Z")

</div>

Wow that was fast. I have to say this is one of the best forums I’ve encountered. You guys are awesome.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [May 9, 2022, 9:32pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636/4 "2022-05-09T21:32:57Z")

</div>

Which CMake version was this with? Please try the latest release. There were changes that went in to 3.23.0 (notable [MR 6926](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6926)) which I think will have already fixed the problem you’re seeing.

---

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [May 9, 2022, 9:51pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636/5 "2022-05-09T21:51:48Z")

</div>

My bad - I spaced out on reporting what version I was using. The problem occurred with 3.21. It’s gone in 3.23.1.
