summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-properties.7.rst1
-rw-r--r--Help/prop_dir/BUILDSYSTEM_TARGETS.rst2
-rw-r--r--Help/prop_dir/IMPORTED_TARGETS.rst14
-rw-r--r--Help/release/dev/dir-IMPORTED_TARGETS.rst6
-rw-r--r--Source/cmMakefile.cxx1
-rw-r--r--Source/cmState.cxx1
-rw-r--r--Source/cmStateDirectory.cxx11
-rw-r--r--Source/cmStateDirectory.h1
-rw-r--r--Source/cmStatePrivate.h1
-rw-r--r--Tests/RunCMake/get_property/directory_properties-stderr.txt4
-rw-r--r--Tests/RunCMake/get_property/directory_properties.cmake5
-rw-r--r--Tests/RunCMake/get_property/directory_properties/CMakeLists.txt3
12 files changed, 50 insertions, 0 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 2db1ec2..5f18a82 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -74,6 +74,7 @@ Properties on Directories
/prop_dir/DEFINITIONS
/prop_dir/EXCLUDE_FROM_ALL
/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ /prop_dir/IMPORTED_TARGETS
/prop_dir/INCLUDE_DIRECTORIES
/prop_dir/INCLUDE_REGULAR_EXPRESSION
/prop_dir/INTERPROCEDURAL_OPTIMIZATION
diff --git a/Help/prop_dir/BUILDSYSTEM_TARGETS.rst b/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
index 5c5893d..c998488 100644
--- a/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
+++ b/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
@@ -11,3 +11,5 @@ and :command:`add_custom_target` commands. The list does not include any
:ref:`Interface Libraries`. Each entry in the list is the logical name
of a target, suitable to pass to the :command:`get_property` command
``TARGET`` option.
+
+See also the :prop_dir:`IMPORTED_TARGETS` directory property.
diff --git a/Help/prop_dir/IMPORTED_TARGETS.rst b/Help/prop_dir/IMPORTED_TARGETS.rst
new file mode 100644
index 0000000..fea8a93
--- /dev/null
+++ b/Help/prop_dir/IMPORTED_TARGETS.rst
@@ -0,0 +1,14 @@
+IMPORTED_TARGETS
+----------------
+
+.. versionadded:: 3.21
+
+This read-only directory property contains a
+:ref:`semicolon-separated list <CMake Language Lists>` of
+:ref:`Imported Targets` added in the directory by calls to the
+:command:`add_library` and :command:`add_executable` commands.
+Each entry in the list is the logical name of a target, suitable
+to pass to the :command:`get_property` command ``TARGET`` option
+when called in the same directory.
+
+See also the :prop_dir:`BUILDSYSTEM_TARGETS` directory property.
diff --git a/Help/release/dev/dir-IMPORTED_TARGETS.rst b/Help/release/dev/dir-IMPORTED_TARGETS.rst
new file mode 100644
index 0000000..a2797ec
--- /dev/null
+++ b/Help/release/dev/dir-IMPORTED_TARGETS.rst
@@ -0,0 +1,6 @@
+dir-IMPORTED_TARGETS
+--------------------
+
+* The :prop_dir:`IMPORTED_TARGETS` directory property was added to
+ get a list of :ref:`Imported Targets` created in the current
+ directory.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 908b3f0..d2d34f9 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4134,6 +4134,7 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
// Add to the set of available imported targets.
this->ImportedTargets[name] = target.get();
this->GetGlobalGenerator()->IndexTarget(target.get());
+ this->GetStateSnapshot().GetDirectory().AddImportedTargetName(name);
// Transfer ownership to this cmMakefile object.
this->ImportedTargetsOwned.push_back(std::move(target));
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index d97762b..0b8a64b 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -286,6 +286,7 @@ cmStateSnapshot cmState::Reset()
it->LinkDirectoriesBacktraces.clear();
it->DirectoryEnd = pos;
it->NormalTargetNames.clear();
+ it->ImportedTargetNames.clear();
it->Properties.Clear();
it->Children.clear();
}
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx
index 9ae2861..c898dd4 100644
--- a/Source/cmStateDirectory.cxx
+++ b/Source/cmStateDirectory.cxx
@@ -8,7 +8,9 @@
#include <vector>
#include <cm/iterator>
+#include <cm/string_view>
#include <cmext/algorithm>
+#include <cmext/string_view>
#include "cmAlgorithms.h"
#include "cmProperty.h"
@@ -475,6 +477,10 @@ cmProp cmStateDirectory::GetProperty(const std::string& prop, bool chain) const
output = cmJoin(this->DirectoryState->NormalTargetNames, ";");
return &output;
}
+ if (prop == "IMPORTED_TARGETS"_s) {
+ output = cmJoin(this->DirectoryState->ImportedTargetNames, ";");
+ return &output;
+ }
if (prop == "LISTFILE_STACK") {
std::vector<std::string> listFiles;
@@ -546,3 +552,8 @@ void cmStateDirectory::AddNormalTargetName(std::string const& name)
{
this->DirectoryState->NormalTargetNames.push_back(name);
}
+
+void cmStateDirectory::AddImportedTargetName(std::string const& name)
+{
+ this->DirectoryState->ImportedTargetNames.emplace_back(name);
+}
diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h
index ce00dbb..b8abccb 100644
--- a/Source/cmStateDirectory.h
+++ b/Source/cmStateDirectory.h
@@ -81,6 +81,7 @@ public:
std::vector<std::string> GetPropertyKeys() const;
void AddNormalTargetName(std::string const& name);
+ void AddImportedTargetName(std::string const& name);
private:
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator
diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h
index a437ce2..6f475f2 100644
--- a/Source/cmStatePrivate.h
+++ b/Source/cmStatePrivate.h
@@ -83,6 +83,7 @@ struct cmStateDetail::BuildsystemDirectoryStateType
std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces;
std::vector<std::string> NormalTargetNames;
+ std::vector<std::string> ImportedTargetNames;
std::string ProjectName;
diff --git a/Tests/RunCMake/get_property/directory_properties-stderr.txt b/Tests/RunCMake/get_property/directory_properties-stderr.txt
index 89f5618..be06f0e 100644
--- a/Tests/RunCMake/get_property/directory_properties-stderr.txt
+++ b/Tests/RunCMake/get_property/directory_properties-stderr.txt
@@ -12,6 +12,10 @@ get_directory_property: -->CustomTop;InterfaceTop<--
get_property: -->CustomTop;InterfaceTop<--
get_directory_property: -->CustomSub;InterfaceSub<--
get_property: -->CustomSub;InterfaceSub<--
+get_directory_property: -->Imported1Top;Imported2Top<--
+get_property: -->Imported1Top;Imported2Top<--
+get_directory_property: -->Imported1Sub;Imported2Sub<--
+get_property: -->Imported1Sub;Imported2Sub<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build<--
get_directory_property: -->[^<;]*/RunCMake/get_property<--
diff --git a/Tests/RunCMake/get_property/directory_properties.cmake b/Tests/RunCMake/get_property/directory_properties.cmake
index 9b978fd..4dce524 100644
--- a/Tests/RunCMake/get_property/directory_properties.cmake
+++ b/Tests/RunCMake/get_property/directory_properties.cmake
@@ -18,11 +18,16 @@ add_custom_target(CustomTop)
add_library(InterfaceTop INTERFACE)
add_library(my::InterfaceTop ALIAS InterfaceTop)
+add_library(Imported1Top INTERFACE IMPORTED)
+add_library(Imported2Top INTERFACE IMPORTED)
+
add_subdirectory(directory_properties)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SUBDIRECTORIES)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" SUBDIRECTORIES)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" BUILDSYSTEM_TARGETS)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" BUILDSYSTEM_TARGETS)
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" IMPORTED_TARGETS)
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" IMPORTED_TARGETS)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR)
diff --git a/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt b/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
index 95106ad..9fab799 100644
--- a/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
+++ b/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
@@ -5,5 +5,8 @@ add_custom_target(CustomSub)
add_library(InterfaceSub INTERFACE)
add_library(my::InterfaceSub ALIAS InterfaceSub)
+add_library(Imported1Sub INTERFACE IMPORTED)
+add_library(Imported2Sub INTERFACE IMPORTED)
+
add_test(Sub/test1 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test1")
add_test(Sub/test2 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test2")