QCMake.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 "cmCMakePresetsFile.h"
  6. #include "cmake.h"
  7. #ifdef _MSC_VER
  8. # pragma warning(disable : 4127)
  9. # pragma warning(disable : 4512)
  10. #endif
  11. #include <memory>
  12. #include <vector>
  13. #include "QCMakePreset.h"
  14. #include <QAtomicInt>
  15. #include <QList>
  16. #include <QMetaType>
  17. #include <QObject>
  18. #include <QProcessEnvironment>
  19. #include <QString>
  20. #include <QStringList>
  21. #include <QTimer>
  22. #include <QVariant>
  23. /// struct to represent cmake properties in Qt
  24. /// Value is of type String or Bool
  25. struct QCMakeProperty
  26. {
  27. enum PropertyType
  28. {
  29. BOOL,
  30. PATH,
  31. FILEPATH,
  32. STRING
  33. };
  34. QString Key;
  35. QVariant Value;
  36. QStringList Strings;
  37. QString Help;
  38. PropertyType Type;
  39. bool Advanced;
  40. bool operator==(const QCMakeProperty& other) const
  41. {
  42. return this->Key == other.Key;
  43. }
  44. bool operator<(const QCMakeProperty& other) const
  45. {
  46. return this->Key < other.Key;
  47. }
  48. };
  49. // list of properties
  50. using QCMakePropertyList = QList<QCMakeProperty>;
  51. // allow QVariant to be a property or list of properties
  52. Q_DECLARE_METATYPE(QCMakeProperty)
  53. Q_DECLARE_METATYPE(QCMakePropertyList)
  54. Q_DECLARE_METATYPE(QProcessEnvironment)
  55. Q_DECLARE_METATYPE(cmCMakePresetsFile::ReadFileResult)
  56. /// Qt API for CMake library.
  57. /// Wrapper like class allows for easier integration with
  58. /// Qt features such as, signal/slot connections, multi-threading, etc..
  59. class QCMake : public QObject
  60. {
  61. Q_OBJECT
  62. public:
  63. QCMake(QObject* p = nullptr);
  64. ~QCMake();
  65. public slots:
  66. /// load the cache file in a directory
  67. void loadCache(const QString& dir);
  68. /// set the source directory containing the source
  69. void setSourceDirectory(const QString& dir);
  70. /// set the binary directory to build in
  71. void setBinaryDirectory(const QString& dir);
  72. /// set the preset name to use
  73. void setPreset(const QString& name, bool setBinary = true);
  74. /// set the desired generator to use
  75. void setGenerator(const QString& generator);
  76. /// set the desired generator to use
  77. void setPlatform(const QString& platform);
  78. /// set the desired generator to use
  79. void setToolset(const QString& toolset);
  80. /// set the configure and generate environment
  81. void setEnvironment(const QProcessEnvironment& environment);
  82. /// do the configure step
  83. void configure();
  84. /// generate the files
  85. void generate();
  86. /// open the project
  87. void open();
  88. /// set the property values
  89. void setProperties(const QCMakePropertyList&);
  90. /// interrupt the configure or generate process (if connecting, make a direct
  91. /// connection)
  92. void interrupt();
  93. /// delete the cache in binary directory
  94. void deleteCache();
  95. /// reload the cache in binary directory
  96. void reloadCache();
  97. /// set whether to do debug output
  98. void setDebugOutput(bool);
  99. /// get whether to do suppress dev warnings
  100. bool getSuppressDevWarnings();
  101. /// set whether to do suppress dev warnings
  102. void setSuppressDevWarnings(bool value);
  103. /// get whether to do suppress deprecated warnings
  104. bool getSuppressDeprecatedWarnings();
  105. /// set whether to do suppress deprecated warnings
  106. void setSuppressDeprecatedWarnings(bool value);
  107. /// get whether to treat developer (author) warnings as errors
  108. bool getDevWarningsAsErrors();
  109. /// set whether to treat developer (author) warnings as errors
  110. void setDevWarningsAsErrors(bool value);
  111. /// get whether to treat deprecated warnings as errors
  112. bool getDeprecatedWarningsAsErrors();
  113. /// set whether to treat deprecated warnings as errors
  114. void setDeprecatedWarningsAsErrors(bool value);
  115. /// set whether to run cmake with warnings about uninitialized variables
  116. void setWarnUninitializedMode(bool value);
  117. /// check if project IDE open is possible and emit openPossible signal
  118. void checkOpenPossible();
  119. public:
  120. /// get the list of cache properties
  121. QCMakePropertyList properties() const;
  122. /// get the current binary directory
  123. QString binaryDirectory() const;
  124. /// get the current source directory
  125. QString sourceDirectory() const;
  126. /// get the current generator
  127. QString generator() const;
  128. /// get the configure and generate environment
  129. QProcessEnvironment environment() const;
  130. /// get the available generators
  131. std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
  132. /// get whether to do debug output
  133. bool getDebugOutput() const;
  134. signals:
  135. /// signal when properties change (during read from disk or configure
  136. /// process)
  137. void propertiesChanged(const QCMakePropertyList& vars);
  138. /// signal when the generator changes
  139. void generatorChanged(const QString& gen);
  140. /// signal when the source directory changes (binary directory already
  141. /// containing a CMakeCache.txt file)
  142. void sourceDirChanged(const QString& dir);
  143. /// signal when the binary directory changes
  144. void binaryDirChanged(const QString& dir);
  145. /// signal when the preset list changes
  146. void presetsChanged(const QVector<QCMakePreset>& presets);
  147. /// signal when the selected preset changes
  148. void presetChanged(const QString& name);
  149. /// signal when there's an error reading the presets files
  150. void presetLoadError(const QString& dir,
  151. cmCMakePresetsFile::ReadFileResult error);
  152. /// signal when uninitialized warning changes
  153. void warnUninitializedModeChanged(bool value);
  154. /// signal for progress events
  155. void progressChanged(const QString& msg, float percent);
  156. /// signal when configure is done
  157. void configureDone(int error);
  158. /// signal when generate is done
  159. void generateDone(int error);
  160. /// signal when there is an output message
  161. void outputMessage(const QString& msg);
  162. /// signal when there is an error message
  163. void errorMessage(const QString& msg);
  164. /// signal when debug output changes
  165. void debugOutputChanged(bool);
  166. /// signal when the toolset changes
  167. void toolsetChanged(const QString& toolset);
  168. /// signal when the platform changes
  169. void platformChanged(const QString& platform);
  170. /// signal when open is done
  171. void openDone(bool successful);
  172. /// signal when open is done
  173. void openPossible(bool possible);
  174. protected:
  175. std::unique_ptr<cmake> CMakeInstance;
  176. bool interruptCallback();
  177. void progressCallback(std::string const& msg, float percent);
  178. void messageCallback(std::string const& msg, const char* title);
  179. void stdoutCallback(std::string const& msg);
  180. void stderrCallback(std::string const& msg);
  181. void setUpEnvironment() const;
  182. void loadPresets();
  183. bool WarnUninitializedMode;
  184. QString SourceDirectory;
  185. QString BinaryDirectory;
  186. QString Generator;
  187. QString Platform;
  188. QString Toolset;
  189. std::vector<cmake::GeneratorInfo> AvailableGenerators;
  190. cmCMakePresetsFile CMakePresetsFile;
  191. cmCMakePresetsFile::ReadFileResult LastLoadPresetsResult =
  192. cmCMakePresetsFile::ReadFileResult::READ_OK;
  193. QString PresetName;
  194. QString CMakeExecutable;
  195. QAtomicInt InterruptFlag;
  196. QProcessEnvironment StartEnvironment;
  197. QProcessEnvironment Environment;
  198. QTimer LoadPresetsTimer;
  199. };