0
votes

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?
2
Yes. Is it a good idea? Well, probably when you start to do this, your life will be much simpler if you use a dependency manager to manage the dependencies. vcpkg, conan.io, … - spectras
@spectras yeah I agree. Unfortunately, I cannot really do it in my specific case, the only help with dependencies I can use is CMake - Vicente Bolea
For these who's boring to just build, there is a cmake.org/cmake/help/latest/module/ExternalProject.html module to bring ~problems~ fun to their life :) - zaufi
You have my sympathy. Then ExternalProject that zaufi linked is probably your best bet. - spectras

2 Answers

2
votes

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).

0
votes

I would suggest ExternalProject which is even better than FetchContent if you want to build that you've fetched after.