cmState.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 GetParent() 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 CreateSnapshot(Snapshot originSnapshot);
  48. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
  49. UNINITIALIZED };
  50. static CacheEntryType StringToCacheEntryType(const char*);
  51. static const char* CacheEntryTypeToString(CacheEntryType);
  52. static bool IsCacheEntryType(std::string const& key);
  53. std::vector<std::string> GetCacheEntryKeys() const;
  54. const char* GetCacheEntryValue(std::string const& key) const;
  55. const char* GetInitializedCacheValue(std::string const& key) const;
  56. CacheEntryType GetCacheEntryType(std::string const& key) const;
  57. void SetCacheEntryValue(std::string const& key, std::string const& value);
  58. void SetCacheValue(std::string const& key, std::string const& value);
  59. void AddCacheEntry(const std::string& key, const char* value,
  60. const char* helpString, CacheEntryType type);
  61. void RemoveCacheEntry(std::string const& key);
  62. void SetCacheEntryProperty(std::string const& key,
  63. std::string const& propertyName,
  64. std::string const& value);
  65. void SetCacheEntryBoolProperty(std::string const& key,
  66. std::string const& propertyName,
  67. bool value);
  68. const char* GetCacheEntryProperty(std::string const& key,
  69. std::string const& propertyName);
  70. bool GetCacheEntryPropertyAsBool(std::string const& key,
  71. std::string const& propertyName);
  72. void AppendCacheEntryProperty(std::string const& key,
  73. const std::string& property,
  74. const std::string& value,
  75. bool asString = false);
  76. void RemoveCacheEntryProperty(std::string const& key,
  77. std::string const& propertyName);
  78. void Reset();
  79. // Define a property
  80. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  81. const char *ShortDescription,
  82. const char *FullDescription,
  83. bool chain = false);
  84. // get property definition
  85. cmPropertyDefinition *GetPropertyDefinition
  86. (const std::string& name, cmProperty::ScopeType scope);
  87. // Is a property defined?
  88. bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope);
  89. bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope);
  90. void SetLanguageEnabled(std::string const& l);
  91. bool GetLanguageEnabled(std::string const& l) const;
  92. std::vector<std::string> GetEnabledLanguages() const;
  93. void SetEnabledLanguages(std::vector<std::string> const& langs);
  94. void ClearEnabledLanguages();
  95. bool GetIsInTryCompile() const;
  96. void SetIsInTryCompile(bool b);
  97. cmCommand* GetCommand(std::string const& name) const;
  98. void AddCommand(cmCommand* command);
  99. void RemoveUnscriptableCommands();
  100. void RenameCommand(std::string const& oldName, std::string const& newName);
  101. void RemoveUserDefinedCommands();
  102. std::vector<std::string> GetCommandNames() const;
  103. void SetGlobalProperty(const std::string& prop, const char *value);
  104. void AppendGlobalProperty(const std::string& prop,
  105. const char *value,bool asString=false);
  106. const char *GetGlobalProperty(const std::string& prop);
  107. bool GetGlobalPropertyAsBool(const std::string& prop);
  108. const char* GetSourceDirectory() const;
  109. void SetSourceDirectory(std::string const& sourceDirectory);
  110. const char* GetBinaryDirectory() const;
  111. void SetBinaryDirectory(std::string const& binaryDirectory);
  112. std::vector<std::string> const& GetSourceDirectoryComponents() const;
  113. std::vector<std::string> const& GetBinaryDirectoryComponents() const;
  114. private:
  115. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  116. std::vector<std::string> EnabledLanguages;
  117. std::map<std::string, cmCommand*> Commands;
  118. cmPropertyMap GlobalProperties;
  119. cmake* CMakeInstance;
  120. std::vector<std::string> Locations;
  121. std::vector<std::string> OutputLocations;
  122. std::vector<PositionType> ParentPositions;
  123. std::vector<std::vector<std::string> > CurrentSourceDirectoryComponents;
  124. std::vector<std::vector<std::string> > CurrentBinaryDirectoryComponents;
  125. // The top-most directories for relative path conversion. Both the
  126. // source and destination location of a relative path conversion
  127. // must be underneath one of these directories (both under source or
  128. // both under binary) in order for the relative path to be evaluated
  129. // safely by the build tools.
  130. std::vector<std::string> RelativePathTopSource;
  131. std::vector<std::string> RelativePathTopBinary;
  132. std::vector<std::string> SourceDirectoryComponents;
  133. std::vector<std::string> BinaryDirectoryComponents;
  134. std::string SourceDirectory;
  135. std::string BinaryDirectory;
  136. bool IsInTryCompile;
  137. };
  138. #endif