title: CMake and external dependency
body: <p>I'd like to add an external dependency to my project. The one I'm trying to add is the <a href="https://github.com/DanBloomberg/leptonica" rel="nofollow noreferrer">Leptonica</a> library as a submodule.</p>
  
  <p>My project has the following directory structure:</p>
  
  <p>|root<br>
     CMakeLists.txt<br>
     |-bin<br>
     |-build<br>
     |-buildsystem<br>
     |-executable<br>
     |-leptonica<br>
     |--CMakeLists.txt<br>
     |--cmake<br>
     |---Configure.cmake<br>
     |-production<br></p>
  
  <p>In my root <code>CMakeLists.txt</code> file I added <br><i>ADD_SUBDIRECTORY(${ROOT_DIR}/leptonica)</i></p>
  
  <p>Unfortunately, CMake is not searching for <code>Configure.cmake</code> in the proper directory:</p>
  
  <pre><code>CMake Error at leptonica/CMakeLists.txt:107 (include):
  
  include could not find load file:
  
  Configure
  
  CMake Error: File
  
  &lt;root&gt;/cmake/templates/LeptonicaConfig-version.cmake.in does not exist.
  
  CMake Error at leptonica/CMakeLists.txt:113 (configure_file):
  
  configure_file Problem configuring file
  </code></pre>
  
  <p>When I build the project by myself, everything goes fine. In my opinion, the problem is with <code>CMAKE_SOURCE_DIR</code>. When using <code>add_subdirectory</code> it has the value of <code>ROOT</code> CMake instead <code>ROOT/leptonica</code>, so it's searching the wrong paths - as you can see in Leptonica CMake, it's used to determinate paths of its files.</p>
  
  <p>What should be the proper way to fix this - should I set <code>CMAKE_SOURCE_DIR</code> to <code>ROOT/leptonica</code> just before calling <code>add_subdirectory</code> and set it back when it's finished, or does some other, more elegant solutions exist?</p>