cmState.h 7.1 KB

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