Merge topic 'directory-list-targets-and-subdirs'

d0be1e15 Add directory properties to get source and binary directories
cbca6582 Add directory property to list buildsystem targets
7a4b8d0d Add a directory property to list subdirectories
089868a2 cmState: Record buildsystem target names in each directory
This commit is contained in:
Brad King 2016-09-20 08:41:01 -04:00 committed by CMake Topic Stage
commit 6b8812c27e
14 changed files with 134 additions and 1 deletions

View File

@ -54,6 +54,8 @@ Properties on Directories
:maxdepth: 1 :maxdepth: 1
/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES /prop_dir/ADDITIONAL_MAKE_CLEAN_FILES
/prop_dir/BINARY_DIR
/prop_dir/BUILDSYSTEM_TARGETS
/prop_dir/CACHE_VARIABLES /prop_dir/CACHE_VARIABLES
/prop_dir/CLEAN_NO_CUSTOM /prop_dir/CLEAN_NO_CUSTOM
/prop_dir/CMAKE_CONFIGURE_DEPENDS /prop_dir/CMAKE_CONFIGURE_DEPENDS
@ -73,6 +75,8 @@ Properties on Directories
/prop_dir/RULE_LAUNCH_COMPILE /prop_dir/RULE_LAUNCH_COMPILE
/prop_dir/RULE_LAUNCH_CUSTOM /prop_dir/RULE_LAUNCH_CUSTOM
/prop_dir/RULE_LAUNCH_LINK /prop_dir/RULE_LAUNCH_LINK
/prop_dir/SOURCE_DIR
/prop_dir/SUBDIRECTORIES
/prop_dir/TEST_INCLUDE_FILE /prop_dir/TEST_INCLUDE_FILE
/prop_dir/VARIABLES /prop_dir/VARIABLES
/prop_dir/VS_GLOBAL_SECTION_POST_section /prop_dir/VS_GLOBAL_SECTION_POST_section

View File

@ -0,0 +1,5 @@
BINARY_DIR
----------
This read-only directory property reports absolute path to the binary
directory corresponding to the source on which it is read.

View File

@ -0,0 +1,11 @@
BUILDSYSTEM_TARGETS
-------------------
This read-only directory property contains a
:ref:`;-list <CMake Language Lists>` of buildsystem targets added in the
directory by calls to the :command:`add_library`, :command:`add_executable`,
and :command:`add_custom_target` commands. The list does not include any
:ref:`Imported Targets` or :ref:`Alias Targets`, but does include
: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.

View File

@ -0,0 +1,5 @@
SOURCE_DIR
----------
This read-only directory property reports absolute path to the source
directory on which it is read.

View File

@ -0,0 +1,15 @@
SUBDIRECTORIES
--------------
This read-only directory property contains a
:ref:`;-list <CMake Language Lists>` of subdirectories processed so far by
the :command:`add_subdirectory` or :command:`subdirs` commands. Each entry is
the absolute path to the source directory (containing the ``CMakeLists.txt``
file). This is suitable to pass to the :command:`get_property` command
``DIRECTORY`` option.
.. note::
The :command:`subdirs` command does not process its arguments until
after the calling directory is fully processed. Therefore looking
up this property in the current directory will not see them.

View File

@ -0,0 +1,16 @@
directory-list-targets-and-subdirs
----------------------------------
* A :prop_dir:`SOURCE_DIR` directory property was added to get the
absolute path to the source directory associated with a directory.
* A :prop_dir:`BINARY_DIR` directory property was added to get the
absolute path to the binary directory corresponding to the source
directory on which the property is read.
* A :prop_dir:`BUILDSYSTEM_TARGETS` directory property was added to
get the list of logical buildsystem target names added by the
project in a directory.
* A :prop_dir:`SUBDIRECTORIES` directory property was added to
get the list of subdirectories added by a project in a directory.

View File

@ -1930,6 +1930,7 @@ cmTarget* cmMakefile::AddNewTarget(cmState::TargetType type,
name, cmTarget(name, type, cmTarget::VisibilityNormal, this))) name, cmTarget(name, type, cmTarget::VisibilityNormal, this)))
.first; .first;
this->GetGlobalGenerator()->IndexTarget(&it->second); this->GetGlobalGenerator()->IndexTarget(&it->second);
this->GetStateSnapshot().GetDirectory().AddNormalTargetName(name);
return &it->second; return &it->second;
} }

View File

