[cmake-developers] Exporting dependent library targets in multiple export sets

Alexander Neundorf neundorf at kde.org
Wed Aug 22 16:15:45 EDT 2012


Hi,

currently, when exporting library targets, it is required that all in-project 
libraries which the exported libraries depend on, are also exported in the 
same export set.

I.e. the following currently does not work:

------------------------------------

add_library(foo SHARED foo.c)

install(TARGETS foo EXPORT FooExport DESTINATION lib )
install(TARGETS foo EXPORT FooExportX DESTINATION libx )

install(EXPORT FooExport  DESTINATION lib/foo )
install(EXPORT FooExport  NAMESPACE "Foo::" DESTINATION lib/foo2 )
install(EXPORT FooExportX DESTINATION lib/fooX )

add_library(bar SHARED bar.c)
target_link_libraries(bar foo)

install(TARGETS bar EXPORT BarExport DESTINATION lib )

install(EXPORT BarExport NAMESPACE Xyz:: DESTINATION lib/bar )

------------------------------------

If I would do this, I would get the error for the BarExport export set, that 
it does not contain target foo, which it depends on.

We'd like to make this work, since we need this in KDE.


How can this be done ?
Here's a relatively simple (I think) idea: export it anyway, and make sure in 
the generated targets file that those targets which were not part of the 
export-set exist:

if(NOT TARGET Xyz::foo)
  message(FATAL_ERROR "Exported Xyz::target foo not found")
endif()


This would leave it to the user to make sure that the export file is loaded 
before.
There is an issue with the used namespace. Maybe it could simply assume that 
the targets which are not present use the same namespace as it does itself (as 
shown in the example above) ?

Also, CMake could still error out if it detects that a library which an 
exported library depends on, is not exported at all, also taking into account 
the namespace.

Would that work ?
Did I miss something ?
Better ideas ?

Alex



More information about the cmake-developers mailing list