title: How to retrieve include directory from cmake find_package?
body: <p>I have written a library, built with cmake (currently using version 3.5.1 if that is important), and am now trying to use that library in another project, also built with cmake.</p>
  
  <p><code>find_package</code> finds the library just fine, and creates the exported targets, but unfortunately does not provide the expected <code>&lt;package&gt;_INCLUDE_DIRS</code> variable.</p>
  
  <p>Unfortunately I can't post the library, but for example <a href="https://github.com/zeux/pugixml" rel="nofollow noreferrer">pugixml</a> has the same problem:</p>
  
  <pre class="lang-sh prettyprint-override"><code>mkdir pugi
  cd pugi
  git clone https://github.com/zeux/pugixml.git .
  mkdir build
  cd build
  cmake -DCMAKE_INSTALL_PREFIX=~/temp ..
  make install
  </code></pre>
  
  <p>So far so good. However, trying to <code>find_package</code> it:</p>
  
  <pre><code>find_package(pugixml REQUIRED)
  message(STATUS ${pugixml_FOUND})
  message(STATUS ${pugixml_INCLUDE_DIRS})
  </code></pre>
  
  <pre><code>cmake -DCMAKE_INSTALL_PREFIX=~/temp ..
  </code></pre>
  
  <p>shows that the expected <code>pugixml_INCLUDE_DIRS</code> variable is not set:</p>
  
  <pre><code>-- 1
  --
  </code></pre>
  
  <p>I found that I can retrieve the include directory using a property on the target:</p>
  
  <pre><code>get_target_property(INCLUDE_DIRS pugixml INTERFACE_INCLUDE_DIRECTORIES)
  message(STATUS ${INCLUDE_DIRS})
  </code></pre>
  
  <pre><code>-- /home/username/temp/include
  </code></pre>
  
  <p>but I have never seen a cmake file do this.</p>
  
  <p>What is the proper method of retrieving the include directory of a package in cmake?</p>
  
  <p>Alternatively, what needs to be done in the package's cmake file such that <code>&lt;package&gt;_INCLUDE_DIRS</code> is properly set by <code>find_package</code>?</p>
  
  <hr>
  
  <p>Thanks for the tips thus far, I'm getting closer.</p>
  
  <p>The problem turns out to be that I am creating an intermediary object library target, which cannot link to a library. The <code>target_link_libraries</code> is only present in the final binary, but that is understandably not enough for compilation of the object library to find the headers.</p>
  
  <p>The question remains: how can I make the object library target aware of the include path of the found package?</p>
  
  <hr>
  
  <p>The marked duplicate unfortunately only solves this problem for relatively new versions of cmake (3.12 or newer). For older versions, <code>get_target_property</code> or the associated generator expression seem to be the only way to do this.</p>