QCMake.h 4.7 KB

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