[CMake] ExternalProject dependency question

Dan Kegel dank at kegel.com
Thu Oct 27 19:07:30 EDT 2011


Oh, man, now I get it.
The idea of http://www.cmake.org/Bug/view.php?id=10395
is to tell cmake that the external project is generating a library;
you can then hang the dependencies on that library.
Here's an example that seems works for me (tested by inserting a big
sleep into the configure for the external project):

cmake_minimum_required (VERSION 2.8.4)
include(ExternalProject)
ExternalProject_Add(
    Foobar_external
    SOURCE_DIR ${CMAKE_SOURCE_DIR}/foobar
    INSTALL_DIR ${CMAKE_BINARY_DIR}/prefix
    CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/foobar/configure
--prefix=${CMAKE_BINARY_DIR}/prefix
)
# Tell cmake that the external project generated a library so we can
add dependencies here instead of later
add_library(Foobar UNKNOWN IMPORTED)
set_property(TARGET Foobar PROPERTY IMPORTED_LOCATION
${CMAKE_BINARY_DIR}/prefix/lib/libfoobar.a )
add_dependencies(Foobar Foobar_external)
SET(Foobar_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/foobar)
SET(Foobar_LIBRARIES Foobar)

# Now callers of library Foobar can just do
#   target_link_libraries(whatever ${Foobar_LIBRARIES})
# instead of
#   target_link_libraries(whatever ${Foobar_LIBRARIES})
#   add_dependencies(whatever ${Foobar_LIBRARIES})

That sound right?

I wonder if this couldn't be wrapped up more neatly somehow, but for
now, it's better than what I was doing before.
- Dan


More information about the CMake mailing list