[cmake-developers] INTERFACE_LIBRARY target type
Stephen Kelly
steveire at gmail.com
Wed Aug 28 11:31:16 EDT 2013
Hi there,
I've rebased and pushed the INTERFACE_LIBRARY-target-type branch to my clone
again.
I'd like to get this one in to the next release soon after it opens for
features, but there are still a few things to discuss about how it should
work.
Relevant previous threads:
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/6691
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/3615/focus=5320
1) We already have ALIAS targets, which leaves INTERFACE_LIBRARY to cover
the uses cases of
add_library(iface INTERFACE)
target_link_libraries(iface INTERFACE bing sing)
target_link_libraries(foo INTERFACE bar iface bat)
and
add_library(iface INTERFACE)
target_link_libraries(iface INTERFACE bing sing)
target_link_libraries(foo INTERFACE
bar
$<TARGET_PROPERTY:iface,INTERFACE_LINK_LIBRARIES>
bat
)
I think that's fine.
2) In my branch, the 'old' (IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?
are always ignored for INTERFACE_LIBRARY types, for simplicity like the
above, and always being able to rely on the INTERFACE_LINK_LIBRARIES
property for them.
3) I have left a TODO note in cmLocalGenerator.cxx about the return value
from GetRealDependency.
4) The target_* commands always need to be invoked with an explicit
INTERFACE option.
5) The INTERFACE_LIBRARY can be installed and exported, resulting in
add_library(Foo::iface INTERFACE IMPORTED)
# ...
In my branch, the versions are a bit messed up in the install(EXPORT) code,
due to what's currently in master. That will be cleaned later.
6) When we get transitive INTERFACE_SOURCES, it will be possible to 'link
to' OBJECT_LIBRARYs:
add_library(obj OBJECT foo.cpp)
add_library(obj_iface INTERFACE)
set_property(TARGET obj_iface
PROPERTY INTERFACE_SOURCES $<TARGET_OBJECTS:obj>
)
add_executable(user main.cpp)
target_link_libraries(user obj_iface)
So, it might make sense to revisit whether it is allowed to link to
OBJECT_LIBRARYs. Either way, the obj_iface can't be exported in this case,
because the dependent obj library can't be exported.
7) I've only implemented the support for this target type in the Makefile
generator so far. I can also do the Ninja one after all of the details about
how it works are sorted out.
Can someone else implement the VS and Xcode support? I'm too unfamiliar with
those generators.
8) I made it possible to use
make iface
to build the *dependencies* of iface. The special /requires /depends and
/build sub-targets are not generated for INTERFACE_LIBRARY targets.
9) INTERFACE_LIBRARY targets are always effectively EXCLUDE_FROM_ALL because
they have no direct outputs.
Is there anything I'm missing here?
Thanks,
Steve.
More information about the cmake-developers
mailing list