QCMake.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 setToolset(const QString& toolset);
  70. /// do the configure step
  71. void configure();
  72. /// generate the files
  73. void generate();
  74. /// open the project
  75. void open();
  76. /// set the property values
  77. void setProperties(const QCMakePropertyList&);
  78. /// interrupt the configure or generate process (if connecting, make a direct
  79. /// connection)
  80. void interrupt();
  81. /// delete the cache in binary directory
  82. void deleteCache();
  83. /// reload the cache in binary directory
  84. void reloadCache();
  85. /// set whether to do debug output
  86. void setDebugOutput(bool);
  87. /// get whether to do suppress dev warnings
  88. bool getSuppressDevWarnings();
  89. /// set whether to do suppress dev warnings
  90. void setSuppressDevWarnings(bool value);
  91. /// get whether to do suppress deprecated warnings
  92. bool getSuppressDeprecatedWarnings();
  93. /// set whether to do suppress deprecated warnings
  94. void setSuppressDeprecatedWarnings(bool value);
  95. /// get whether to treat developer (author) warnings as errors
  96. bool getDevWarningsAsErrors();
  97. /// set whether to treat developer (author) warnings as errors
  98. void setDevWarningsAsErrors(bool value);
  99. /// get whether to treat deprecated warnings as errors
  100. bool getDeprecatedWarningsAsErrors();
  101. /// set whether to treat deprecated warnings as errors
  102. void setDeprecatedWarningsAsErrors(bool value);
  103. /// set whether to run cmake with warnings about uninitialized variables
  104. void setWarnUninitializedMode(bool value);
  105. /// set whether to run cmake with warnings about unused variables
  106. void setWarnUnusedMode(bool value);
  107. /// check if project IDE open is possible and emit openPossible signal
  108. void checkOpenPossible();
  109. public:
  110. /// get the list of cache properties
  111. QCMakePropertyList properties() const;
  112. /// get the current binary directory
  113. QString binaryDirectory() const;
  114. /// get the current source directory
  115. QString sourceDirectory() const;
  116. /// get the current generator
  117. QString generator() const;
  118. /// get the available generators
  119. std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
  120. /// get whether to do debug output
  121. bool getDebugOutput() const;
  122. signals:
  123. /// signal when properties change (during read from disk or configure
  124. /// process)
  125. void propertiesChanged(const QCMakePropertyList& vars);
  126. /// signal when the generator changes
  127. void generatorChanged(const QString& gen);
  128. /// signal when the source directory changes (binary directory already
  129. /// containing a CMakeCache.txt file)
  130. void sourceDirChanged(const QString& dir);
  131. /// signal when the binary directory changes
  132. void binaryDirChanged(const QString& dir);
  133. /// signal for progress events
  134. void progressChanged(const QString& msg, float percent);
  135. /// signal when configure is done
  136. void configureDone(int error);
  137. /// signal when generate is done
  138. void generateDone(int error);
  139. /// signal when there is an output message
  140. void outputMessage(const QString& msg);
  141. /// signal when there is an error message
  142. void errorMessage(const QString& msg);
  143. /// signal when debug output changes
  144. void debugOutputChanged(bool);
  145. /// signal when the toolset changes
  146. void toolsetChanged(const QString& toolset);
  147. /// signal when open is done
  148. void openDone(bool successful);
  149. /// signal when open is done
  150. void openPossible(bool possible);
  151. protected:
  152. cmake* CMakeInstance;
  153. static bool interruptCallback(void*);
  154. static void progressCallback(const char* msg, float percent, void* cd);
  155. static void messageCallback(const char* msg, const char* title, bool&,
  156. void* cd);
  157. static void stdoutCallback(const char* msg, size_t len, void* cd);
  158. static void stderrCallback(const char* msg, size_t len, void* cd);
  159. bool WarnUninitializedMode;
  160. bool WarnUnusedMode;
  161. bool WarnUnusedAllMode;
  162. QString SourceDirectory;
  163. QString BinaryDirectory;
  164. QString Generator;
  165. QString Toolset;
  166. std::vector<cmake::GeneratorInfo> AvailableGenerators;
  167. QString CMakeExecutable;
  168. QAtomicInt InterruptFlag;
  169. };
  170. #endif // QCMake_h