title: custom target as a target library in cmake
body: <p>I have a custom target that is in fact an externally generated library that I want to integrate in my build.</p>
  
  <pre><code>add_custom_command(
         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liblib2.a
         COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/makefile liblib2.a)
  
  add_custom_target(lib2  
         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/liblib2.a)
  </code></pre>
  
  <p>How can I tell cmake that this target is in fact a library, <strong>where it can be found and where are the headers</strong> ?</p>
  
  <p>To be clear : <strong>I don't want the upper CMakeList using this library having to manually specify include folders and the library location folder</strong> It must be done automatically (from the target properties).</p>
  
  <p>On a standard cmake library I would just have to add the INTERFACE_INCLUDE_DIRECTORIES property in the library CMakeLists to make cmake link my app with the relevant -I and -L gcc parameters :</p>
  
  <pre><code>set_target_properties(lib1
    PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES
    ${CMAKE_CURRENT_SOURCE_DIR})
  </code></pre>
  
  <p>But in the case of a custom target I don't know how to to it.</p>
  
  <p>Any clue ?</p>
  
  <p>Thanks for your help.</p>
  
  <hr>
  
  <p>Thanks to zaufi it works!</p>
  
  <p>For others who may be interested in embedded externally build target inside cmake here is what I did :</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  
  SET(LIB_FILE ${CMAKE_CURRENT_SOURCE_DIR}/bin/liblib2.a)
  SET(LIB_HEADER_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/include)
  
  # how to build the result of the library
  add_custom_command(OUTPUT  ${LIB_FILE}
                     COMMAND make 
                     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  
  # create a target out of the library compilation result
  add_custom_target(lib2_target DEPENDS ${LIB_FILE})
  
  # create an library target out of the library compilation result
  add_library(lib2 STATIC IMPORTED GLOBAL)
  add_dependencies(lib2 lib2_target)
  
  # specify where the library is and where to find the headers
  set_target_properties(lib2
      PROPERTIES
      IMPORTED_LOCATION ${LIB_FILE}
      INTERFACE_INCLUDE_DIRECTORIES ${LIB_HEADER_FOLDER})
  </code></pre>
  
  <p>Now in a CMakeLists.txt I can do somthing like</p>
  
  <pre><code>add_subdirectory(${ROOT_DIR}/lib1 bin/lib1)
  add_subdirectory(${ROOT_DIR}/lib2 bin/lib2)
  add_executable(app app.c )
  target_link_libraries(app lib1 lib2)
  </code></pre>
  
  <p>No need to specify where the .a and the .h are. </p>