1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
10 #include <unordered_set>
13 #include <cm/string_view>
15 #include <cm3p/json/value.h>
17 #include "cmFileTime.h"
18 #include "cmQtAutoGen.h"
20 /** \class cmQtAutoGenerator
21 * \brief Base class for QtAutoGen generators
23 class cmQtAutoGenerator
: public cmQtAutoGen
28 /** Thread safe logger. */
36 unsigned int Verbosity() const { return this->Verbosity_
; }
37 void SetVerbosity(unsigned int value
) { this->Verbosity_
= value
; }
38 void RaiseVerbosity(unsigned int value
);
39 bool Verbose() const { return (this->Verbosity_
!= 0); }
40 void SetVerbose(bool value
) { this->Verbosity_
= value
? 1 : 0; }
42 bool ColorOutput() const { return this->ColorOutput_
; }
43 void SetColorOutput(bool value
);
45 void Info(GenT genType
, cm::string_view message
) const;
47 void Warning(GenT genType
, cm::string_view message
) const;
49 void Error(GenT genType
, cm::string_view message
) const;
50 void ErrorCommand(GenT genType
, cm::string_view message
,
51 std::vector
<std::string
> const& command
,
52 std::string
const& output
) const;
55 static std::string
HeadLine(cm::string_view title
);
57 mutable std::mutex Mutex_
;
58 unsigned int Verbosity_
= 0;
59 bool ColorOutput_
= false;
62 /** Project directories. */
67 std::string CurrentSource
;
68 std::string CurrentBinary
;
71 // -- File system methods
72 static bool MakeParentDirectory(std::string
const& filename
);
73 static bool FileRead(std::string
& content
, std::string
const& filename
,
74 std::string
* error
= nullptr);
75 static bool FileWrite(std::string
const& filename
,
76 std::string
const& content
,
77 std::string
* error
= nullptr);
78 static bool FileDiffers(std::string
const& filename
,
79 std::string
const& content
);
82 cmQtAutoGenerator(GenT genType
);
83 virtual ~cmQtAutoGenerator();
85 cmQtAutoGenerator(cmQtAutoGenerator
const&) = delete;
86 cmQtAutoGenerator
& operator=(cmQtAutoGenerator
const&) = delete;
89 std::string
const& InfoFile() const { return this->InfoFile_
; }
90 std::string
const& InfoDir() const { return this->InfoDir_
; }
91 cmFileTime
const& InfoFileTime() const { return this->InfoFileTime_
; }
92 std::string
const& InfoConfig() const { return this->InfoConfig_
; }
93 std::string
const& ExecutableConfig() const
95 return this->ExecutableConfig_
;
98 // -- Info file parsing
99 /** Info file reader class. */
103 InfoT(cmQtAutoGenerator
& gen
)
108 /** Read json data from a stream. */
109 bool Read(std::istream
& istr
);
111 /** Returns false if the JSON value isn't a string. */
112 bool GetString(std::string
const& key
, std::string
& value
,
113 bool required
) const;
114 bool GetStringConfig(std::string
const& key
, std::string
& value
,
115 bool required
) const;
116 bool GetBool(std::string
const& key
, bool& value
, bool required
) const;
117 bool GetUInt(std::string
const& key
, unsigned int& value
,
118 bool required
) const;
119 /** Returns false if the JSON value isn't an array. */
120 bool GetArray(std::string
const& key
, std::vector
<std::string
>& list
,
121 bool required
) const;
122 bool GetArray(std::string
const& key
,
123 std::unordered_set
<std::string
>& list
, bool required
) const;
124 bool GetArrayConfig(std::string
const& key
, std::vector
<std::string
>& list
,
125 bool required
) const;
127 Json::Value
const& GetValue(std::string
const& key
) const
129 return this->Json_
[key
];
132 /** Returns true if strings were appended to the list. */
133 static bool GetJsonArray(std::vector
<std::string
>& list
,
134 Json::Value
const& jval
);
135 /** Returns true if strings were found in the JSON array. */
136 static bool GetJsonArray(std::unordered_set
<std::string
>& list
,
137 Json::Value
const& jval
);
139 bool LogError(GenT genType
, cm::string_view message
) const;
140 bool LogError(cm::string_view message
) const;
143 std::string
ConfigKey(cm::string_view key
) const;
146 cmQtAutoGenerator
& Gen_
;
150 static std::string
SettingsFind(cm::string_view content
,
151 cm::string_view key
);
154 ProjectDirsT
const& ProjectDirs() const { return this->ProjectDirs_
; }
155 std::string
MessagePath(cm::string_view path
) const;
158 bool Run(cm::string_view infoFile
, cm::string_view config
,
159 cm::string_view executableConfig
);
162 // -- Abstract processing interface
163 virtual bool InitFromInfo(InfoT
const& info
) = 0;
164 virtual bool Process() = 0;
166 Logger
const& Log() const { return this->Logger_
; }
174 std::string InfoFile_
;
175 std::string InfoDir_
;
176 cmFileTime InfoFileTime_
;
177 std::string InfoConfig_
;
178 std::string ExecutableConfig_
;
180 ProjectDirsT ProjectDirs_
;