title: cmake and include directories across projects
body: <p>I'm trying to split a large cmake-managed project into a collection of smaller projects. I'm having trouble making cmake accept propagation of include directories. I'm currently using the cmake version that comes with ubuntu 14.04 (2.8). I can switch to 3.x if it really is necessary, but I'd rather not if I can help it. </p>
  
  <p>Consider an example where a certain directory of my source tree consists of a separable, isolate-able library. It has no other dependencies within my source tree, and has so far been managed by a combination of </p>
  
  <pre><code>ADD_SUBDIRECTORY(smdir)
  </code></pre>
  
  <p>and within smdir:</p>
  
  <pre><code>ADD_LIBRARY(something STATIC something.c something.h)
  </code></pre>
  
  <p>In other areas where <code>something</code> is used as a dependency, the following works perfectly:</p>
  
  <pre><code>ADD_LIBRARY(something_else STATIC ...)
  TARGET_LINK_LIBRARIES(something_else something)
  </code></pre>
  
  <p>All of this happening inside cmake macros / functions that do some other name mangling, so please forgive me if the precise code listed here is slightly incorrect.</p>
  
  <p>What I'm now trying to do is pull <code>something</code> completely out of my source tree. I should note that these are embedded libraries for use on bare metal microcontrollers, and it's not something I'm installing on the build machine. </p>
  
  <p>The basic compile scripts for <code>something</code> work pretty much as expected with minimal changes. My approach to integrate this (now externally compiled and managed) library with the rest of the codebase is by exporting the compiled library from the build tree, and importing it into my other project. This approach is based largely on the <code>Exporting from a Build Tree</code> section of <a href="https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets" rel="nofollow">https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets</a>. I have tried to do this in the following way :</p>
  
  <pre><code>TARGET_INCLUDE_DIRECTORIES(something PUBLIC /path/to/smdir/src)
  EXPORT(TARGETS something FILE something-config.cmake)
  INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/something-config.cmake 
              DESTINATION ${PLATFORM_PACKAGES_PATH})
  </code></pre>
  
  <p>where ${PLATFORM_PACKAGES_PATH} is some system folder where I intend to collect all of these config files. The generated config file looks reasonable, and is installed to the correct place just fine, and has the following lines (among many others):</p>
  
  <pre><code>add_library(something STATIC IMPORTED)
  set_target_properties(something PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "/path/to/smdir/src"
  )
  set_property(TARGET something APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
  set_target_properties(something PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "C" IMPORTED_LOCATION_RELWITHDEBINFO "/correct/path/to/something.a")
  </code></pre>
  
  <p>The problem comes when importing this library, which I do using:</p>
  
  <pre><code>ADD_LIBRARY(something STATIC IMPORTED)
  SET_PROPERTY(TARGET something PROPERTY IMPORTED_LOCATION "${PLATFORM_PACKAGES_PATH}") 
  GET_PROPERTY(public_include_dirs TARGET something PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
  </code></pre>
  
  <p>The build of any library which lists something as a dependency does not include the INCLUDE_FOLDERS for something in the gcc command. The <code>public_include_dirs</code> variable which I try to read here with GET_PROPERTY is blank. </p>
  
  <p>Any help or insight would be greatly appreciated, including suggestions for a 'cleaner' or better approach.</p>