cmState.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. struct BuildsystemDirectoryStateType;
  22. typedef cmLinkedTree<SnapshotDataType>::iterator PositionType;
  23. friend class Snapshot;
  24. public:
  25. cmState(cmake* cm);
  26. ~cmState();
  27. enum SnapshotType
  28. {
  29. BuildsystemDirectoryType,
  30. FunctionCallType,
  31. MacroCallType,
  32. CallStackType,
  33. InlineListFileType
  34. };
  35. class Directory;
  36. class Snapshot {
  37. public:
  38. Snapshot(cmState* state = 0);
  39. Snapshot(cmState* state, PositionType position);
  40. void SetListFile(std::string const& listfile);
  41. std::string GetExecutionListFile() const;
  42. std::string GetEntryPointCommand() const;
  43. long GetEntryPointLine() const;
  44. bool IsValid() const;
  45. Snapshot GetBuildsystemDirectoryParent() const;
  46. Snapshot GetCallStackParent() const;
  47. cmState* GetState() const;
  48. Directory GetDirectory() const;
  49. private:
  50. friend class cmState;
  51. friend class Directory;
  52. cmState* State;
  53. cmState::PositionType Position;
  54. };
  55. class Directory
  56. {
  57. Directory(cmLinkedTree<BuildsystemDirectoryStateType>::iterator iter,
  58. Snapshot const& snapshot);
  59. public:
  60. const char* GetCurrentSource() const;
  61. void SetCurrentSource(std::string const& dir);
  62. const char* GetCurrentBinary() const;
  63. void SetCurrentBinary(std::string const& dir);
  64. std::vector<std::string> const&
  65. GetCurrentSourceComponents() const;
  66. std::vector<std::string> const&
  67. GetCurrentBinaryComponents() const;
  68. const char* GetRelativePathTopSource() const;
  69. const char* GetRelativePathTopBinary() const;
  70. void SetRelativePathTopSource(const char* dir);
  71. void SetRelativePathTopBinary(const char* dir);
  72. private:
  73. void ComputeRelativePathTopSource();
  74. void ComputeRelativePathTopBinary();
  75. private:
  76. cmLinkedTree<BuildsystemDirectoryStateType>::iterator DirectoryState;
  77. Snapshot Snapshot_;
  78. friend class Snapshot;
  79. };
  80. Snapshot CreateBaseSnapshot();
  81. Snapshot
  82. CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
  83. std::string const& entryPointCommand,
  84. long entryPointLine);
  85. Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot,
  86. std::string const& entryPointCommand,
  87. long entryPointLine,
  88. std::string const& fileName);
  89. Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot,
  90. std::string const& entryPointCommand,
  91. long entryPointLine,
  92. std::string const& fileName);
  93. Snapshot CreateCallStackSnapshot(Snapshot originSnapshot,
  94. std::string const& entryPointCommand,
  95. long entryPointLine,
  96. std::string const& fileName);
  97. Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot,
  98. const std::string& entryPointCommand,
  99. long entryPointLine,
  100. std::string const& fileName);
  101. Snapshot Pop(Snapshot originSnapshot);
  102. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
  103. UNINITIALIZED };
  104. static CacheEntryType StringToCacheEntryType(const char*);
  105. static const char* CacheEntryTypeToString(CacheEntryType);
  106. static bool IsCacheEntryType(std::string const& key);
  107. std::vector<std::string> GetCacheEntryKeys() const;
  108. const char* GetCacheEntryValue(std::string const& key) const;
  109. const char* GetInitializedCacheValue(std::string const& key) const;
  110. CacheEntryType GetCacheEntryType(std::string const& key) const;
  111. void SetCacheEntryValue(std::string const& key, std::string const& value);
  112. void SetCacheValue(std::string const& key, std::string const& value);
  113. void AddCacheEntry(const std::string& key, const char* value,
  114. const char* helpString, CacheEntryType type);
  115. void RemoveCacheEntry(std::string const& key);
  116. void SetCacheEntryProperty(std::string const& key,
  117. std::string const& propertyName,
  118. std::string const& value);
  119. void SetCacheEntryBoolProperty(std::string const& key,
  120. std::string const& propertyName,
  121. bool value);
  122. const char* GetCacheEntryProperty(std::string const& key,
  123. std::string const& propertyName);
  124. bool GetCacheEntryPropertyAsBool(std::string const& key,
  125. std::string const& propertyName);
  126. void AppendCacheEntryProperty(std::string const& key,
  127. const std::string& property,
  128. const std::string& value,
  129. bool asString = false);
  130. void RemoveCacheEntryProperty(std::string const& key,
  131. std::string const& propertyName);
  132. Snapshot Reset();
  133. // Define a property
  134. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  135. const char *ShortDescription,
  136. const char *FullDescription,
  137. bool chain = false);
  138. // get property definition
  139. cmPropertyDefinition const* GetPropertyDefinition
  140. (const std::string& name, cmProperty::ScopeType scope) const;
  141. // Is a property defined?
  142. bool IsPropertyDefined(const std::string& name,
  143. cmProperty::ScopeType scope) const;
  144. bool IsPropertyChained(const std::string& name,
  145. cmProperty::ScopeType scope) const;
  146. void SetLanguageEnabled(std::string const& l);
  147. bool GetLanguageEnabled(std::string const& l) const;
  148. std::vector<std::string> GetEnabledLanguages() const;
  149. void SetEnabledLanguages(std::vector<std::string> const& langs);
  150. void ClearEnabledLanguages();
  151. bool GetIsInTryCompile() const;
  152. void SetIsInTryCompile(bool b);
  153. cmCommand* GetCommand(std::string const& name) const;
  154. void AddCommand(cmCommand* command);
  155. void RemoveUnscriptableCommands();
  156. void RenameCommand(std::string const& oldName, std::string const& newName);
  157. void RemoveUserDefinedCommands();
  158. std::vector<std::string> GetCommandNames() const;
  159. void SetGlobalProperty(const std::string& prop, const char *value);
  160. void AppendGlobalProperty(const std::string& prop,
  161. const char *value,bool asString=false);
  162. const char *GetGlobalProperty(const std::string& prop);
  163. bool GetGlobalPropertyAsBool(const std::string& prop);
  164. const char* GetSourceDirectory() const;
  165. void SetSourceDirectory(std::string const& sourceDirectory);
  166. const char* GetBinaryDirectory() const;
  167. void SetBinaryDirectory(std::string const& binaryDirectory);
  168. std::vector<std::string> const& GetSourceDirectoryComponents() const;
  169. std::vector<std::string> const& GetBinaryDirectoryComponents() const;
  170. void SetWindowsShell(bool windowsShell);
  171. bool UseWindowsShell() const;
  172. void SetWindowsVSIDE(bool windowsVSIDE);
  173. bool UseWindowsVSIDE() const;
  174. void SetWatcomWMake(bool watcomWMake);
  175. bool UseWatcomWMake() const;
  176. void SetMinGWMake(bool minGWMake);
  177. bool UseMinGWMake() const;
  178. void SetNMake(bool nMake);
  179. bool UseNMake() const;
  180. void SetMSYSShell(bool mSYSShell);
  181. bool UseMSYSShell() const;
  182. private:
  183. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  184. std::vector<std::string> EnabledLanguages;
  185. std::map<std::string, cmCommand*> Commands;
  186. cmPropertyMap GlobalProperties;
  187. cmake* CMakeInstance;
  188. cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
  189. cmLinkedTree<std::string> ExecutionListFiles;
  190. cmLinkedTree<SnapshotDataType> SnapshotData;
  191. std::vector<std::string> SourceDirectoryComponents;
  192. std::vector<std::string> BinaryDirectoryComponents;
  193. std::string SourceDirectory;
  194. std::string BinaryDirectory;
  195. bool IsInTryCompile;
  196. bool WindowsShell;
  197. bool WindowsVSIDE;
  198. bool WatcomWMake;
  199. bool MinGWMake;
  200. bool NMake;
  201. bool MSYSShell;
  202. };
  203. #endif