[cmake-developers] Strange behaviour with install(EXPORT)
Alex Merry
alex.merry at kde.org
Mon Jul 27 13:39:58 EDT 2015
Suppose you have a CMakeLists.txt file like
=================================
cmake_minimum_required(VERSION 2.8.12)
project(Foo)
add_library(Ext::Imported SHARED IMPORTED)
add_library(FooDep SHARED main.cpp)
install(TARGETS FooDep
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
add_library(FooMain SHARED main.cpp)
target_link_libraries(FooMain
PUBLIC
Ext::Imported
PRIVATE
FooDep
)
install(TARGETS FooMain
EXPORT FooTargets
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
install(EXPORT FooTargets
NAMESPACE Foo::
DESTINATION "lib/cmake/Foo"
FILE FooTargets.cmake)
=================================
This fails with the error
CMake Error: install(EXPORT "FooTargets" ...) includes target "FooMain" which
requires target "FooDep" that is not in the export set.
It is not obvious from what I have read of the documentation that this should
happen, but (looking at the CMake code), this seems to be deliberate - the
issue is in trying to populate IMPORTED_LINK_DEPENDENT_LIBRARIES for the
exported target, it wants the private dependencies as well as the interface
ones. So it wants FooDep to be EXPORTed, even though this may be a private
internal library.
However, removing the PUBLIC dependencies of FooMain suppresses this error,
presumably because the INTERFACE_LINK_LIBRARIES property is not set, so
cmTargetInternals::ComputeLinkInterfaceLibraries does not set
iface.ExplicitLibraries for the target, so
cmTargetInternals::ComputeLinkInterface does not add anything to
iface.SharedDeps, which is what is used to populate
IMPORTED_LINK_DEPENDENT_LIBRARIES.
This difference in behaviour does not make sense. So either neither case
should be an error, or both cases should be. However, I don't know which it
is.
Alex
More information about the cmake-developers
mailing list