[CMake] External projects and imported targets

Timothy M. Shead tshead at k-3d.com
Sun May 16 12:48:38 EDT 2010


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:

  # Build external project A
  ExternalProject_Add(A ...)

  # Setup target B, which will be build as part of A
  add_library(B SHARED IMPORTED)
  set_target_properties(B PROPERTIES
    IMPORTED_LOCATION "${BINARY_DIR}/path/to/B.so.x.y"
    IMPORTED_SONAME "B.so.x"
    )

  # Link with B
  add_library(C ...)
  target_link_libraries(C B)

which is dissatisfying, since it means I have to get intimate with the
way project A's libraries are named, whether they're .dlls, .sos,
.dylibs, etc.

I'm wondering if there are any suggestions or best practices on how to
simplify this.

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/51623239/attachment.vcf>


More information about the CMake mailing list