[CMake] FetchContent and multiple CMake projects

Saad Khattak saadrustam at gmail.com
Thu Apr 12 19:06:24 EDT 2018


Hi,

I have many independent CMake projects and most projects have external
dependencies. Most of the projects have the same dependency e.g. Catch
testing library.

Each library uses FetchContent so that it can be built independently by
simply cloning its github repository, configuring and generating through
CMake and then building. However, I would also like the ability for these
projects to share the same dependency to save disk space (and compile time)
if they detect that another project already has done FetchContent on a
particular dependency.

Again, note that all projects are independent where their own repositories.

------------------------------------------ EXAMPLE
----------------------------------------------
To illustrate the setup: I have LibA, LibB, LibC, LibD, LibE etc. where
each may have a dependency that is found to be the same. So, when LibA is
the only one that is cloned, it uses FetchContent to clone the
dependencies, build them, install them and the test executable linked to
the dependencies properly.

Now LibB is cloned and it has some dependencies that LibA doesn't have but
other dependencies that LibA 'does' use. Assuming LibA is already built
successfully, I would like LibB to rely on LibA's dependencies, if found,
otherwise LibB clones, generates and builds its own dependencies.

It is also possible that LibA was never cloned/built and thus LibB must
clone/generate/build all dependencies.
------------------------------------------ END EXAMPLE
----------------------------------------------

To solve this issue, I am using a combination of find_package(...) and
FetchContent, however the whole setup is starting to show cracks, is
fragile and difficult to test and maintain. So now I am wondering whether
there is a better way to about solving the issue.

Thank you,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180412/31f0f116/attachment.html>


More information about the CMake mailing list