cmQtAutoGenerator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmQtAutoGenerator_h
  4. #define cmQtAutoGenerator_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmFileTime.h"
  7. #include "cmQtAutoGen.h"
  8. #include <cm/string_view>
  9. #include <mutex>
  10. #include <string>
  11. #include <vector>
  12. class cmMakefile;
  13. /** \class cmQtAutoGenerator
  14. * \brief Base class for QtAutoGen generators
  15. */
  16. class cmQtAutoGenerator : public cmQtAutoGen
  17. {
  18. public:
  19. // -- Types
  20. /** Thread safe logger. */
  21. class Logger
  22. {
  23. public:
  24. // -- Construction
  25. Logger();
  26. ~Logger();
  27. // -- Verbosity
  28. unsigned int Verbosity() const { return this->Verbosity_; }
  29. void SetVerbosity(unsigned int value) { this->Verbosity_ = value; }
  30. void RaiseVerbosity(std::string const& value);
  31. bool Verbose() const { return (this->Verbosity_ != 0); }
  32. void SetVerbose(bool value) { this->Verbosity_ = value ? 1 : 0; }
  33. // -- Color output
  34. bool ColorOutput() const { return this->ColorOutput_; }
  35. void SetColorOutput(bool value);
  36. // -- Log info
  37. void Info(GenT genType, cm::string_view message) const;
  38. // -- Log warning
  39. void Warning(GenT genType, cm::string_view message) const;
  40. // -- Log error
  41. void Error(GenT genType, cm::string_view message) const;
  42. void ErrorCommand(GenT genType, cm::string_view message,
  43. std::vector<std::string> const& command,
  44. std::string const& output) const;
  45. private:
  46. static std::string HeadLine(cm::string_view title);
  47. private:
  48. mutable std::mutex Mutex_;
  49. unsigned int Verbosity_ = 0;
  50. bool ColorOutput_ = false;
  51. };
  52. /** Project directories. */
  53. struct ProjectDirsT
  54. {
  55. std::string Source;
  56. std::string Binary;
  57. std::string CurrentSource;
  58. std::string CurrentBinary;
  59. };
  60. // -- File system methods
  61. static bool MakeParentDirectory(std::string const& filename);
  62. static bool FileRead(std::string& content, std::string const& filename,
  63. std::string* error = nullptr);
  64. static bool FileWrite(std::string const& filename,
  65. std::string const& content,
  66. std::string* error = nullptr);
  67. static bool FileDiffers(std::string const& filename,
  68. std::string const& content);
  69. public:
  70. // -- Constructors
  71. cmQtAutoGenerator();
  72. virtual ~cmQtAutoGenerator();
  73. cmQtAutoGenerator(cmQtAutoGenerator const&) = delete;
  74. cmQtAutoGenerator& operator=(cmQtAutoGenerator const&) = delete;
  75. // -- Run
  76. bool Run(std::string const& infoFile, std::string const& config);
  77. // -- InfoFile
  78. std::string const& InfoFile() const { return InfoFile_; }
  79. cmFileTime const& InfoFileTime() const { return InfoFileTime_; }
  80. std::string const& InfoDir() const { return InfoDir_; }
  81. std::string const& InfoConfig() const { return InfoConfig_; }
  82. // -- Directories
  83. ProjectDirsT const& ProjectDirs() const { return ProjectDirs_; }
  84. // -- Utility
  85. static std::string SettingsFind(std::string const& content, const char* key);
  86. std::string MessagePath(cm::string_view path) const;
  87. protected:
  88. // -- Abstract processing interface
  89. virtual bool Init(cmMakefile* makefile) = 0;
  90. virtual bool Process() = 0;
  91. ProjectDirsT& ProjectDirsRef() { return ProjectDirs_; }
  92. private:
  93. // -- Info settings
  94. std::string InfoFile_;
  95. cmFileTime InfoFileTime_;
  96. std::string InfoDir_;
  97. std::string InfoConfig_;
  98. // -- Directories
  99. ProjectDirsT ProjectDirs_;
  100. };
  101. #endif