QCMake.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #ifdef _MSC_VER
  13. #pragma warning ( disable : 4127 )
  14. #pragma warning ( disable : 4512 )
  15. #endif
  16. #include <vector>
  17. #include <QObject>
  18. #include <QString>
  19. #include <QVariant>
  20. #include <QList>
  21. #include <QStringList>
  22. #include <QMetaType>
  23. #include <QAtomicInt>
  24. #include "cmake.h"
  25. /// struct to represent cmake properties in Qt
  26. /// Value is of type String or Bool
  27. struct QCMakeProperty
  28. {
  29. enum PropertyType { BOOL, PATH, FILEPATH, STRING };
  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=0);
  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 connection)
  77. void interrupt();
  78. /// delete the cache in binary directory
  79. void deleteCache();
  80. /// reload the cache in binary directory
  81. void reloadCache();
  82. /// set whether to do debug output
  83. void setDebugOutput(bool);
  84. /// get whether to do suppress dev warnings
  85. bool getSuppressDevWarnings();
  86. /// set whether to do suppress dev warnings
  87. void setSuppressDevWarnings(bool value);
  88. /// get whether to do suppress deprecated warnings
  89. bool getSuppressDeprecatedWarnings();
  90. /// set whether to do suppress deprecated warnings
  91. void setSuppressDeprecatedWarnings(bool value);
  92. /// set whether to run cmake with warnings about uninitialized variables
  93. void setWarnUninitializedMode(bool value);
  94. /// set whether to run cmake with warnings about unused variables
  95. void setWarnUnusedMode(bool value);
  96. public:
  97. /// get the list of cache properties
  98. QCMakePropertyList properties() const;
  99. /// get the current binary directory
  100. QString binaryDirectory() const;
  101. /// get the current source directory
  102. QString sourceDirectory() const;
  103. /// get the current generator
  104. QString generator() const;
  105. /// get the available generators
  106. std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
  107. /// get whether to do debug output
  108. bool getDebugOutput() const;
  109. signals:
  110. /// signal when properties change (during read from disk or configure process)
  111. void propertiesChanged(const QCMakePropertyList& vars);
  112. /// signal when the generator changes
  113. void generatorChanged(const QString& gen);
  114. /// signal when the source directory changes (binary directory already
  115. /// containing a CMakeCache.txt file)
  116. void sourceDirChanged(const QString& dir);
  117. /// signal when the binary directory changes
  118. void binaryDirChanged(const QString& dir);
  119. /// signal for progress events
  120. void progressChanged(const QString& msg, float percent);
  121. /// signal when configure is done
  122. void configureDone(int error);
  123. /// signal when generate is done
  124. void generateDone(int error);
  125. /// signal when there is an output message
  126. void outputMessage(const QString& msg);
  127. /// signal when there is an error message
  128. void errorMessage(const QString& msg);
  129. /// signal when debug output changes
  130. void debugOutputChanged(bool);
  131. /// signal when the toolset changes
  132. void toolsetChanged(const QString& toolset);
  133. protected:
  134. cmake* CMakeInstance;
  135. static bool interruptCallback(void*);
  136. static void progressCallback(const char* msg, float percent, void* cd);
  137. static void messageCallback(const char* msg, const char* title,
  138. bool&, void* cd);
  139. static void stdoutCallback(const char* msg, size_t len, void* cd);
  140. static void stderrCallback(const char* msg, size_t len, void* cd);
  141. bool WarnUninitializedMode;
  142. bool WarnUnusedMode;
  143. bool WarnUnusedAllMode;
  144. QString SourceDirectory;
  145. QString BinaryDirectory;
  146. QString Generator;
  147. QString Toolset;
  148. std::vector<cmake::GeneratorInfo> AvailableGenerators;
  149. QString CMakeExecutable;
  150. QAtomicInt InterruptFlag;
  151. };
  152. #endif // QCMake_h