cmGetTestPropertyCommand.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGetTestPropertyCommand.h"
  4. #include "cmExecutionStatus.h"
  5. #include "cmMakefile.h"
  6. #include "cmSetPropertyCommand.h"
  7. #include "cmTest.h"
  8. #include "cmValue.h"
  9. bool cmGetTestPropertyCommand(std::vector<std::string> const& args,
  10. cmExecutionStatus& status)
  11. {
  12. std::vector<std::string>::size_type args_size = args.size();
  13. if (args_size != 3 && args_size != 5) {
  14. status.SetError("called with incorrect number of arguments");
  15. return false;
  16. }
  17. std::string test_directory;
  18. bool test_directory_option_enabled = false;
  19. int var_arg_index = 2;
  20. if (args[2] == "DIRECTORY" && args_size == 5) {
  21. var_arg_index = 4;
  22. test_directory_option_enabled = true;
  23. test_directory = args[3];
  24. }
  25. cmMakefile* test_directory_makefile = &status.GetMakefile();
  26. bool file_scopes_handled =
  27. SetPropertyCommand::HandleAndValidateTestDirectoryScopes(
  28. status, test_directory_option_enabled, test_directory,
  29. test_directory_makefile);
  30. if (!file_scopes_handled) {
  31. return false;
  32. }
  33. std::string const& testName = args[0];
  34. std::string const& var = args[var_arg_index];
  35. cmMakefile& mf = status.GetMakefile();
  36. cmTest* test = test_directory_makefile->GetTest(testName);
  37. if (test) {
  38. cmValue prop;
  39. if (!args[1].empty()) {
  40. prop = test->GetProperty(args[1]);
  41. }
  42. if (prop) {
  43. mf.AddDefinition(var, prop);
  44. return true;
  45. }
  46. }
  47. mf.AddDefinition(var, "NOTFOUND");
  48. return true;
  49. }