We use FetchContent to fetch external dependencies for our project:
FetchContent_Declare(Library
GIT_REPOSITORY https://github.corpname.com/OrgName/library
GIT_TAG aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
FetchContent_MakeAvailable(Library)
However, since source is cached in the binary dir, this means our build agents which do a clean build every run do a git checkout for all of our dependencies every run. We would like to cache the sources outside of the binary dir.
There is FETCHCONTENT_BASE_DIR
which solves our use case, as it allows us to move the FetchContent base dir outside of the build dir, but then we run into issues with building multiple configurations because this also moves the build and subbuild dirs outside of the binary dir and shares them across all builds. There is SUBBUILD_DIR
which allows us to move the subbuild dir back to the binary dir, but not the build dir. There is FETCHCONTENT_SOURCE_DIR_<uppercaseName>
which allows us to move just the source dir, but this disables fetching entirely and makes us rewrite our source fetching outside of cmake.
Is there a way to only change just the FetchContent source dir cache location without touching build/subbuild dirs or disabling fetching?