summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-05-16 14:03:33 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-05-16 14:03:39 (GMT)
commitcd5d6dfadae4d177c1ce79530fbc6d7cbc7e43e9 (patch)
tree49f57d1fd1ff24c151526ff4f71b8ae251e90ad8
parentc8c07c24dd6692f5a5d6bfa604e25a8e2275588c (diff)
parentc9349cc1b94a08b4f5ed86a397e72ceed50847dd (diff)
downloadCMake-cd5d6dfadae4d177c1ce79530fbc6d7cbc7e43e9.zip
CMake-cd5d6dfadae4d177c1ce79530fbc6d7cbc7e43e9.tar.gz
CMake-cd5d6dfadae4d177c1ce79530fbc6d7cbc7e43e9.tar.bz2
Merge topic 'subdirectory-linking'
c9349cc1b9 target_link_libraries: Allow use with targets in other directories Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2040
-rw-r--r--Copyright.txt1
-rw-r--r--Help/command/target_link_libraries.rst2
-rw-r--r--Help/release/dev/subdirectory-linking.rst5
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx11
-rw-r--r--Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirImportedTarget-stdout.txt4
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirImportedTarget.cmake17
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirImportedTarget/CMakeLists.txt13
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL-stdout.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL.cmake11
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-stdout.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED.cmake11
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt1
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt5
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget-stdout.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget.cmake10
-rw-r--r--Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt6
19 files changed, 110 insertions, 10 deletions
diff --git a/Copyright.txt b/Copyright.txt
index 660455f..743c634 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -78,6 +78,7 @@ The following individuals and institutions are among the Contributors:
* Nikita Krupen'ko <krnekit@gmail.com>
* NVIDIA Corporation <www.nvidia.com>
* OpenGamma Ltd. <opengamma.com>
+* Patrick Stotko <stotko@cs.uni-bonn.de>
* Per Øyvind Karlsen <peroyvind@mandriva.org>
* Peter Collingbourne <peter@pcc.me.uk>
* Petr Gotthard <gotthard@honeywell.com>
diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst
index fcc2c07..6379730 100644
--- a/Help/command/target_link_libraries.rst
+++ b/Help/command/target_link_libraries.rst
@@ -18,7 +18,7 @@ All of them have the general form::
target_link_libraries(<target> ... <item>... ...)
-The named ``<target>`` must have been created in the current directory by
+The named ``<target>`` must have been created by
a command such as :command:`add_executable` or :command:`add_library` and
must not be an :ref:`ALIAS target <Alias Targets>`.
Repeated calls for the same ``<target>`` append items in the order called.
diff --git a/Help/release/dev/subdirectory-linking.rst b/Help/release/dev/subdirectory-linking.rst
new file mode 100644
index 0000000..1909c36
--- /dev/null
+++ b/Help/release/dev/subdirectory-linking.rst
@@ -0,0 +1,5 @@
+subdirectory-linking
+--------------------
+
+* The :command:`target_link_libraries` command may now be called
+ to modify targets created outside the current directory.
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index 699fff8..53f1213 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -364,7 +364,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
if (this->CurrentProcessingState != ProcessingKeywordLinkInterface &&
this->CurrentProcessingState != ProcessingPlainLinkInterface) {
- // Assure that the target on the LHS was created in the current directory.
+ // Find target on the LHS locally
cmTarget* t =
this->Makefile->FindLocalNonAliasTarget(this->Target->GetName());
if (!t) {
@@ -377,11 +377,18 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
}
}
}
+
+ // If no local target has been found, find it in the global scope
+ if (!t) {
+ t = this->Makefile->GetGlobalGenerator()->FindTarget(
+ this->Target->GetName(), true);
+ }
+
if (!t) {
std::ostringstream e;
e << "Attempt to add link library \"" << lib << "\" to target \""
<< this->Target->GetName()
- << "\" which is not built in this directory.";
+ << "\" which does not exist or is an alias target.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return false;
}
diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
index 97b0888..d61fa5f 100644
--- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
@@ -8,7 +8,10 @@ run_cmake(ImportedTarget)
run_cmake(ImportedTargetFailure)
run_cmake(MixedSignature)
run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses)
+run_cmake(SubDirImportedTarget)
run_cmake(SubDirTarget)
+run_cmake(SubDirTarget-UNKNOWN-IMPORTED)
+run_cmake(SubDirTarget-UNKNOWN-IMPORTED-GLOBAL)
run_cmake(SharedDepNotTarget)
run_cmake(StaticPrivateDepNotExported)
run_cmake(StaticPrivateDepNotTarget)
diff --git a/Tests/RunCMake/target_link_libraries/SubDirImportedTarget-stdout.txt b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget-stdout.txt
new file mode 100644
index 0000000..a7ef260
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget-stdout.txt
@@ -0,0 +1,4 @@
+-- mainexeUnknownImportedGlobal: mainlib;sublib
+-- mainlibUnknownImportedGlobal: mainlib;sublib
+-- subexeUnknownImportedGlobal: mainlib;sublib
+-- sublibUnknownImportedGlobal: mainlib;sublib
diff --git a/Tests/RunCMake/target_link_libraries/SubDirImportedTarget.cmake b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget.cmake
new file mode 100644
index 0000000..738280b
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget.cmake
@@ -0,0 +1,17 @@
+enable_language(C)
+
+add_executable(mainexeUnknownImportedGlobal IMPORTED GLOBAL)
+add_library(mainlibUnknownImportedGlobal UNKNOWN IMPORTED GLOBAL)
+add_library(mainlib empty.c)
+
+add_subdirectory(SubDirImportedTarget)
+
+target_link_libraries(subexeUnknownImportedGlobal INTERFACE mainlib)
+target_link_libraries(subexeUnknownImportedGlobal INTERFACE sublib)
+get_property(subexeUnknownImportedGlobal_libs TARGET subexeUnknownImportedGlobal PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "subexeUnknownImportedGlobal: ${subexeUnknownImportedGlobal_libs}")
+
+target_link_libraries(sublibUnknownImportedGlobal INTERFACE mainlib)
+target_link_libraries(sublibUnknownImportedGlobal INTERFACE sublib)
+get_property(sublibUnknownImportedGlobal_libs TARGET sublibUnknownImportedGlobal PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "sublibUnknownImportedGlobal: ${sublibUnknownImportedGlobal_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirImportedTarget/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget/CMakeLists.txt
new file mode 100644
index 0000000..d67a01c
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirImportedTarget/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_executable(subexeUnknownImportedGlobal IMPORTED GLOBAL)
+add_library(sublibUnknownImportedGlobal UNKNOWN IMPORTED GLOBAL)
+add_library(sublib ../empty.c)
+
+target_link_libraries(mainexeUnknownImportedGlobal INTERFACE mainlib)
+target_link_libraries(mainexeUnknownImportedGlobal INTERFACE sublib)
+get_property(mainexeUnknownImportedGlobal_libs TARGET mainexeUnknownImportedGlobal PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "mainexeUnknownImportedGlobal: ${mainexeUnknownImportedGlobal_libs}")
+
+target_link_libraries(mainlibUnknownImportedGlobal INTERFACE mainlib)
+target_link_libraries(mainlibUnknownImportedGlobal INTERFACE sublib)
+get_property(mainlibUnknownImportedGlobal_libs TARGET mainlibUnknownImportedGlobal PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "mainlibUnknownImportedGlobal: ${mainlibUnknownImportedGlobal_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL-stdout.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL-stdout.txt
new file mode 100644
index 0000000..a8c77cb
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL-stdout.txt
@@ -0,0 +1,2 @@
+-- mainexe: mainlibUnknownImportedGlobal;sublibUnknownImportedGlobal
+-- subexe: mainlibUnknownImportedGlobal;sublibUnknownImportedGlobal
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL.cmake b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL.cmake
new file mode 100644
index 0000000..04d64e6
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL.cmake
@@ -0,0 +1,11 @@
+enable_language(C)
+
+add_executable(mainexe empty.c)
+add_library(mainlibUnknownImportedGlobal UNKNOWN IMPORTED GLOBAL)
+
+add_subdirectory(SubDirTarget-UNKNOWN-IMPORTED-GLOBAL)
+
+target_link_libraries(subexe mainlibUnknownImportedGlobal)
+target_link_libraries(subexe sublibUnknownImportedGlobal)
+get_property(subexe_libs TARGET subexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "subexe: ${subexe_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL/CMakeLists.txt
new file mode 100644
index 0000000..6c0c8b2
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-GLOBAL/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_executable(subexe ../empty.c)
+add_library(sublibUnknownImportedGlobal UNKNOWN IMPORTED GLOBAL)
+
+target_link_libraries(mainexe mainlibUnknownImportedGlobal)
+target_link_libraries(mainexe sublibUnknownImportedGlobal)
+get_property(mainexe_libs TARGET mainexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "mainexe: ${mainexe_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-stdout.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-stdout.txt
new file mode 100644
index 0000000..4980dc9
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED-stdout.txt
@@ -0,0 +1,2 @@
+-- mainexe: mainlibUnknownImported;sublibUnknownImported
+-- subexe: mainlibUnknownImported;sublibUnknownImported
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED.cmake b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED.cmake
new file mode 100644
index 0000000..e476a3f
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED.cmake
@@ -0,0 +1,11 @@
+enable_language(C)
+
+add_executable(mainexe empty.c)
+add_library(mainlibUnknownImported UNKNOWN IMPORTED)
+
+add_subdirectory(SubDirTarget-UNKNOWN-IMPORTED)
+
+target_link_libraries(subexe mainlibUnknownImported)
+target_link_libraries(subexe sublibUnknownImported)
+get_property(subexe_libs TARGET subexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "subexe: ${subexe_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED/CMakeLists.txt
new file mode 100644
index 0000000..4a40a68
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-UNKNOWN-IMPORTED/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_executable(subexe ../empty.c)
+add_library(sublibUnknownImported UNKNOWN IMPORTED)
+
+target_link_libraries(mainexe mainlibUnknownImported)
+target_link_libraries(mainexe sublibUnknownImported)
+get_property(mainexe_libs TARGET mainexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "mainexe: ${mainexe_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt
deleted file mode 100644
index d00491f..0000000
--- a/Tests/RunCMake/target_link_libraries/SubDirTarget-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt
deleted file mode 100644
index 5cd1f23..0000000
--- a/Tests/RunCMake/target_link_libraries/SubDirTarget-stderr.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-^CMake Error at SubDirTarget.cmake:[0-9]+ \(target_link_libraries\):
- Attempt to add link library "m" to target "subexe" which is not built in
- this directory.
-Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget-stdout.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget-stdout.txt
new file mode 100644
index 0000000..646f984
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget-stdout.txt
@@ -0,0 +1,2 @@
+-- mainexe: mainlib;sublib
+-- subexe: mainlib;sublib
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake b/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake
index 32431ce..55c658d 100644
--- a/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget.cmake
@@ -1,3 +1,11 @@
enable_language(C)
+
+add_executable(mainexe empty.c)
+add_library(mainlib empty.c)
+
add_subdirectory(SubDirTarget)
-target_link_libraries(subexe m)
+
+target_link_libraries(subexe mainlib)
+target_link_libraries(subexe sublib)
+get_property(subexe_libs TARGET subexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "subexe: ${subexe_libs}")
diff --git a/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt
index b0b2380..3d956a8 100644
--- a/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt
+++ b/Tests/RunCMake/target_link_libraries/SubDirTarget/CMakeLists.txt
@@ -1 +1,7 @@
add_executable(subexe ../empty.c)
+add_library(sublib ../empty.c)
+
+target_link_libraries(mainexe mainlib)
+target_link_libraries(mainexe sublib)
+get_property(mainexe_libs TARGET mainexe PROPERTY INTERFACE_LINK_LIBRARIES)
+message(STATUS "mainexe: ${mainexe_libs}")