summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeniz Bahadir <dbahadir@benocs.com>2017-09-14 11:15:08 (GMT)
committerBrad King <brad.king@kitware.com>2017-10-26 13:11:04 (GMT)
commit494906a8a21f44e9233632d9be7f93ee3990aaaf (patch)
tree027746c20b4cc38e33f4ec9e30e295c2d89da23a
parentfe4b25ec2fa09a50b6ffbfcf29e118afdfba0659 (diff)
downloadCMake-494906a8a21f44e9233632d9be7f93ee3990aaaf.zip
CMake-494906a8a21f44e9233632d9be7f93ee3990aaaf.tar.gz
CMake-494906a8a21f44e9233632d9be7f93ee3990aaaf.tar.bz2
Add support for IMPORTED GLOBAL targets to be aliased
Issue: #15569 Issue: #17197
-rw-r--r--Help/command/add_executable.rst5
-rw-r--r--Help/command/add_library.rst3
-rw-r--r--Source/cmAddExecutableCommand.cxx11
-rw-r--r--Source/cmAddLibraryCommand.cxx7
-rw-r--r--Tests/RunCMake/alias_targets/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/alias_targets/imported-global-target-stderr.txt2
-rw-r--r--Tests/RunCMake/alias_targets/imported-global-target.cmake46
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-stderr.txt12
-rw-r--r--Tests/RunCMake/alias_targets/imported-target.cmake44
9 files changed, 109 insertions, 22 deletions
diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst
index 6763620..c7a30d7 100644
--- a/Help/command/add_executable.rst
+++ b/Help/command/add_executable.rst
@@ -74,8 +74,9 @@ properties for more information.
Creates an :ref:`Alias Target <Alias Targets>`, such that ``<name>`` can
be used to refer to ``<target>`` in subsequent commands. The ``<name>``
does not appear in the generated buildsystem as a make target. The
-``<target>`` may not be an :ref:`Imported Target <Imported Targets>` or an
-``ALIAS``. ``ALIAS`` targets can be used as targets to read properties
+``<target>`` may not be a non-``GLOBAL``
+:ref:`Imported Target <Imported Targets>` or an ``ALIAS``.
+``ALIAS`` targets can be used as targets to read properties
from, executables for custom commands and custom targets. They can also be
tested for existence with the regular :command:`if(TARGET)` subcommand.
The ``<name>`` may not be used to modify properties of ``<target>``, that
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
index 78b316d..4e85d8c 100644
--- a/Help/command/add_library.rst
+++ b/Help/command/add_library.rst
@@ -125,7 +125,8 @@ Alias Libraries
Creates an :ref:`Alias Target <Alias Targets>`, such that ``<name>`` can be
used to refer to ``<target>`` in subsequent commands. The ``<name>`` does
not appear in the generated buildsystem as a make target. The ``<target>``
-may not be an :ref:`Imported Target <Imported Targets>` or an ``ALIAS``.
+may not be a non-``GLOBAL`` :ref:`Imported Target <Imported Targets>` or an
+``ALIAS``.
``ALIAS`` targets can be used as linkable targets and as targets to
read properties from. They can also be tested for existence with the
regular :command:`if(TARGET)` subcommand. The ``<name>`` may not be used
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index 262e3a1..053e34c 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -140,8 +140,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
if (!aliasedTarget) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" does not already "
- "exist.";
+ << aliasedName << "\" does not already exist.";
this->SetError(e.str());
return false;
}
@@ -149,15 +148,15 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
if (type != cmStateEnums::EXECUTABLE) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" is not an "
- "executable.";
+ << aliasedName << "\" is not an executable.";
this->SetError(e.str());
return false;
}
- if (aliasedTarget->IsImported()) {
+ if (aliasedTarget->IsImported() &&
+ !aliasedTarget->IsImportedGloballyVisible()) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" is IMPORTED.";
+ << aliasedName << "\" is imported but not globally visible.";
this->SetError(e.str());
return false;
}
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index 31c2ecf..9129047 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -256,13 +256,6 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
this->SetError(e.str());
return false;
}
- if (aliasedTarget->IsImported()) {
- std::ostringstream e;
- e << "cannot create ALIAS target \"" << libName << "\" because target \""
- << aliasedName << "\" is IMPORTED.";
- this->SetError(e.str());
- return false;
- }
this->Makefile->AddAlias(libName, aliasedName);
return true;
}
diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
index 9a5eaaf..dded248 100644
--- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
@@ -6,6 +6,7 @@ run_cmake(exclude-from-all)
run_cmake(imported)
run_cmake(invalid-name)
run_cmake(invalid-target)
+run_cmake(imported-global-target)
run_cmake(imported-target)
run_cmake(alias-target)
run_cmake(set_property)
diff --git a/Tests/RunCMake/alias_targets/imported-global-target-stderr.txt b/Tests/RunCMake/alias_targets/imported-global-target-stderr.txt
new file mode 100644
index 0000000..8259c80
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-global-target-stderr.txt
@@ -0,0 +1,2 @@
+^'alias-test-exe' is an alias for 'test-exe' and its name-property contains 'test-exe'.
+'alias-test-lib' is an alias for 'test-lib' and its name-property contains 'test-lib'.$
diff --git a/Tests/RunCMake/alias_targets/imported-global-target.cmake b/Tests/RunCMake/alias_targets/imported-global-target.cmake
new file mode 100644
index 0000000..12c4e0a
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-global-target.cmake
@@ -0,0 +1,46 @@
+
+enable_language(CXX)
+
+
+add_executable(test-exe IMPORTED GLOBAL)
+add_executable(alias-test-exe ALIAS test-exe)
+
+if(TARGET alias-test-exe)
+ get_target_property(aliased-target alias-test-exe ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-exe")
+ get_target_property(aliased-name alias-test-exe NAME)
+ if("${aliased-name}" STREQUAL "test-exe")
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-exe' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-exe' does not exist!?")
+endif()
+
+
+add_library(test-lib SHARED IMPORTED GLOBAL)
+add_library(alias-test-lib ALIAS test-lib)
+
+if(TARGET alias-test-lib)
+ get_target_property(aliased-target alias-test-lib ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-lib")
+ get_target_property(aliased-name alias-test-lib NAME)
+ if("${aliased-name}" STREQUAL "test-lib")
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-lib' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-lib' does not exist!?")
+endif()
diff --git a/Tests/RunCMake/alias_targets/imported-target-stderr.txt b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
index bbff29a..12ffbc2 100644
--- a/Tests/RunCMake/alias_targets/imported-target-stderr.txt
+++ b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
@@ -1,5 +1,9 @@
-CMake Error at imported-target.cmake:6 \(add_library\):
- add_library cannot create ALIAS target "alias" because target "foo" is
- IMPORTED.
+^CMake Error at imported-target.cmake:[0-9]+ \(add_executable\):
+ add_executable cannot create ALIAS target \"alias-test-exe\" because target
+ \"test-exe\" is imported but not globally visible.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
+
+
+'alias-test-exe' does not exist![?]
+'alias-test-lib' does not exist![?]$
diff --git a/Tests/RunCMake/alias_targets/imported-target.cmake b/Tests/RunCMake/alias_targets/imported-target.cmake
index 7259ab0..bb682fe 100644
--- a/Tests/RunCMake/alias_targets/imported-target.cmake
+++ b/Tests/RunCMake/alias_targets/imported-target.cmake
@@ -1,6 +1,46 @@
enable_language(CXX)
-add_library(foo SHARED IMPORTED)
-add_library(alias ALIAS foo)
+add_executable(test-exe IMPORTED)
+add_executable(alias-test-exe ALIAS test-exe)
+
+if(TARGET alias-test-exe)
+ get_target_property(aliased-target alias-test-exe ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-exe")
+ get_target_property(aliased-name alias-test-exe NAME)
+ if("${aliased-name}" STREQUAL "test-exe")
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-exe' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-exe' does not exist!?")
+endif()
+
+
+add_library(test-lib SHARED IMPORTED)
+add_library(alias-test-lib ALIAS test-lib)
+
+if(TARGET alias-test-lib)
+ get_target_property(aliased-target alias-test-lib ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-lib")
+ get_target_property(aliased-name alias-test-lib NAME)
+ if("${aliased-name}" STREQUAL "test-lib")
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-lib' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-lib' does not exist!?")
+endif()