Commit 7a4b8d0d authored by Brad King's avatar Brad King
Browse files

Add a directory property to list subdirectories

Add a SUBDIRECTORIES directory property to allow project code to
traverse the directory structure of itself as CMake sees it.
parent 089868a2
......@@ -73,6 +73,7 @@ Properties on Directories
/prop_dir/RULE_LAUNCH_COMPILE
/prop_dir/RULE_LAUNCH_CUSTOM
/prop_dir/RULE_LAUNCH_LINK
/prop_dir/SUBDIRECTORIES
/prop_dir/TEST_INCLUDE_FILE
/prop_dir/VARIABLES
/prop_dir/VS_GLOBAL_SECTION_POST_section
......
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.
directory-list-targets-and-subdirs
----------------------------------
* A :prop_dir:`SUBDIRECTORIES` directory property was added to
get the list of subdirectories added by a project in a directory.
......@@ -29,6 +29,8 @@
#include <string.h>
#include <utility>
static std::string const kSUBDIRECTORIES = "SUBDIRECTORIES";
struct cmState::SnapshotDataType
{
cmState::PositionType ScopeParent;
......@@ -1670,6 +1672,18 @@ const char* cmState::Directory::GetProperty(const std::string& prop,
}
return "";
}
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 == "LISTFILE_STACK") {
std::vector<std::string> listFiles;
cmState::Snapshot snp = this->Snapshot_;
......
......@@ -3,4 +3,8 @@ get_property: --><--
get_directory_property: -->value<--
get_property: -->value<--
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<--$
......@@ -13,3 +13,7 @@ set_directory_properties(PROPERTIES empty "" custom value)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" empty)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" custom)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" noexist)
add_subdirectory(directory_properties)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SUBDIRECTORIES)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" SUBDIRECTORIES)
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