title: CMake target_sources and install
body: <p>I am having a hard time figuring out how to install <code>PUBLIC</code> headers specified in <a href="https://cmake.org/cmake/help/v3.17/command/target_sources.html" rel="nofollow noreferrer"><code>target_sources()</code></a>.</p>
  
  <p>It appears that <code>target_sources()</code> is somewhat of a mystery for anything other than adding private sources to an executable.
  After reading a lot of material, where especially <a href="https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/" rel="nofollow noreferrer">this blog entry</a> was helpful, I managed to understand &amp; bypass the issue with <code>target_sources()</code> and PUBLIC files. A <code>CMakeLists.txt</code> in one of the many subdirectories of my C++ library project looks like this:</p>
  
  <pre><code>target_sources(mylib
      PRIVATE
          foo.cpp
  
      PUBLIC
          $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/foo.hpp&gt;
          $&lt;INSTALL_INTERFACE:foo.hpp&gt;
  )
  </code></pre>
  
  <p>This allows me to successfully build the library. However, upon installation, the header file(s) listed in the <code>PUBLIC</code> section of <code>target_sources()</code> are never installed.</p>
  
  <p>My installation looks like this:</p>
  
  <pre><code>install(
      TARGETS
          mylib
      EXPORT mylib-targets
      LIBRARY
          DESTINATION ${CMAKE_INSTALL_LIBDIR}
          COMPONENT lib
      ARCHIVE
          DESTINATION ${CMAKE_INSTALL_LIBDIR}
          COMPONENT lib
      RUNTIME
          DESTINATION ${CMAKE_INSTALL_BINDIR}
          COMPONENT bin
      INCLUDES
          DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mylib
  </code></pre>
  
  <p>However, this doesn't install any of the headers.
  This <a href="https://stackoverflow.com/a/56559641/1414496">stackoverflow answer</a> mentions the use of <a href="https://cmake.org/cmake/help/v3.17/prop_tgt/PUBLIC_HEADER.html" rel="nofollow noreferrer"><code>PUBLIC_HEADER</code></a> but reading the documentation doesn't give me the feeling that that is relevant in my case.</p>
  
  <p><strong>Question:</strong> What is the proper way of installing <code>PUBLIC</code> or <code>INTERFACE</code> headers using <code>install()</code>?</p>
  
  <p><strong>Background:</strong> My goal is to have a separate <code>CMakeLists.txt</code> in every subdirectory of my source tree. Each of these lists is supposed to use <code>target_sources()</code> to add <code>PRIVATE</code> and <code>PUBLIC</code> files to the build. All <code>PUBLIC</code> (and <code>INTERFACE</code>) sources should be installed during installation.</p>