QCMake.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef QCMake_h
  11. #define QCMake_h
  12. #include <cmConfigure.h>
  13. #include "cmake.h"
  14. #ifdef _MSC_VER
  15. #pragma warning(disable : 4127)
  16. #pragma warning(disable : 4512)
  17. #endif
  18. #include <vector>
  19. #include <QAtomicInt>
  20. #include <QList>
  21. #include <QMetaType>
  22. #include <QObject>
  23. #include <QString>
  24. #include <QStringList>
  25. #include <QVariant>
  26. /// struct to represent cmake properties in Qt
  27. /// Value is of type String or Bool
  28. struct QCMakeProperty
  29. {
  30. enum PropertyType
  31. {
  32. BOOL,
  33. PATH,
  34. FILEPATH,
  35. STRING
  36. };
  37. QString Key;
  38. QVariant Value;
  39. QStringList Strings;
  40. QString Help;
  41. PropertyType Type;
  42. bool Advanced;
  43. bool operator==(const QCMakeProperty& other) const
  44. {
  45. return this->Key == other.Key;
  46. }
  47. bool operator<(const QCMakeProperty& other) const
  48. {
  49. return this->Key < other.Key;
  50. }
  51. };
  52. // list of properties
  53. typedef QList<QCMakeProperty> QCMakePropertyList;
  54. // allow QVariant to be a property or list of properties
  55. Q_DECLARE_METATYPE(QCMakeProperty)
  56. Q_DECLARE_METATYPE(QCMakePropertyList)
  57. /// Qt API for CMake library.
  58. /// Wrapper like class allows for easier integration with
  59. /// Qt features such as, signal/slot connections, multi-threading, etc..
  60. class QCMake : public QObject
  61. {
  62. Q_OBJECT
  63. public:
  64. QCMake(QObject* p = CM_NULLPTR);
  65. ~QCMake();
  66. public slots:
  67. /// load the cache file in a directory
  68. void loadCache(const QString& dir);
  69. /// set the source directory containing the source
  70. void setSourceDirectory(const QString& dir);
  71. /// set the binary directory to build in
  72. void setBinaryDirectory(const QString& dir);
  73. /// set the desired generator to use
  74. void setGenerator(const QString& generator);
  75. /// set the desired generator to use
  76. void setToolset(const QString& toolset);
  77. /// do the configure step
  78. void configure();
  79. /// generate the files
  80. void generate();
  81. /// set the property values
  82. void setProperties(const QCMakePropertyList&);
  83. /// interrupt the configure or generate process (if connecting, make a direct
  84. /// connection)
  85. void interrupt();
  86. /// delete the cache in binary directory
  87. void deleteCache();
  88. /// reload the cache in binary directory
  89. void reloadCache();
  90. /// set whether to do debug output
  91. void setDebugOutput(bool);
  92. /// get whether to do suppress dev warnings
  93. bool getSuppressDevWarnings();
  94. /// set whether to do suppress dev warnings
  95. void setSuppressDevWarnings(bool value);
  96. /// get whether to do suppress deprecated warnings
  97. bool getSuppressDeprecatedWarnings();
  98. /// set whether to do suppress deprecated warnings
  99. void setSuppressDeprecatedWarnings(bool value);
  100. /// get whether to treat developer (author) warnings as errors
  101. bool getDevWarningsAsErrors();
  102. /// set whether to treat developer (author) warnings as errors
  103. void setDevWarningsAsErrors(bool value);
  104. /// get whether to treat deprecated warnings as errors
  105. bool getDeprecatedWarningsAsErrors();
  106. /// set whether to treat deprecated warnings as errors
  107. void setDeprecatedWarningsAsErrors(bool value);
  108. /// set whether to run cmake with warnings about uninitialized variables
  109. void setWarnUninitializedMode(bool value);
  110. /// set whether to run cmake with warnings about unused variables
  111. void setWarnUnusedMode(bool value);
  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. protected:
  151. cmake* CMakeInstance;
  152. static bool interruptCallback(void*);
  153. static void progressCallback(const char* msg, float percent, void* cd);
  154. static void messageCallback(const char* msg, const char* title, bool&,
  155. void* cd);
  156. static void stdoutCallback(const char* msg, size_t len, void* cd);
  157. static void stderrCallback(const char* msg, size_t len, void* cd);
  158. bool WarnUninitializedMode;
  159. bool WarnUnusedMode;
  160. bool WarnUnusedAllMode;
  161. QString SourceDirectory;
  162. QString BinaryDirectory;
  163. QString Generator;
  164. QString Toolset;
  165. std::vector<cmake::GeneratorInfo> AvailableGenerators;
  166. QString CMakeExecutable;
  167. QAtomicInt InterruptFlag;
  168. };
  169. #endif // QCMake_h