title: CMake: how best to build multiple (optional) subprojects?
body: <p>Imagine an overall project with several components:</p>
  
  <ul>
  <li>basic</li>
  <li>io</li>
  <li>web</li>
  <li>app-a</li>
  <li>app-b</li>
  <li>app-c</li>
  </ul>
  
  <p>Now, let's say web depends on io which depends on basic, and all those things are in one repo and have a CMakeLists.txt to build them as shared libraries.</p>
  
  <p><strong>How should I set things up so that I can build the three apps, if each of them is optional and may not be present at build time?</strong></p>
  
  <p>One idea is to have an empty "apps" directory in the main repo and we can clone whichever app repos we want into that.  Our main CMakeLists.txt file can use GLOB to find all the app directories and build them (not knowing in advance how many there will be).  Issues with this approach include:</p>
  
  <ul>
  <li>Apparently CMake doesn't re-glob when you just say <code>make</code>, so if you add a new app you must run <code>cmake</code> again.</li>
  <li>It imposes a specific structure on the person doing the build.</li>
  <li>It's not obvious how one could make two clones of a single app and build them both separately against the same library build.</li>
  </ul>
  
  <p>The general concept is like a traditional recursive CMake project, but where the lower-level modules don't necessarily know in advance which higher-level ones will be using them.  Yet, I don't want to require the user to install the lower-level libraries in a fixed location (e.g. <code>/usr/local/lib</code>).  I do however want a single invocation of <code>make</code> to notice changed dependencies across the entire project, so that if I'm building an app but have changed one of the low-level libraries, everything will recompile appropriately.</p>