Search code examples
c++makefilecmakeconfigure

CMAKE: Configure/build a foreign package from your package


Let say that your CMake C++ project depends on some external library such has Google Benchmarks/Test.

I know that I can independently configure and install the external library so that later when building my personal project I can access its CMake file which will nicely satisfy the dependency (It will nicely add its headers and library files)

My question is:

  • Is it possible to directly configure/build this external library when configuring my project bypassing installing this external library?

Solution

  • Yes. Have a look at https://cmake.org/cmake/help/latest/module/FetchContent.html

    This is exactly what I use for fetching GTest.

    Idea is simple - FetchContent will clone a repo for you, then you do add_subdirectory into that repo, and you can manage all subproject details (assuming project uses CMake and is written properly).