diff options
-rw-r--r-- | Help/manual/cmake-properties.7.rst | 1 | ||||
-rw-r--r-- | Help/prop_tgt/MANUALLY_ADDED_DEPENDENCIES.rst | 8 | ||||
-rw-r--r-- | Help/release/dev/manually-added-dependencies.rst | 6 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 17 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/ReadOnlyProperty-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/ReadOnlyProperty-stderr.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/ReadOnlyProperty.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/RetrieveDependencies.cmake | 16 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/RunCMakeTest.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/a.c | 3 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/b.c | 3 | ||||
-rw-r--r-- | Tests/RunCMake/add_dependencies/c.c | 3 |
12 files changed, 67 insertions, 0 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 864d1dc077..5b39bedfaa 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 0000000000..c12ea147cc --- /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 0000000000..6c486daae6 --- /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 9261ca8440..d825e5c7df 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 0000000000..d00491fd7e --- /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 0000000000..da30b81ada --- /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 0000000000..f0e4069eda --- /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 0000000000..45b3974420 --- /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 30b7e674f8..507d43fd56 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 0000000000..707c1c3805 --- /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 0000000000..57b290030c --- /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 0000000000..cbf94ca3bc --- /dev/null +++ b/Tests/RunCMake/add_dependencies/c.c @@ -0,0 +1,3 @@ +void c() +{ +} |