๐Ÿ“ฆ FetchContent() and Package Managers

FetchContent() as Package Manager

cmake-re L1 Build Cache is a git connected automatic build cache for CMake, it can be used as a C++ package manager or as โšก batteries to supercharge your favorite package manager.

One of the built-in CMake package manager that is used broadly is the FetchContent() module. FetchContent() is rudimentary and simple and hence slow when starting a fresh build on a CI node or during developer onboarding. The cmake-tipi-provider allows to express any dependencies with the best CMake Package Manager out there FetchContent.

Advantages :

  • Without changes FetchContent is automatically cached.
  • tipi . -t linux -u automatically injects the cmake-tipi-provider.
  • CMakeLists.txt stays fully compatible to plain CMake without tipi or cmake-re

How to use it ?

Exactly as the CMake FetchContent documentation requires, the build will just be cached and faster to restore. export CMAKE_TIPI_PROVIDER_ENABLE=ON

Include(FetchContent)
FetchContent_Declare(
    Boost
    GIT_REPOSITORY https://github.com/boostorg/boost.git
    GIT_TAG        32da69a36f84c5255af8a994951918c258bac601 # Boost 1.80
    )
FetchContent_MakeAvailable(Boost)
find_package(boost_filesystem CONFIG REQUIRED)

add_executable(app boost.cpp)
target_link_libraries(app Boost::filesystem)

How does it work ?

The speedup comes from the fact that instead of using add_subdirectory by default as plain FetchContent does, it runs the build of the dependency in a separate CMake context with cmake-re git mirroring based caching and installs the build artifacts in a dependency-specific sysroot.

When a cache entry is found, as it does not rely on CMake adding the subdirectory as part of the build, it doesn't need to fetch the sources but simply the install-tree artifacts.

Fetching the sources in big project can be slow, but also having to provide the exact same environments for the build to happen to get the built artifacts can also be an issue, tipi's smart caching is based on an ABI-hash computation, that behaves as if the project was built from sources but without the cost of building if it was already done by a peer in the same team.

If compile flags changes in an incompatible way, the build will be performed fully from sources again.

tipi installs the FetchContent provider by defining: -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=tipi_provider.cmake.

It leverages the standard CMake DEPENDENCY_PROVIDER feature dedicated to integrate with FetchContent and find_package.

Other C++ Package Managers

We have been working on integrating our build cache into the other common C++ package managers ( CPM, vcpkg, Conan... ). Contact us for more informations.

Help & Support

๐Ÿงš Get community support
๐Ÿ“– Read CMake FetchContent documentation


Found an error or want to add more info? Write an issue or contribute changes to this documentation at tipi-build/docs on