QCMake.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <QObject>
  17. #include <QString>
  18. #include <QVariant>
  19. #include <QList>
  20. #include <QStringList>
  21. #include <QMetaType>
  22. #include <QAtomicInt>
  23. class cmake;
  24. /// struct to represent cmake properties in Qt
  25. /// Value is of type String or Bool
  26. struct QCMakeProperty
  27. {
  28. enum PropertyType { BOOL, PATH, FILEPATH, STRING };
  29. QString Key;
  30. QVariant Value;
  31. QStringList Strings;
  32. QString Help;
  33. PropertyType Type;
  34. bool Advanced;
  35. bool operator==(const QCMakeProperty& other) const
  36. {
  37. return this->Key == other.Key;
  38. }
  39. bool operator<(const QCMakeProperty& other) const
  40. {
  41. return this->Key < other.Key;
  42. }
  43. };
  44. // list of properties
  45. typedef QList<QCMakeProperty> QCMakePropertyList;
  46. // allow QVariant to be a property or list of properties
  47. Q_DECLARE_METATYPE(QCMakeProperty)
  48. Q_DECLARE_METATYPE(QCMakePropertyList)
  49. /// Qt API for CMake library.
  50. /// Wrapper like class allows for easier integration with
  51. /// Qt features such as, signal/slot connections, multi-threading, etc..
  52. class QCMake : public QObject
  53. {
  54. Q_OBJECT
  55. public:
  56. QCMake(QObject* p=0);
  57. ~QCMake();
  58. public slots:
  59. /// load the cache file in a directory
  60. void loadCache(const QString& dir);
  61. /// set the source directory containing the source
  62. void setSourceDirectory(const QString& dir);
  63. /// set the binary directory to build in
  64. void setBinaryDirectory(const QString& dir);
  65. /// set the desired generator to use
  66. void setGenerator(const QString& generator);
  67. /// do the configure step
  68. void configure();
  69. /// generate the files
  70. void generate();
  71. /// set the property values
  72. void setProperties(const QCMakePropertyList&);
  73. /// interrupt the configure or generate process (if connecting, make a direct connection)
  74. void interrupt();
  75. /// delete the cache in binary directory
  76. void deleteCache();
  77. /// reload the cache in binary directory
  78. void reloadCache();
  79. /// set whether to do debug output
  80. void setDebugOutput(bool);
  81. /// set whether to do suppress dev warnings
  82. void setSuppressDevWarnings(bool value);
  83. /// set whether to run cmake with warnings about uninitialized variables
  84. void setWarnUninitializedMode(bool value);
  85. /// set whether to run cmake with warnings about unused variables
  86. void setWarnUnusedMode(bool value);
  87. public:
  88. /// get the list of cache properties
  89. QCMakePropertyList properties() const;
  90. /// get the current binary directory
  91. QString binaryDirectory() const;
  92. /// get the current source directory
  93. QString sourceDirectory() const;
  94. /// get the current generator
  95. QString generator() const;
  96. /// get the available generators
  97. QStringList availableGenerators() const;
  98. /// get whether to do debug output
  99. bool getDebugOutput() const;
  100. signals:
  101. /// signal when properties change (during read from disk or configure process)
  102. void propertiesChanged(const QCMakePropertyList& vars);
  103. /// signal when the generator changes
  104. void generatorChanged(const QString& gen);
  105. /// signal when the source directory changes (binary directory already
  106. /// containing a CMakeCache.txt file)
  107. void sourceDirChanged(const QString& dir);
  108. /// signal when the binary directory changes
  109. void binaryDirChanged(const QString& dir);
  110. /// signal for progress events
  111. void progressChanged(const QString& msg, float percent);
  112. /// signal when configure is done
  113. void configureDone(int error);
  114. /// signal when generate is done
  115. void generateDone(int error);
  116. /// signal when there is an output message
  117. void outputMessage(const QString& msg);
  118. /// signal when there is an error message
  119. void errorMessage(const QString& msg);
  120. /// signal when debug output changes
  121. void debugOutputChanged(bool);
  122. protected:
  123. cmake* CMakeInstance;
  124. static bool interruptCallback(void*);
  125. static void progressCallback(const char* msg, float percent, void* cd);
  126. static void messageCallback(const char* msg, const char* title,
  127. bool&, void* cd);
  128. bool SuppressDevWarnings;
  129. bool WarnUninitializedMode;
  130. bool WarnUnusedMode;
  131. bool WarnUnusedAllMode;
  132. QString SourceDirectory;
  133. QString BinaryDirectory;
  134. QString Generator;
  135. QStringList AvailableGenerators;
  136. QString CMakeExecutable;
  137. QAtomicInt InterruptFlag;
  138. };
  139. #endif // __QCMake_h