cmTest.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <string>
  7. #include <vector>
  8. #include "cmListFileCache.h"
  9. #include "cmPolicies.h"
  10. #include "cmPropertyMap.h"
  11. #include "cmValue.h"
  12. class cmMakefile;
  13. /** \class cmTest
  14. * \brief Represent a test
  15. *
  16. * cmTest is representation of a test.
  17. */
  18. class cmTest
  19. {
  20. public:
  21. /**
  22. */
  23. cmTest(cmMakefile* mf);
  24. ~cmTest();
  25. //! Set the test name
  26. void SetName(const std::string& name);
  27. std::string GetName() const { return this->Name; }
  28. void SetCommand(std::vector<std::string> const& command);
  29. std::vector<std::string> const& GetCommand() const { return this->Command; }
  30. //! Set/Get a property of this source file
  31. void SetProperty(const std::string& prop, cmValue value);
  32. void SetProperty(const std::string& prop, std::nullptr_t)
  33. {
  34. this->SetProperty(prop, cmValue{ nullptr });
  35. }
  36. void SetProperty(const std::string& prop, const std::string& value)
  37. {
  38. this->SetProperty(prop, cmValue(value));
  39. }
  40. void AppendProperty(const std::string& prop, const std::string& value,
  41. bool asString = false);
  42. cmValue GetProperty(const std::string& prop) const;
  43. bool GetPropertyAsBool(const std::string& prop) const;
  44. cmPropertyMap& GetProperties() { return this->Properties; }
  45. /** Get the cmMakefile instance that owns this test. */
  46. cmMakefile* GetMakefile() { return this->Makefile; }
  47. /** Get the backtrace of the command that created this test. */
  48. cmListFileBacktrace const& GetBacktrace() const;
  49. /** Get/Set whether this is an old-style test. */
  50. bool GetOldStyle() const { return this->OldStyle; }
  51. void SetOldStyle(bool b) { this->OldStyle = b; }
  52. /** Get if CMP0158 policy is NEW */
  53. bool GetCMP0158IsNew() const
  54. {
  55. return this->PolicyStatusCMP0158 == cmPolicies::NEW;
  56. }
  57. /** Get/Set the CMP0178 policy setting */
  58. cmPolicies::PolicyStatus GetCMP0178() const
  59. {
  60. return this->PolicyStatusCMP0178;
  61. }
  62. void SetCMP0178(cmPolicies::PolicyStatus p)
  63. {
  64. this->PolicyStatusCMP0178 = p;
  65. }
  66. /** Set/Get whether lists in command lines should be expanded. */
  67. bool GetCommandExpandLists() const;
  68. void SetCommandExpandLists(bool b);
  69. private:
  70. cmPropertyMap Properties;
  71. std::string Name;
  72. std::vector<std::string> Command;
  73. bool CommandExpandLists = false;
  74. bool OldStyle;
  75. cmMakefile* Makefile;
  76. cmListFileBacktrace Backtrace;
  77. cmPolicies::PolicyStatus PolicyStatusCMP0158;
  78. cmPolicies::PolicyStatus PolicyStatusCMP0178;
  79. };