summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-08-10 21:31:07 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-08-11 14:50:52 (GMT)
commit84e76fedb0255ac4d0524f47268be79598b096fc (patch)
tree18d5ccaf3b16920ea7710494eb5e94e3ade063b8
parentefc8f19cc5b4442cbfb9c40f36b8d3909d42cd92 (diff)
downloadCMake-84e76fedb0255ac4d0524f47268be79598b096fc.zip
CMake-84e76fedb0255ac4d0524f47268be79598b096fc.tar.gz
CMake-84e76fedb0255ac4d0524f47268be79598b096fc.tar.bz2
get_property(TEST): Add DIRECTORY option
-rw-r--r--Help/command/get_property.rst13
-rw-r--r--Help/release/dev/test-properties-directory.rst3
-rw-r--r--Source/cmGetPropertyCommand.cxx32
3 files changed, 40 insertions, 8 deletions
diff --git a/Help/command/get_property.rst b/Help/command/get_property.rst
index 6b9931e..a0a12bb 100644
--- a/Help/command/get_property.rst
+++ b/Help/command/get_property.rst
@@ -12,7 +12,8 @@ Get a property.
SOURCE <source>
[DIRECTORY <dir> | TARGET_DIRECTORY <target>] |
INSTALL <file> |
- TEST <test> |
+ TEST <test>
+ [DIRECTORY <dir>] |
CACHE <entry> |
VARIABLE >
PROPERTY <name>
@@ -73,6 +74,16 @@ It must be one of the following:
Scope must name one existing test.
See also the :command:`get_test_property` command.
+ .. versionadded:: 3.28
+ Directory scope can be overridden with the following sub-option:
+
+ ``DIRECTORY <dir>``
+ The test property will be read from the ``<dir>`` directory's
+ scope. CMake must already know about the directory, either by having added
+ it through a call to :command:`add_subdirectory` or ``<dir>`` being the top
+ level directory. Relative paths are treated as relative to the current
+ source directory. ``<dir>`` may reference a binary directory.
+
``CACHE``
Scope must name one cache entry.
diff --git a/Help/release/dev/test-properties-directory.rst b/Help/release/dev/test-properties-directory.rst
index 7a36372..2daa533 100644
--- a/Help/release/dev/test-properties-directory.rst
+++ b/Help/release/dev/test-properties-directory.rst
@@ -7,3 +7,6 @@ test-properties-directory
* The :command:`set_tests_properties` command gained a ``DIRECTORY``
sub-option, which allows you to set properties on tests in other
directories.
+* The ``TEST`` mode of the :command:`get_property` command gained a
+ ``DIRECTORY`` sub-option, which allows you to get properties on tests in
+ other directories.
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx
index 943ce1d..880756d 100644
--- a/Source/cmGetPropertyCommand.cxx
+++ b/Source/cmGetPropertyCommand.cxx
@@ -49,7 +49,8 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
bool source_file_paths_should_be_absolute);
bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
OutType infoType, const std::string& variable,
- const std::string& propertyName);
+ const std::string& propertyName,
+ cmMakefile& directory_makefile);
bool HandleVariableMode(cmExecutionStatus& status, const std::string& name,
OutType infoType, const std::string& variable,
const std::string& propertyName);
@@ -81,6 +82,9 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
bool source_file_directory_option_enabled = false;
bool source_file_target_option_enabled = false;
+ std::string test_directory;
+ bool test_directory_option_enabled = false;
+
// Get the scope from which to get the property.
cmProperty::ScopeType scope;
if (args[1] == "GLOBAL") {
@@ -116,7 +120,8 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
DoingProperty,
DoingType,
DoingSourceDirectory,
- DoingSourceTargetDirectory
+ DoingSourceTargetDirectory,
+ DoingTestDirectory,
};
Doing doing = DoingName;
for (unsigned int i = 2; i < args.size(); ++i) {
@@ -145,12 +150,19 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
args[i] == "TARGET_DIRECTORY") {
doing = DoingSourceTargetDirectory;
source_file_target_option_enabled = true;
+ } else if (doing == DoingNone && scope == cmProperty::TEST &&
+ args[i] == "DIRECTORY") {
+ doing = DoingTestDirectory;
+ test_directory_option_enabled = true;
} else if (doing == DoingSourceDirectory) {
source_file_directories.push_back(args[i]);
doing = DoingNone;
} else if (doing == DoingSourceTargetDirectory) {
source_file_target_directories.push_back(args[i]);
doing = DoingNone;
+ } else if (doing == DoingTestDirectory) {
+ test_directory = args[i];
+ doing = DoingNone;
} else if (doing == DoingProperty) {
doing = DoingNone;
propertyName = args[i];
@@ -167,12 +179,17 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
}
std::vector<cmMakefile*> source_file_directory_makefiles;
- bool file_scopes_handled =
+ bool source_file_scopes_handled =
SetPropertyCommand::HandleAndValidateSourceFileDirectoryScopes(
status, source_file_directory_option_enabled,
source_file_target_option_enabled, source_file_directories,
source_file_target_directories, source_file_directory_makefiles);
- if (!file_scopes_handled) {
+ cmMakefile* test_directory_makefile;
+ bool test_scopes_handled =
+ SetPropertyCommand::HandleAndValidateTestDirectoryScopes(
+ status, test_directory_option_enabled, test_directory,
+ test_directory_makefile);
+ if (!(source_file_scopes_handled && test_scopes_handled)) {
return false;
}
@@ -231,7 +248,8 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
directory_scope_mf,
source_file_paths_should_be_absolute);
case cmProperty::TEST:
- return HandleTestMode(status, name, infoType, variable, propertyName);
+ return HandleTestMode(status, name, infoType, variable, propertyName,
+ *test_directory_makefile);
case cmProperty::VARIABLE:
return HandleVariableMode(status, name, infoType, variable,
propertyName);
@@ -404,7 +422,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
OutType infoType, const std::string& variable,
- const std::string& propertyName)
+ const std::string& propertyName, cmMakefile& test_makefile)
{
if (name.empty()) {
status.SetError("not given name for TEST scope.");
@@ -412,7 +430,7 @@ bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
}
// Loop over all tests looking for matching names.
- if (cmTest* test = status.GetMakefile().GetTest(name)) {
+ if (cmTest* test = test_makefile.GetTest(name)) {
return StoreResult(infoType, status.GetMakefile(), variable,
test->GetProperty(propertyName));
}