[CMake] External projects and imported targets

Timothy M. Shead tshead at k-3d.com
Sun May 16 14:26:05 EDT 2010


On 05/16/2010 12:11 PM, Marcus D. Hanwell wrote:
> On Sun, May 16, 2010 at 12:48 PM, Timothy M. Shead <tshead at k-3d.com
> <mailto:tshead at k-3d.com>> wrote:
> 
>     I'd like to do the following:
> 
>      # Build external project A
>      ExternalProject_Add(A ...)
> 
>      # Import target B, which is exported by A in AConfig.cmake
>      ExternalProject_Get_Property(A, BINARY_DIR)
>      set(A_DIR ${BINARY_DIR})
>      find_package(A)
> 
>      # Link with B
>      add_library(C ...)
>      target_link_libraries(C B)
> 
>     Of course, this doesn't work because the external project hasn't been
>     built yet at configure-time, so AConfig.cmake doesn't exist.  Which
>     leads me to the following:
> 
> Hi,
> 
> If I understand your question correctly, then adding DEPENDS A to your
> ExternalProject_Add(B...) call will ensure that A has been built when B
> is configured, thus satisfying your need to find A's exported targets.
> Using the dependencies between external projects it is possible to
> control the build order, so that A's config file will be present before
> B attempts a configure step.

That wasn't quite what I was describing - "B" isn't another external
project, it's a library that's built by external project "A".  Because A
hasn't been built (isn't even downloaded yet) at configure time, I can't
use find_package to benefit from A's internal understanding of where
its' outputs are located.  Basically, I want the simplest possible
add_library(... IMPORTED) call possible, one that doesn't end-up
duplicating all of the platform-specific logic that CMake normally takes
care of.  Since my last post, I've switched to the following, which
works on Linux and seems like it could work on Windows:

  ADD_LIBRARY(B SHARED IMPORTED)
  SET_TARGET_PROPERTIES(B PROPERTIES
    IMPORTED_LOCATION
"${BINARY_DIR}/path/to/libB${CMAKE_SHARED_LIBRARY_SUFFIX}"
   IMPORTED_IMPLIB "${BINARY_DIR}/path/to/libB.lib"
  )

Cheers,
Tim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tshead.vcf
Type: text/x-vcard
Size: 151 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100516/db5bbac9/attachment.vcf>


More information about the CMake mailing list