QCMake.h 5.5 KB

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