CMake - Adding dependencies to other projects
<p>I'm quite new to CMake, and me and my colleagues decided on using it in some project we're developing. In this work, everybody is responsible for some module of the project. The layout is as follows:</p>

<pre><code>ROOT
  -&gt; Module1
     ...
  -&gt; Module2 (depends on Module 1)
     ...
  -&gt; Module3 (depends on Module 2 and 1)
</code></pre>

<p>Each <code>ModuleN</code> has its own <code>CMakeLists.txt</code> file and must be able to be compiled, tested, and finished before they can be put together into the whole project. Now, I'm quite confused about what approach to use to make those dependencies work.</p>

<p>My research showed me some ways (like adding <code>add_directory</code> directives, etc.), but some of them complained that this way the projects can be compiled many times unnecessarily (like <code>Module1</code> in this example); or requires a full path to be given.</p>

<p>The project won't be installed to the target machine, so I cannot use system library folders, includers, etc. either. Every developer has this repository in different folders, so I cannot give "exact" folders either. Can I use a syntax like "../Module1" for the <code>add_directory</code> command? Would this cause "unnecessary builds" as told?</p>

<p>Also, people usually recommend putting a <code>CMakeLists.txt</code> file in the root of the project as well, but I think this way we always have to build from the root directory - so modules cannot be built and tested separately.</p>

<p>What is the "noob way" to make this possible? As I said, I'm quite new to CMake, and honestly I don't even know the "keyword" to search for such a thing (searching "adding dependency" brings some results that I am simply drowned in :) )</p>