cmState.h 11 KB

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