QCMake.h 5.9 KB

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