QCMake.h 5.8 KB

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