[CMake] Can imported libraries depend on ExternalProject targets?

David Cole david.cole at kitware.com
Fri Jun 22 13:29:24 EDT 2012


On Fri, Jun 22, 2012 at 11:33 AM, Kent Williams
<nkwmailinglists at gmail.com>wrote:

> Say I have an ExternalProject that generates several libraries
>
> ExternalProject_Add(foo
>  # the usual mumbo jumbo
> )
>
> set(foo_LIBRARIES)
>
> # foo makes 3 libraries
> foreach(lib a b c)
>  # import the libraries
>  add_library(${lib} STATIC IMPORTED)
>
>  # tell CMake where the library file is
>  set_property(TARGET ${lib} PROPERTY
>     IMPORTED_LOCATION
>     ${imported_library_filename})
>
>  # add to the library list
>  list(APPEND foo_LIBRARIES ${lib})
>
>  # this doesn't work apparently
>  add_dependencies(${lib} foo)
> endforeach()
>
> In order for parallel make to work, the foo ExternalProject must
> complete successfully before any programs that link to
> ${foo_LIBRARIES} are compiled and linked.
>
> I thought that making the imported library targets depend on the
> ExternalProject target would behave in a transitive manner - i.e.
>
> add_executable(foo_user foo.cxx)
> target_link_libraries(foo_user ${foo_LIBRARIES})
>
> But this is not the case. In a parallel build, the foo_user build
> doesn't wait for the foo ExternalProject to finish.
>
> If I add
>
> add_dependencies(foo_user foo)
>
> Everything behaves fine.  But that requires explicitly add a
> dependency on an ExternalProject target everywhere it's outputs are
> used.
>
> Is this a bug? A feature request? Or is there another way to make this
> work?
>


It's neither a bug nor a feature request, it's just the way it works. The
explicit dependency is the only way to connect up the outputs of one
ExternalProject call to another, which by their nature are independent of
one another unless explicitly connected via arguments / cache entries.

If you want foo_user to depend on the actual libraries, then it should be
its own project that does a find_package(foo) to get them. And then *also*
have a SuperBuild that builds foo and then foo_user, where foo_user as an
ExternalProject depends on foo as an ExternalProject.

The best way to use ExternalProject is to have a SuperBuild project that
builds *everything* as an ExternalProject.

It's not easy (or advisable, in my thinking) to combine ExternalProject
calls with non-ExternalProject CMake targets. That's why I recommend a
SuperBuild, with exclusively ExternalProject targets, as the best bet.


HTH,
David


--
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120622/3e3e8030/attachment.htm>


More information about the CMake mailing list