Add directory property to list imported targets

Model the change after commit cbca65826c (Add directory property to list
buildsystem targets, 2016-09-19, v3.7.0-rc1~79^2~1).

Fixes: #22291
This commit is contained in:
Brad King 2021-06-10 15:41:39 -04:00
parent ea6d338ea1
commit e13704ce72
8 changed files with 41 additions and 0 deletions

View File

@ -74,6 +74,7 @@ Properties on Directories
/prop_dir/DEFINITIONS /prop_dir/DEFINITIONS
/prop_dir/EXCLUDE_FROM_ALL /prop_dir/EXCLUDE_FROM_ALL
/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM /prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
/prop_dir/IMPORTED_TARGETS
/prop_dir/INCLUDE_DIRECTORIES /prop_dir/INCLUDE_DIRECTORIES
/prop_dir/INCLUDE_REGULAR_EXPRESSION /prop_dir/INCLUDE_REGULAR_EXPRESSION
/prop_dir/INTERPROCEDURAL_OPTIMIZATION /prop_dir/INTERPROCEDURAL_OPTIMIZATION

View File

@ -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 :ref:`Interface Libraries`. Each entry in the list is the logical name
of a target, suitable to pass to the :command:`get_property` command of a target, suitable to pass to the :command:`get_property` command
``TARGET`` option. ``TARGET`` option.
See also the :prop_dir:`IMPORTED_TARGETS` directory property.

View File

@ -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.

View File

@ -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.

View File

@ -8,7 +8,9 @@
#include <vector> #include <vector>
#include <cm/iterator> #include <cm/iterator>
#include <cm/string_view>
#include <cmext/algorithm> #include <cmext/algorithm>
#include <cmext/string_view>
#include "cmAlgorithms.h" #include "cmAlgorithms.h"
#include "cmProperty.h" #include "cmProperty.h"
@ -475,6 +477,10 @@ cmProp cmStateDirectory::GetProperty(const std::string& prop, bool chain) const
output = cmJoin(this->DirectoryState->NormalTargetNames, ";"); output = cmJoin(this->DirectoryState->NormalTargetNames, ";");
return &output; return &output;
} }
if (prop == "IMPORTED_TARGETS"_s) {
output = cmJoin(this->DirectoryState->ImportedTargetNames, ";");
return &output;
}
if (prop == "LISTFILE_STACK") { if (prop == "LISTFILE_STACK") {
std::vector<std::string> listFiles; std::vector<std::string> listFiles;

View File

@ -12,6 +12,10 @@ get_directory_property: -->CustomTop;InterfaceTop<--
get_property: -->CustomTop;InterfaceTop<-- get_property: -->CustomTop;InterfaceTop<--
get_directory_property: -->CustomSub;InterfaceSub<-- get_directory_property: -->CustomSub;InterfaceSub<--
get_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_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build<-- get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build<--
get_directory_property: -->[^<;]*/RunCMake/get_property<-- get_directory_property: -->[^<;]*/RunCMake/get_property<--

View File

@ -18,11 +18,16 @@ add_custom_target(CustomTop)
add_library(InterfaceTop INTERFACE) add_library(InterfaceTop INTERFACE)
add_library(my::InterfaceTop ALIAS InterfaceTop) add_library(my::InterfaceTop ALIAS InterfaceTop)
add_library(Imported1Top INTERFACE IMPORTED)
add_library(Imported2Top INTERFACE IMPORTED)
add_subdirectory(directory_properties) add_subdirectory(directory_properties)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SUBDIRECTORIES) 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}/directory_properties" SUBDIRECTORIES)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" BUILDSYSTEM_TARGETS) 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}/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}" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR) check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR)

View File

@ -5,5 +5,8 @@ add_custom_target(CustomSub)
add_library(InterfaceSub INTERFACE) add_library(InterfaceSub INTERFACE)
add_library(my::InterfaceSub ALIAS InterfaceSub) 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/test1 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test1")
add_test(Sub/test2 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test2") add_test(Sub/test2 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test2")