I'm wondering how to manage dependencies of an external project. Let's say I have three projects, each one in a different repository:
- Core: library exporting a lot of useful stuff.
- Lib1: library with some specific classes (depends on Core).
- Executable: uses stuff from Core and also from Lib1.
Each project with its CMakeLists.txt. Using find_package and defining paths on CMake I can build each project without problems and install it (I followed this tuto to build .cmake files for libraries)
Now I'm trying to make this process as easy as possible and I'm introducing the ExternalProject_Add macro, this way people will only have to clone Executable repository and with the help of CMake files Lib1 and Core are also downloaded, compiled and linked.
The problem is that Executable and Lib1 depends on Core but I want it to be cloned (and compiled) only once. Here is the problem:
- In Executable CMake clones and builds Core with the ExternalProject_Add features.
- Then Cmake clones Lib1 and look for Core but it hasn't been already installed so there is no core-targets.cmake file (core-config.cmake is available)... and building fails...
I don't know if there is a documented way to work with this kind of project tree or shall I write some kind of workaround when Core is included as dependency of an external project in order to avoid the use of core-targets.cmake file.
Thanks!
Solution
I realized that when using ExternalProject_Add it downloads, builds and INSTALL the project so, in the install-folder, I already have all the files needed to compile its dependants.
So I can manage this issue following these steps (also for build order):
- *ExternalProject_Add* for Core
- *ExternalProject_Add* for Lib1 passing Core install_dir as argument
- ...and Executable.
Executableonly depend onLib1. - Nicu Stiurca