title: cmake propagate dependencies using find_package
body: <p>As a simple example: there are two libraries and one executable.
  Both libraries are <code>SHARED</code> (i.e. a .so file). One is called <em>libMain</em> and one is called <em>libUtil</em>. <em>libMain</em> uses <em>libUtil</em> and so does the executable. 
  The executable might use <em>libUtil</em> on its own but usually it calls a method from <em>libMain</em> that does use <em>libUtil</em> in its implementation. </p>
  
  <p>So after reading some tutorials and docs about CMake this example seemed fairly straight forward.
  There is a simple CMakeLists.txt for each project while <em>libUtil</em> links to <em>libMain</em> and executable links to <em>libMain</em>. (I ommited <code>target_include_directories</code> to spare some lines) Same PREFIX_PATH is used by all projects.</p>
  
  <h1>libUtil</h1>
  
  <pre><code>include(GNUInstallDirs)
  
  project(libUtil)
  set(CMAKE_SHARED_LIBRARY_PREFIX "")    
  add_library(libUtil SHARED main.cpp)
  install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  install(EXPORT ${PROJECT_NAME}Config DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)
  </code></pre>
  
  <h1>libMain</h1>
  
  <pre><code>include(GNUInstallDirs)
  
  project(libMain)
  set(CMAKE_SHARED_LIBRARY_PREFIX "")
  add_library(libUtil SHARED main.cpp)
  find_package(libUtil REQUIRED)
  target_link_libraries(${PROJECT_NAME} PUBLIC libUtil)
  install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  install(EXPORT ${PROJECT_NAME}Config DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)
  </code></pre>
  
  <h1>executable</h1>
  
  <pre><code>project(exe)
  find_package(libMain REQUIRED)
  set(CMAKE_SHARED_LIBRARY_PREFIX "")
  add_executable(exe main.cpp)
  target_link_libraries(${PROJECT_NAME} PRIVATE libMain)
  </code></pre>
  
  <p>However when building the executable I ended up with a linker error, telling exe was <strong>not able to perform -llibUtil</strong>.</p>
  
  <p>I spend quite some time on this already and after reading several posts I found out (or at least I think so..) that I need to provide a <strong>custom libMainConfig.cmake</strong> (I renamed the generated one to libMainTargets.cmake)</p>
  
  <pre><code>include("${CMAKE_CURRENT_LIST_DIR}/libMainTargets.cmake")
  
  find_package(libUtil REQUIRED)
  </code></pre>
  
  <p>The linker error is gone now and I can run my project. Still I do not understand why I need to do this. I understood there is a difference when handling an already built library. However, as CMake always uses a directory based separation of projects, how and why would I ever build multiple projects in the same CMakeLists.txt? So far I always used <code>find_package</code> (which essentialy does add_library IMPORTED, i.e. searches a pre-build library If I am not mistaken) and wanted to propagate its defined dependencies to the "consuming" project. But it seems all of <code>PUBLIC</code>, <code>INTERFACE</code> and <code>PRIVATE</code> from the imported target have no affect in the "consuming" target? </p>
  
  <p>Please be detailed in the explanation and/or point out some references I missed and point out some best practices assuming all projects are either build by myself or are system libraries like boost or JNI.</p>
  
  <p>Thanks!</p>