title: CMake: copy header file to output directory
body: <p>I have a directory with c++ source and header files.  I want to create a CMakeLists.txt to build this as a library for use in other CMake projects that include it as a sub directory.</p>
  
  <p>Structure: </p>
  
  <pre><code>example/
      foo.h
      foo.cpp
      CMakeLists.txt
  </code></pre>
  
  <p>The problem I run into is CMake doesn't seem to put foo.h anywhere, so getting the parent CMake to know how to find the header file is beguiling me.</p>
  
  <p>Here's my current CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.8.2)
  project(example)
  set (CMAKE_CXX_STANDARD 11)
  
  # add library target foo
  add_library(foo STATIC foo.cpp)
  
  # tell cmake where to find headers for it
  target_include_directories(foo PUBLIC .)
  
  # sad attempt to get it to output the header
  set_target_properties(foo PROPERTIES PUBLIC_HEADER foo.h)
  </code></pre>
  
  <p>I DON'T want to have to do install.  The idea here is that the library would be used by other CMake projects, not by the entire system.  </p>
  
  <p>Ideally, the foo.h would show up next to libfoo.a in the build directory.</p>
  
  <p>I've tried calling it a "FRAMEWORK", no luck; that only makes is a macOs framework.</p>
  
  <p>I believe I can jury rig this, but methinks there's a best practice out there.</p>
  
  <p>Open to an answer that says "here's a better way", too...</p>
  
  <p>UPDATE</p>
  
  <p>It might help to clarify how I think I want to pull this project into another.  I've seen other projects use something like this:</p>
  
  <pre><code>add_subdirectory(&lt;path_to_foo&gt;/foo foo_build)
  </code></pre>
  
  <p>which causes the foo build to happen in a subdirectory.  This allows me to refer to the library using 'foo_build', which is nice and clean.  However, I still have to point at the original include directory to get the .h file, which makes me feel like I'm missing something.</p>
  
  <p>It seems like cmake would have a clean solution for this.</p>