cmState.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. class cmake;
  16. class cmCommand;
  17. class cmState
  18. {
  19. struct SnapshotDataType;
  20. typedef std::vector<std::string>::size_type PositionType;
  21. friend class Snapshot;
  22. public:
  23. cmState(cmake* cm);
  24. ~cmState();
  25. enum SnapshotType
  26. {
  27. BuildsystemDirectoryType
  28. };
  29. class Snapshot {
  30. public:
  31. Snapshot(cmState* state = 0, PositionType position = 0);
  32. const char* GetCurrentSourceDirectory() const;
  33. void SetCurrentSourceDirectory(std::string const& dir);
  34. const char* GetCurrentBinaryDirectory() const;
  35. void SetCurrentBinaryDirectory(std::string const& dir);
  36. std::vector<std::string> const& GetCurrentSourceDirectoryComponents();
  37. std::vector<std::string> const& GetCurrentBinaryDirectoryComponents();
  38. const char* GetRelativePathTopSource() const;
  39. const char* GetRelativePathTopBinary() const;
  40. void SetRelativePathTopSource(const char* dir);
  41. void SetRelativePathTopBinary(const char* dir);
  42. bool IsValid() const;
  43. Snapshot GetBuildsystemDirectoryParent() const;
  44. private:
  45. void ComputeRelativePathTopSource();
  46. void ComputeRelativePathTopBinary();
  47. private:
  48. friend class cmState;
  49. cmState* State;
  50. cmState::PositionType Position;
  51. };
  52. Snapshot CreateBaseSnapshot();
  53. Snapshot CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot);
  54. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
  55. UNINITIALIZED };
  56. static CacheEntryType StringToCacheEntryType(const char*);
  57. static const char* CacheEntryTypeToString(CacheEntryType);
  58. static bool IsCacheEntryType(std::string const& key);
  59. std::vector<std::string> GetCacheEntryKeys() const;
  60. const char* GetCacheEntryValue(std::string const& key) const;
  61. const char* GetInitializedCacheValue(std::string const& key) const;
  62. CacheEntryType GetCacheEntryType(std::string const& key) const;
  63. void SetCacheEntryValue(std::string const& key, std::string const& value);
  64. void SetCacheValue(std::string const& key, std::string const& value);
  65. void AddCacheEntry(const std::string& key, const char* value,
  66. const char* helpString, CacheEntryType type);
  67. void RemoveCacheEntry(std::string const& key);
  68. void SetCacheEntryProperty(std::string const& key,
  69. std::string const& propertyName,
  70. std::string const& value);
  71. void SetCacheEntryBoolProperty(std::string const& key,
  72. std::string const& propertyName,
  73. bool value);
  74. const char* GetCacheEntryProperty(std::string const& key,
  75. std::string const& propertyName);
  76. bool GetCacheEntryPropertyAsBool(std::string const& key,
  77. std::string const& propertyName);
  78. void AppendCacheEntryProperty(std::string const& key,
  79. const std::string& property,
  80. const std::string& value,
  81. bool asString = false);
  82. void RemoveCacheEntryProperty(std::string const& key,
  83. std::string const& propertyName);
  84. void Reset();
  85. // Define a property
  86. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  87. const char *ShortDescription,
  88. const char *FullDescription,
  89. bool chain = false);
  90. // get property definition
  91. cmPropertyDefinition *GetPropertyDefinition
  92. (const std::string& name, cmProperty::ScopeType scope);
  93. // Is a property defined?
  94. bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope);
  95. bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope);
  96. void SetLanguageEnabled(std::string const& l);
  97. bool GetLanguageEnabled(std::string const& l) const;
  98. std::vector<std::string> GetEnabledLanguages() const;
  99. void SetEnabledLanguages(std::vector<std::string> const& langs);
  100. void ClearEnabledLanguages();
  101. bool GetIsInTryCompile() const;
  102. void SetIsInTryCompile(bool b);
  103. cmCommand* GetCommand(std::string const& name) const;
  104. void AddCommand(cmCommand* command);
  105. void RemoveUnscriptableCommands();
  106. void RenameCommand(std::string const& oldName, std::string const& newName);
  107. void RemoveUserDefinedCommands();
  108. std::vector<std::string> GetCommandNames() const;
  109. void SetGlobalProperty(const std::string& prop, const char *value);
  110. void AppendGlobalProperty(const std::string& prop,
  111. const char *value,bool asString=false);
  112. const char *GetGlobalProperty(const std::string& prop);
  113. bool GetGlobalPropertyAsBool(const std::string& prop);
  114. const char* GetSourceDirectory() const;
  115. void SetSourceDirectory(std::string const& sourceDirectory);
  116. const char* GetBinaryDirectory() const;
  117. void SetBinaryDirectory(std::string const& binaryDirectory);
  118. std::vector<std::string> const& GetSourceDirectoryComponents() const;
  119. std::vector<std::string> const& GetBinaryDirectoryComponents() const;
  120. void SetWindowsShell(bool windowsShell);
  121. bool UseWindowsShell() const;
  122. void SetWindowsVSIDE(bool windowsVSIDE);
  123. bool UseWindowsVSIDE() const;
  124. void SetWatcomWMake(bool watcomWMake);
  125. bool UseWatcomWMake() const;
  126. void SetMinGWMake(bool minGWMake);
  127. bool UseMinGWMake() const;
  128. void SetNMake(bool nMake);
  129. bool UseNMake() const;
  130. void SetMSYSShell(bool mSYSShell);
  131. bool UseMSYSShell() const;
  132. private:
  133. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  134. std::vector<std::string> EnabledLanguages;
  135. std::map<std::string, cmCommand*> Commands;
  136. cmPropertyMap GlobalProperties;
  137. cmake* CMakeInstance;
  138. std::vector<std::string> Locations;
  139. std::vector<std::string> OutputLocations;
  140. std::vector<SnapshotDataType> SnapshotData;
  141. std::vector<std::vector<std::string> > CurrentSourceDirectoryComponents;
  142. std::vector<std::vector<std::string> > CurrentBinaryDirectoryComponents;
  143. // The top-most directories for relative path conversion. Both the
  144. // source and destination location of a relative path conversion
  145. // must be underneath one of these directories (both under source or
  146. // both under binary) in order for the relative path to be evaluated
  147. // safely by the build tools.
  148. std::vector<std::string> RelativePathTopSource;
  149. std::vector<std::string> RelativePathTopBinary;
  150. std::vector<std::string> SourceDirectoryComponents;
  151. std::vector<std::string> BinaryDirectoryComponents;
  152. std::string SourceDirectory;
  153. std::string BinaryDirectory;
  154. bool IsInTryCompile;
  155. bool WindowsShell;
  156. bool WindowsVSIDE;
  157. bool WatcomWMake;
  158. bool MinGWMake;
  159. bool NMake;
  160. bool MSYSShell;
  161. };
  162. #endif