diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-07-12 07:14:31 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-08-02 13:21:00 (GMT) |
commit | 370bf554151a1b272baf62a0ce9823cf9995116e (patch) | |
tree | 8f0a75a9894691c2b56588c3be4b090bf07a1558 /Tests/AliasTarget | |
parent | b341bf2178e3923636735ae1df53a33e5857df7d (diff) | |
download | CMake-370bf554151a1b272baf62a0ce9823cf9995116e.zip CMake-370bf554151a1b272baf62a0ce9823cf9995116e.tar.gz CMake-370bf554151a1b272baf62a0ce9823cf9995116e.tar.bz2 |
Add the ALIAS target concept for libraries and executables.
* The ALIAS name must match a validity regex.
* Executables and libraries may be aliased.
* An ALIAS acts immutable. It can not be used as the lhs
of target_link_libraries or other commands.
* An ALIAS can be used with add_custom_command, add_custom_target,
and add_test in the same way regular targets can.
* The target of an ALIAS can be retrieved with the ALIASED_TARGET
target property.
* An ALIAS does not appear in the generated buildsystem. It
is kept separate from cmMakefile::Targets for that reason.
* A target may have multiple aliases.
* An ALIAS target may not itself have an alias.
* An IMPORTED target may not have an alias.
* An ALIAS may not be exported or imported.
Diffstat (limited to 'Tests/AliasTarget')
-rw-r--r-- | Tests/AliasTarget/CMakeLists.txt | 47 | ||||
-rw-r--r-- | Tests/AliasTarget/bat.cpp | 28 | ||||
-rw-r--r-- | Tests/AliasTarget/commandgenerator.cpp | 15 | ||||
-rw-r--r-- | Tests/AliasTarget/empty.cpp | 7 | ||||
-rw-r--r-- | Tests/AliasTarget/object.cpp | 5 | ||||
-rw-r--r-- | Tests/AliasTarget/object.h | 4 | ||||
-rw-r--r-- | Tests/AliasTarget/targetgenerator.cpp | 13 |
7 files changed, 119 insertions, 0 deletions
diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt new file mode 100644 index 0000000..a5eb0f6 --- /dev/null +++ b/Tests/AliasTarget/CMakeLists.txt @@ -0,0 +1,47 @@ + +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() diff --git a/Tests/AliasTarget/bat.cpp b/Tests/AliasTarget/bat.cpp new file mode 100644 index 0000000..1063c21 --- /dev/null +++ b/Tests/AliasTarget/bat.cpp @@ -0,0 +1,28 @@ + +#ifndef FOO_DEFINE +#error Expected FOO_DEFINE +#endif + +#ifndef BAR_DEFINE +#error Expected Bar_DEFINE +#endif + +#include "commandoutput.h" + +#ifndef COMMANDOUTPUT_DEFINE +#error Expected COMMANDOUTPUT_DEFINE +#endif + +#include "targetoutput.h" + +#ifndef TARGETOUTPUT_DEFINE +#error Expected TARGETOUTPUT_DEFINE +#endif + +#ifdef _WIN32 +__declspec(dllexport) +#endif +int bar() +{ + return 0; +} diff --git a/Tests/AliasTarget/commandgenerator.cpp b/Tests/AliasTarget/commandgenerator.cpp new file mode 100644 index 0000000..23560a4 --- /dev/null +++ b/Tests/AliasTarget/commandgenerator.cpp @@ -0,0 +1,15 @@ + +#include <fstream> + +#include "object.h" + +int main(int argc, char **argv) +{ + std::fstream fout; + fout.open("commandoutput.h", std::ios::out); + if (!fout) + return 1; + fout << "#define COMMANDOUTPUT_DEFINE\n"; + fout.close(); + return object(); +} diff --git a/Tests/AliasTarget/empty.cpp b/Tests/AliasTarget/empty.cpp new file mode 100644 index 0000000..b19427a --- /dev/null +++ b/Tests/AliasTarget/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int main(void) +{ + return 0; +} diff --git a/Tests/AliasTarget/object.cpp b/Tests/AliasTarget/object.cpp new file mode 100644 index 0000000..df09c20 --- /dev/null +++ b/Tests/AliasTarget/object.cpp @@ -0,0 +1,5 @@ + +int object(void) +{ + return 0; +} diff --git a/Tests/AliasTarget/object.h b/Tests/AliasTarget/object.h new file mode 100644 index 0000000..e935f14 --- /dev/null +++ b/Tests/AliasTarget/object.h @@ -0,0 +1,4 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int object(void); diff --git a/Tests/AliasTarget/targetgenerator.cpp b/Tests/AliasTarget/targetgenerator.cpp new file mode 100644 index 0000000..3362414 --- /dev/null +++ b/Tests/AliasTarget/targetgenerator.cpp @@ -0,0 +1,13 @@ + +#include <fstream> + +int main(int argc, char **argv) +{ + std::fstream fout; + fout.open("targetoutput.h", std::ios::out); + if (!fout) + return 1; + fout << "#define TARGETOUTPUT_DEFINE\n"; + fout.close(); + return 0; +} |