cmState.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2015 Stephen Kelly <[email protected]>
  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 cmState_h
  11. #define cmState_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmPropertyDefinitionMap.h"
  14. #include "cmPropertyMap.h"
  15. #include "cmLinkedTree.h"
  16. class cmake;
  17. class cmCommand;
  18. class cmState
  19. {
  20. struct SnapshotDataType;
  21. typedef cmLinkedTree<SnapshotDataType>::iterator PositionType;
  22. friend class Snapshot;
  23. public:
  24. cmState(cmake* cm);
  25. ~cmState();
  26. enum SnapshotType
  27. {
  28. BuildsystemDirectoryType,
  29. FunctionCallType,
  30. MacroCallType,
  31. CallStackType,
  32. InlineListFileType
  33. };
  34. class Snapshot {
  35. public:
  36. Snapshot(cmState* state = 0, PositionType position = PositionType());
  37. const char* GetCurrentSourceDirectory() const;
  38. void SetCurrentSourceDirectory(std::string const& dir);
  39. const char* GetCurrentBinaryDirectory() const;
  40. void SetCurrentBinaryDirectory(std::string const& dir);
  41. std::vector<std::string> const&
  42. GetCurrentSourceDirectoryComponents() const;
  43. std::vector<std::string> const&
  44. GetCurrentBinaryDirectoryComponents() const;
  45. const char* GetRelativePathTopSource() const;
  46. const char* GetRelativePathTopBinary() const;
  47. void SetRelativePathTopSource(const char* dir);
  48. void SetRelativePathTopBinary(const char* dir);
  49. bool IsValid() const;
  50. Snapshot GetBuildsystemDirectoryParent() const;
  51. Snapshot GetCallStackParent() const;
  52. cmState* GetState() const;
  53. private:
  54. void ComputeRelativePathTopSource();
  55. void ComputeRelativePathTopBinary();
  56. private:
  57. friend class cmState;
  58. cmState* State;
  59. cmState::PositionType Position;
  60. };
  61. Snapshot CreateBaseSnapshot();
  62. Snapshot
  63. CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot);
  64. Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot);
  65. Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot);
  66. Snapshot CreateCallStackSnapshot(Snapshot originSnapshot);
  67. Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot);
  68. Snapshot Pop(Snapshot originSnapshot);
  69. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
  70. UNINITIALIZED };
  71. static CacheEntryType StringToCacheEntryType(const char*);
  72. static const char* CacheEntryTypeToString(CacheEntryType);
  73. static bool IsCacheEntryType(std::string const& key);
  74. std::vector<std::string> GetCacheEntryKeys() const;
  75. const char* GetCacheEntryValue(std::string const& key) const;
  76. const char* GetInitializedCacheValue(std::string const& key) const;
  77. CacheEntryType GetCacheEntryType(std::string const& key) const;
  78. void SetCacheEntryValue(std::string const& key, std::string const& value);
  79. void SetCacheValue(std::string const& key, std::string const& value);
  80. void AddCacheEntry(const std::string& key, const char* value,
  81. const char* helpString, CacheEntryType type);
  82. void RemoveCacheEntry(std::string const& key);
  83. void SetCacheEntryProperty(std::string const& key,
  84. std::string const& propertyName,
  85. std::string const& value);
  86. void SetCacheEntryBoolProperty(std::string const& key,
  87. std::string const& propertyName,
  88. bool value);
  89. const char* GetCacheEntryProperty(std::string const& key,
  90. std::string const& propertyName);
  91. bool GetCacheEntryPropertyAsBool(std::string const& key,
  92. std::string const& propertyName);
  93. void AppendCacheEntryProperty(std::string const& key,
  94. const std::string& property,
  95. const std::string& value,
  96. bool asString = false);
  97. void RemoveCacheEntryProperty(std::string const& key,
  98. std::string const& propertyName);
  99. Snapshot Reset();
  100. // Define a property
  101. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  102. const char *ShortDescription,
  103. const char *FullDescription,
  104. bool chain = false);
  105. // get property definition
  106. cmPropertyDefinition const* GetPropertyDefinition
  107. (const std::string& name, cmProperty::ScopeType scope) const;
  108. // Is a property defined?
  109. bool IsPropertyDefined(const std::string& name,
  110. cmProperty::ScopeType scope) const;
  111. bool IsPropertyChained(const std::string& name,
  112. cmProperty::ScopeType scope) const;
  113. void SetLanguageEnabled(std::string const& l);
  114. bool GetLanguageEnabled(std::string const& l) const;
  115. std::vector<std::string> GetEnabledLanguages() const;
  116. void SetEnabledLanguages(std::vector<std::string> const& langs);
  117. void ClearEnabledLanguages();
  118. bool GetIsInTryCompile() const;
  119. void SetIsInTryCompile(bool b);
  120. cmCommand* GetCommand(std::string const& name) const;
  121. void AddCommand(cmCommand* command);
  122. void RemoveUnscriptableCommands();
  123. void RenameCommand(std::string const& oldName, std::string const& newName);
  124. void RemoveUserDefinedCommands();
  125. std::vector<std::string> GetCommandNames() const;
  126. void SetGlobalProperty(const std::string& prop, const char *value);
  127. void AppendGlobalProperty(const std::string& prop,
  128. const char *value,bool asString=false);
  129. const char *GetGlobalProperty(const std::string& prop);
  130. bool GetGlobalPropertyAsBool(const std::string& prop);
  131. const char* GetSourceDirectory() const;
  132. void SetSourceDirectory(std::string const& sourceDirectory);
  133. const char* GetBinaryDirectory() const;
  134. void SetBinaryDirectory(std::string const& binaryDirectory);
  135. std::vector<std::string> const& GetSourceDirectoryComponents() const;
  136. std::vector<std::string> const& GetBinaryDirectoryComponents() const;
  137. void SetWindowsShell(bool windowsShell);
  138. bool UseWindowsShell() const;
  139. void SetWindowsVSIDE(bool windowsVSIDE);
  140. bool UseWindowsVSIDE() const;
  141. void SetWatcomWMake(bool watcomWMake);
  142. bool UseWatcomWMake() const;
  143. void SetMinGWMake(bool minGWMake);
  144. bool UseMinGWMake() const;
  145. void SetNMake(bool nMake);
  146. bool UseNMake() const;
  147. void SetMSYSShell(bool mSYSShell);
  148. bool UseMSYSShell() const;
  149. private:
  150. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  151. std::vector<std::string> EnabledLanguages;
  152. std::map<std::string, cmCommand*> Commands;
  153. cmPropertyMap GlobalProperties;
  154. cmake* CMakeInstance;
  155. struct BuildsystemDirectoryStateType;
  156. cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
  157. cmLinkedTree<SnapshotDataType> SnapshotData;
  158. std::vector<std::string> SourceDirectoryComponents;
  159. std::vector<std::string> BinaryDirectoryComponents;
  160. std::string SourceDirectory;
  161. std::string BinaryDirectory;
  162. bool IsInTryCompile;
  163. bool WindowsShell;
  164. bool WindowsVSIDE;
  165. bool WatcomWMake;
  166. bool MinGWMake;
  167. bool NMake;
  168. bool MSYSShell;
  169. };
  170. #endif