cmTest.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/Set if CMP0158 policy is NEW */
  53. bool GetCMP0158IsNew() const
  54. {
  55. return this->PolicyStatusCMP0158 == cmPolicies::NEW;
  56. }
  57. /** Set/Get whether lists in command lines should be expanded. */
  58. bool GetCommandExpandLists() const;
  59. void SetCommandExpandLists(bool b);
  60. private:
  61. cmPropertyMap Properties;
  62. std::string Name;
  63. std::vector<std::string> Command;
  64. bool CommandExpandLists = false;
  65. bool OldStyle;
  66. cmMakefile* Makefile;
  67. cmListFileBacktrace Backtrace;
  68. cmPolicies::PolicyStatus PolicyStatusCMP0158;
  69. };