title: cmake: create a new library target which consists of a prebuilt library
body: <p>I'm trying to create a custom target in cmake which:</p>
  
  <ul>
  <li>links a vendor supplied archive</li>
  <li>adds <code>target_compile_options(... PUBLIC ...)</code></li>
  <li>adds <code>target_include_directories(... PUBLIC ...)</code></li>
  </ul>
  
  <p>In this way consumers can link against my new target and have requisite include directories and compile options set.</p>
  
  <p>In boost-build you can use the <a href="http://www.boost.org/build/doc/html/bbv2/tasks/libraries.html" rel="noreferrer"><code>&lt;file&gt;</code></a> feature to "wrap" or "alias" a prebuilt library, and add additional "usage requirements" (compiler flags etc) which will be added to all targets using the library.</p>
  
  <pre><code>lib foo 
  : 
  : &lt;file&gt;vendor/library.a
  :
  : &lt;include&gt;vendor
  ;
  </code></pre>
  
  <ul>
  <li>This aliases <code>vendor/library.a</code> as a new library <code>foo</code>.  </li>
  <li>When another target uses <code>foo</code> it will also have its include paths updated.  </li>
  <li>The code using <code>foo</code> will then be able to <code>#include "foo.h"</code>, and the file will be found because <code>vendor</code> has been added to the include paths.</li>
  </ul>
  
  <p>I'm looking for a way to do the same thing in CMake.</p>
  
  <p>The way I would currently do it would be something along these lines:</p>
  
  <pre><code>find_library(LIB_FOO library.a PATHS ${CMAKE_SOURCE_DIR}/path/to/vendor NO_DEFAULT_PATH)
  
  target_link_library       (my_target ${LIB_FOO})
  target_include_directories(my_target PRIVATE "${CMAKE_SOURCE_DIR}/path/to/vendor")
  </code></pre>
  
  <p>However, if there are several targets which need to use <code>foo</code> then these 3 calls would have be repeated for each of them, which becomes quite onerous.</p>
  
  <p>It would be far easier for consumers of <code>foo</code> to have some other target which has </p>
  
  <pre><code>target_link_libraries     (foo ${CMAKE_CURRENT_LIST_DIR}/vendor/library.a)
  target_compile_options    (foo PUBLIC ...)
  target_include_directories(foo PUBLIC ...)
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <ul>
  <li>Can I create a <strong>new</strong> library target which consists of a prebuilt library which will allow me to do what I've described?</li>
  </ul>
  
  <p><strong>Edit in response to comment:</strong></p>
  
  <p>I have tried to create an <code>IMPORTED</code> library (as described <a href="https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets" rel="noreferrer">here</a>):</p>
  
  <pre><code>add_library(foo STATIC IMPORTED)
  set_property(TARGET foo PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/vendor/library.a)
  </code></pre>
  
  <p>However, when I then try to set include directories I get an error:</p>
  
  <pre><code>target_include_directories(foo SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/vendor")
  </code></pre>
  
  <p>Error: </p>
  
  <blockquote>
  <pre><code>CMake Error at vendor/CMakeLists.txt:39 (target_include_directories):
    Cannot specify include directories for imported target "foo".
  </code></pre>
  </blockquote>