summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregor Jasny <gjasny@googlemail.com>2016-06-25 22:12:52 (GMT)
committerGregor Jasny <gjasny@googlemail.com>2017-01-16 21:38:24 (GMT)
commitd9f836e9567dbcce85b917300e8de9086aa1f1f7 (patch)
tree3b54a2cae815ff859c09d6c934cab0446315bf3f
parent35ad12f99e71515f9cc65b1219160b88095a5f6b (diff)
downloadCMake-d9f836e9567dbcce85b917300e8de9086aa1f1f7.zip
CMake-d9f836e9567dbcce85b917300e8de9086aa1f1f7.tar.gz
CMake-d9f836e9567dbcce85b917300e8de9086aa1f1f7.tar.bz2
Add a getter for manually added target dependencies
Closes: #16165
-rw-r--r--Help/manual/cmake-properties.7.rst1
-rw-r--r--Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst8
-rw-r--r--Help/release/dev/manually-added-dependencies.rst6
-rw-r--r--Source/cmTarget.cxx17
-rw-r--r--Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt1
-rw-r--r--Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt1
-rw-r--r--Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake6
-rw-r--r--Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake16
-rw-r--r--Tests/RunCMake/add_dependencies/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/add_dependencies/a.c3
-rw-r--r--Tests/RunCMake/add_dependencies/b.c3
-rw-r--r--Tests/RunCMake/add_dependencies/c.c3
12 files changed, 67 insertions, 0 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 864d1dc..5b39bed 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -236,6 +236,7 @@ Properties on Targets
/prop_tgt/MACOSX_BUNDLE
/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST
/prop_tgt/MACOSX_RPATH
+ /prop_tgt/MANUALLY_ADDED_DEPENDENCIES
/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG
/prop_tgt/NAME
/prop_tgt/NO_SONAME
diff --git a/Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst b/Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst
new file mode 100644
index 0000000..c12ea14
--- /dev/null
+++ b/Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst
@@ -0,0 +1,8 @@
+MANUALLY_ADDED_DEPENDENCIES
+---------------------------
+
+Get manually added dependencies to other top-level targets.
+
+This read-only property can be used to query all dependencies that
+were added for this target with the :command:`add_dependencies`
+command.
diff --git a/Help/release/dev/manually-added-dependencies.rst b/Help/release/dev/manually-added-dependencies.rst
new file mode 100644
index 0000000..6c486da
--- /dev/null
+++ b/Help/release/dev/manually-added-dependencies.rst
@@ -0,0 +1,6 @@
+manually-added-dependencies
+---------------------------
+
+* The target property :prop_tgt:`MANUALLY_ADDED_DEPENDENCIES` has
+ been added. It is read-only and could be used to retrieve
+ dependencies that have been added with :command:`add_dependencies`.
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 9261ca8..d825e5c 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -852,6 +852,12 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
this->Makefile->GetBacktrace())) {
return;
}
+ if (prop == "MANUALLY_ADDED_DEPENDENCIES") {
+ std::ostringstream e;
+ e << "MANUALLY_ADDED_DEPENDENCIES property is read-only\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return;
+ }
if (prop == "NAME") {
std::ostringstream e;
e << "NAME property is read-only\n";
@@ -1168,6 +1174,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const
MAKE_STATIC_PROP(COMPILE_OPTIONS);
MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
MAKE_STATIC_PROP(IMPORTED);
+ MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
MAKE_STATIC_PROP(NAME);
MAKE_STATIC_PROP(BINARY_DIR);
MAKE_STATIC_PROP(SOURCE_DIR);
@@ -1181,6 +1188,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const
specialProps.insert(propCOMPILE_OPTIONS);
specialProps.insert(propCOMPILE_DEFINITIONS);
specialProps.insert(propIMPORTED);
+ specialProps.insert(propMANUALLY_ADDED_DEPENDENCIES);
specialProps.insert(propNAME);
specialProps.insert(propBINARY_DIR);
specialProps.insert(propSOURCE_DIR);
@@ -1236,6 +1244,15 @@ const char* cmTarget::GetProperty(const std::string& prop) const
output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
return output.c_str();
}
+ if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
+ if (this->Utilities.empty()) {
+ return CM_NULLPTR;
+ }
+
+ static std::string output;
+ output = cmJoin(this->Utilities, ";");
+ return output.c_str();
+ }
if (prop == propIMPORTED) {
return this->IsImported() ? "TRUE" : "FALSE";
}
diff --git a/Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt b/Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt b/Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt
new file mode 100644
index 0000000..da30b81
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt
@@ -0,0 +1 @@
+MANUALLY_ADDED_DEPENDENCIES property is read-only
diff --git a/Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake b/Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake
new file mode 100644
index 0000000..f0e4069
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.7)
+project(ReadOnlyProperty C)
+
+add_library(a a.c)
+
+set_property(TARGET a PROPERTY MANUALLY_ADDED_DEPENDENCIES DEPENDENCIES foo)
diff --git a/Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake b/Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake
new file mode 100644
index 0000000..45b3974
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.7)
+project(RetrieveDependencies C)
+
+add_library(a a.c)
+
+add_library(b c.c)
+target_link_libraries(a b)
+
+add_library(c c.c)
+add_dependencies(a c)
+
+get_property(DEPS_A TARGET a PROPERTY MANUALLY_ADDED_DEPENDENCIES)
+
+if(NOT DEPS_A STREQUAL "c")
+ message(FATAL_ERROR "Expected target c being a dependency of a but got: '${DEPS_A}'")
+endif()
diff --git a/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake b/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake
index 30b7e67..507d43f 100644
--- a/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_dependencies/RunCMakeTest.cmake
@@ -1,3 +1,5 @@
include(RunCMake)
run_cmake(NoTarget)
+run_cmake(ReadOnlyProperty)
+run_cmake(RetrieveDependencies)
diff --git a/Tests/RunCMake/add_dependencies/a.c b/Tests/RunCMake/add_dependencies/a.c
new file mode 100644
index 0000000..707c1c3
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/a.c
@@ -0,0 +1,3 @@
+void a()
+{
+}
diff --git a/Tests/RunCMake/add_dependencies/b.c b/Tests/RunCMake/add_dependencies/b.c
new file mode 100644
index 0000000..57b2900
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/b.c
@@ -0,0 +1,3 @@
+void b()
+{
+}
diff --git a/Tests/RunCMake/add_dependencies/c.c b/Tests/RunCMake/add_dependencies/c.c
new file mode 100644
index 0000000..cbf94ca
--- /dev/null
+++ b/Tests/RunCMake/add_dependencies/c.c
@@ -0,0 +1,3 @@
+void c()
+{
+}