@ -29,6 +29,11 @@
#include <string.h> #include <string.h>
#include <utility> #include <utility>
static std::string const kBINARY_DIR = "BINARY_DIR";
static std::string const kBUILDSYSTEM_TARGETS = "BUILDSYSTEM_TARGETS";
static std::string const kSOURCE_DIR = "SOURCE_DIR";
static std::string const kSUBDIRECTORIES = "SUBDIRECTORIES";
struct cmState::SnapshotDataType struct cmState::SnapshotDataType
{ {
cmState::PositionType ScopeParent; cmState::PositionType ScopeParent;
@ -94,6 +99,8 @@ struct cmState::BuildsystemDirectoryStateType
std::vector<std::string> CompileOptions; std::vector<std::string> CompileOptions;
std::vector<cmListFileBacktrace> CompileOptionsBacktraces; std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
std::vector<std::string> NormalTargetNames;
std::string ProjectName; std::string ProjectName;
cmPropertyMap Properties; cmPropertyMap Properties;
@ -324,6 +331,7 @@ cmState::Snapshot cmState::Reset()
it->CompileOptions.clear(); it->CompileOptions.clear();
it->CompileOptionsBacktraces.clear(); it->CompileOptionsBacktraces.clear();
it->DirectoryEnd = pos; it->DirectoryEnd = pos;
it->NormalTargetNames.clear();
it->Properties.clear(); it->Properties.clear();
it->Children.clear(); it->Children.clear();
} }
@ -1667,6 +1675,30 @@ const char* cmState::Directory::GetProperty(const std::string& prop,
} }
return ""; return "";
} }
if (prop == kBINARY_DIR) {
output = this->GetCurrentBinary();
return output.c_str();
}
if (prop == kSOURCE_DIR) {
output = this->GetCurrentSource();
return output.c_str();
}
if (prop == kSUBDIRECTORIES) {
std::vector<std::string> child_dirs;
std::vector<cmState::Snapshot> const& children =
this->DirectoryState->Children;
for (std::vector<cmState::Snapshot>::const_iterator ci = children.begin();
ci != children.end(); ++ci) {
child_dirs.push_back(ci->GetDirectory().GetCurrentSource());
}
output = cmJoin(child_dirs, ";");
return output.c_str();
}
if (prop == kBUILDSYSTEM_TARGETS) {
output = cmJoin(this->DirectoryState->NormalTargetNames, ";");
return output.c_str();
}
if (prop == "LISTFILE_STACK") { if (prop == "LISTFILE_STACK") {
std::vector<std::string> listFiles; std::vector<std::string> listFiles;
cmState::Snapshot snp = this->Snapshot_; cmState::Snapshot snp = this->Snapshot_;
@ -1733,6 +1765,11 @@ std::vector<std::string> cmState::Directory::GetPropertyKeys() const
return keys; return keys;
} }
void cmState::Directory::AddNormalTargetName(std::string const& name)
{
this->DirectoryState->NormalTargetNames.push_back(name);
}
bool operator==(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs) bool operator==(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
{ {
return lhs.Position == rhs.Position; return lhs.Position == rhs.Position;

View File

@ -175,6 +175,8 @@ public:
bool GetPropertyAsBool(const std::string& prop) const; bool GetPropertyAsBool(const std::string& prop) const;
std::vector<std::string> GetPropertyKeys() const; std::vector<std::string> GetPropertyKeys() const;
void AddNormalTargetName(std::string const& name);
private: private:
void ComputeRelativePathTopSource(); void ComputeRelativePathTopSource();
void ComputeRelativePathTopBinary(); void ComputeRelativePathTopBinary();

View File

@ -3,4 +3,20 @@ get_property: --><--
get_directory_property: -->value<-- get_directory_property: -->value<--
get_property: -->value<-- get_property: -->value<--
get_directory_property: --><-- get_directory_property: --><--
get_property: --><--$ get_property: --><--
get_directory_property: -->[^<;]*Tests/RunCMake/get_property/directory_properties<--
get_property: -->[^<;]*Tests/RunCMake/get_property/directory_properties<--
get_directory_property: -->[^<;]*Tests/RunCMake/get_property/directory_properties/sub1;[^<;]*Tests/RunCMake/get_property/directory_properties/sub2<--
get_property: -->[^<;]*Tests/RunCMake/get_property/directory_properties/sub1;[^<;]*Tests/RunCMake/get_property/directory_properties/sub2<--
get_directory_property: -->CustomTop;InterfaceTop<--
get_property: -->CustomTop;InterfaceTop<--
get_directory_property: -->CustomSub;InterfaceSub<--
get_property: -->CustomSub;InterfaceSub<--
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<--
get_property: -->[^<;]*/Tests/RunCMake/get_property<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--$

View File

@ -13,3 +13,18 @@ set_directory_properties(PROPERTIES empty "" custom value)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" empty) check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" empty)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" custom) check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" custom)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" noexist) check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" noexist)
add_custom_target(CustomTop)
add_library(InterfaceTop INTERFACE)
add_library(my::InterfaceTop ALIAS InterfaceTop)
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}" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" SOURCE_DIR)

View File

@ -0,0 +1,6 @@
add_subdirectory(sub1)
subdirs(sub2)
add_custom_target(CustomSub)
add_library(InterfaceSub INTERFACE)
add_library(my::InterfaceSub ALIAS InterfaceSub)