cmState.h 11 KB

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