From d9f836e9567dbcce85b917300e8de9086aa1f1f7 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Sun, 26 Jun 2016 00:12:52 +0200 Subject: Add a getter for manually added target dependencies Closes: #16165 --- Help/manual/cmake-properties.7.rst | 1 + Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst | 8 ++++++++ Help/release/dev/manually-added-dependencies.rst | 6 ++++++ Source/cmTarget.cxx | 17 +++++++++++++++++ .../add_dependencies/ReadOnlyProperty-result.txt | 1 + .../add_dependencies/ReadOnlyProperty-stderr.txt | 1 + Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake | 6 ++++++ .../add_dependencies/RetrieveDependencies.cmake | 16 ++++++++++++++++ Tests/RunCMake/add_dependencies/RunCMakeTest.cmake | 2 ++ Tests/RunCMake/add_dependencies/a.c | 3 +++ Tests/RunCMake/add_dependencies/b.c | 3 +++ Tests/RunCMake/add_dependencies/c.c | 3 +++ 12 files changed, 67 insertions(+) create mode 100644 Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst create mode 100644 Help/release/dev/manually-added-dependencies.rst create mode 100644 Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt create mode 100644 Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt create mode 100644 Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake create mode 100644 Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake create mode 100644 Tests/RunCMake/add_dependencies/a.c create mode 100644 Tests/RunCMake/add_dependencies/b.c create mode 100644 Tests/RunCMake/add_dependencies/c.c 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() +{ +} -- cgit v0.12