QCMake.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef __QCMake_h
  14. #define __QCMake_h
  15. #ifdef _MSC_VER
  16. #pragma warning ( disable : 4127 )
  17. #pragma warning ( disable : 4512 )
  18. #endif
  19. #include <QObject>
  20. #include <QString>
  21. #include <QVariant>
  22. #include <QList>
  23. #include <QStringList>
  24. #include <QMetaType>
  25. class cmake;
  26. /// struct to represent cache properties in Qt
  27. /// Value is of type String or Bool
  28. struct QCMakeCacheProperty
  29. {
  30. enum PropertyType { BOOL, PATH, FILEPATH, STRING };
  31. QString Key;
  32. QVariant Value;
  33. QString Help;
  34. PropertyType Type;
  35. bool Advanced;
  36. bool operator==(const QCMakeCacheProperty& other) const
  37. {
  38. return this->Key == other.Key;
  39. }
  40. bool operator<(const QCMakeCacheProperty& other) const
  41. {
  42. return this->Key < other.Key;
  43. }
  44. };
  45. // make types usable with QVariant
  46. Q_DECLARE_METATYPE(QCMakeCacheProperty)
  47. typedef QList<QCMakeCacheProperty> QCMakeCachePropertyList;
  48. Q_DECLARE_METATYPE(QCMakeCachePropertyList)
  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 QCMakeCachePropertyList&);
  73. /// interrupt the configure or generate process
  74. void interrupt();
  75. /// delete the cache in binary directory
  76. void deleteCache();
  77. /// reload the cache in binary directory
  78. void reloadCache();
  79. public:
  80. /// get the list of cache properties
  81. QCMakeCachePropertyList properties() const;
  82. /// get the current binary directory
  83. QString binaryDirectory() const;
  84. /// get the current source directory
  85. QString sourceDirectory() const;
  86. /// get the current generator
  87. QString generator() const;
  88. /// get the available generators
  89. QStringList availableGenerators() const;
  90. signals:
  91. /// signal when properties change (during read from disk or configure process)
  92. void propertiesChanged(const QCMakeCachePropertyList& vars);
  93. /// signal when the generator changes
  94. void generatorChanged(const QString& gen);
  95. /// signal when the source directory changes (binary directory already
  96. /// containing a CMakeCache.txt file)
  97. void sourceDirChanged(const QString& dir);
  98. /// signal for progress events
  99. void progressChanged(const QString& msg, float percent);
  100. /// signal when configure is done
  101. void configureDone(int error);
  102. /// signal when generate is done
  103. void generateDone(int error);
  104. /// signal when there is an output message
  105. void outputMessage(const QString& msg);
  106. /// signal when there is an error message
  107. void errorMessage(const QString& msg);
  108. protected:
  109. cmake* CMakeInstance;
  110. static void progressCallback(const char* msg, float percent, void* cd);
  111. static void errorCallback(const char* msg, const char* title,
  112. bool&, void* cd);
  113. QString SourceDirectory;
  114. QString BinaryDirectory;
  115. QString Generator;
  116. QStringList AvailableGenerators;
  117. QString CMakeExecutable;
  118. };
  119. #endif // __QCMake_h