fe732264e9
This target type only contains INTERFACE_* properties, so it can be used as a structural node. The target-specific commands enforce that they may only be used with the INTERFACE keyword when used with INTERFACE_LIBRARY targets. The old-style target properties matching LINK_INTERFACE_LIBRARIES_<CONFIG> are always ignored for this target type. The name of the INTERFACE_LIBRARY must match a validity generator expression. The validity is similar to that of an ALIAS target, but with the additional restriction that it may not contain double colons. Double colons will carry the meaning of IMPORTED or ALIAS targets in CMake 2.8.13. An ALIAS target may be created for an INTERFACE library. At this point it can not be exported and does not appear in the buildsystem and project files are not created for them. That may be added as a feature in a later commit. The generators need some changes to handle the INTERFACE_LIBRARY targets returned by cmComputeLinkInterface::GetItems. The Ninja generator does not use that API, so it doesn't require changes related to that.
51 lines
1.6 KiB
CMake
51 lines
1.6 KiB
CMake
|
|
cmake_minimum_required(VERSION 2.8.11)
|
|
project(AliasTarget)
|
|
|
|
add_library(foo SHARED empty.cpp)
|
|
add_library(PREFIX::Foo ALIAS foo)
|
|
add_library(Another::Alias ALIAS foo)
|
|
|
|
add_library(objects OBJECT object.cpp)
|
|
add_library(Alias::Objects ALIAS objects)
|
|
|
|
target_compile_definitions(foo PUBLIC FOO_DEFINE)
|
|
|
|
add_library(bar SHARED empty.cpp)
|
|
target_compile_definitions(bar PUBLIC BAR_DEFINE)
|
|
|
|
target_link_libraries(foo LINK_PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:PREFIX::Foo,ALIASED_TARGET>,foo>:bar>)
|
|
|
|
add_executable(AliasTarget commandgenerator.cpp $<TARGET_OBJECTS:Alias::Objects>)
|
|
add_executable(PREFIX::AliasTarget ALIAS AliasTarget)
|
|
add_executable(Generator::Command ALIAS AliasTarget)
|
|
|
|
add_custom_command(OUTPUT commandoutput.h COMMAND Generator::Command)
|
|
|
|
add_library(bat SHARED bat.cpp "${CMAKE_CURRENT_BINARY_DIR}/commandoutput.h")
|
|
target_link_libraries(bat PREFIX::Foo)
|
|
target_include_directories(bat PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
add_executable(targetgenerator targetgenerator.cpp)
|
|
add_executable(Generator::Target ALIAS targetgenerator)
|
|
|
|
add_custom_target(usealias Generator::Target)
|
|
add_dependencies(bat usealias)
|
|
|
|
if (NOT TARGET Another::Alias)
|
|
message(SEND_ERROR "Another::Alias is not considered a target.")
|
|
endif()
|
|
|
|
get_target_property(_alt PREFIX::Foo ALIASED_TARGET)
|
|
if (NOT ${_alt} STREQUAL foo)
|
|
message(SEND_ERROR "ALIASED_TARGET is not foo: ${_alt}")
|
|
endif()
|
|
|
|
get_property(_alt2 TARGET PREFIX::Foo PROPERTY ALIASED_TARGET)
|
|
if (NOT ${_alt2} STREQUAL foo)
|
|
message(SEND_ERROR "ALIASED_TARGET is not foo.")
|
|
endif()
|
|
|
|
add_library(iface INTERFACE)
|
|
add_library(Alias::Iface ALIAS iface)
|