Commit d9f836e9 authored by Gregor Jasny's avatar Gregor Jasny
Browse files

Add a getter for manually added target dependencies

Closes: #16165
parent 35ad12f9
Pipeline #42988 passed with stage
......@@ -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
......
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.
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`.
......@@ -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";
}
......
MANUALLY_ADDED_DEPENDENCIES property is read-only
cmake_minimum_required(VERSION 3.7)
project(ReadOnlyProperty C)
add_library(a a.c)
set_property(TARGET a PROPERTY MANUALLY_ADDED_DEPENDENCIES DEPENDENCIES foo)
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()
include(RunCMake)
run_cmake(NoTarget)
run_cmake(ReadOnlyProperty)
run_cmake(RetrieveDependencies)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment