cmState.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. bool IsValid() const;
  32. Snapshot GetParent() const;
  33. private:
  34. friend class cmState;
  35. cmState* State;
  36. cmState::PositionType Position;
  37. };
  38. Snapshot CreateSnapshot(Snapshot originSnapshot);
  39. enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
  40. UNINITIALIZED };
  41. static CacheEntryType StringToCacheEntryType(const char*);
  42. static const char* CacheEntryTypeToString(CacheEntryType);
  43. static bool IsCacheEntryType(std::string const& key);
  44. std::vector<std::string> GetCacheEntryKeys() const;
  45. const char* GetCacheEntryValue(std::string const& key) const;
  46. const char* GetInitializedCacheValue(std::string const& key) const;
  47. CacheEntryType GetCacheEntryType(std::string const& key) const;
  48. void SetCacheEntryValue(std::string const& key, std::string const& value);
  49. void SetCacheValue(std::string const& key, std::string const& value);
  50. void AddCacheEntry(const std::string& key, const char* value,
  51. const char* helpString, CacheEntryType type);
  52. void RemoveCacheEntry(std::string const& key);
  53. void SetCacheEntryProperty(std::string const& key,
  54. std::string const& propertyName,
  55. std::string const& value);
  56. void SetCacheEntryBoolProperty(std::string const& key,
  57. std::string const& propertyName,
  58. bool value);
  59. const char* GetCacheEntryProperty(std::string const& key,
  60. std::string const& propertyName);
  61. bool GetCacheEntryPropertyAsBool(std::string const& key,
  62. std::string const& propertyName);
  63. void AppendCacheEntryProperty(std::string const& key,
  64. const std::string& property,
  65. const std::string& value,
  66. bool asString = false);
  67. void RemoveCacheEntryProperty(std::string const& key,
  68. std::string const& propertyName);
  69. void Initialize();
  70. // Define a property
  71. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  72. const char *ShortDescription,
  73. const char *FullDescription,
  74. bool chain = false);
  75. // get property definition
  76. cmPropertyDefinition *GetPropertyDefinition
  77. (const std::string& name, cmProperty::ScopeType scope);
  78. // Is a property defined?
  79. bool IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope);
  80. bool IsPropertyChained(const std::string& name, cmProperty::ScopeType scope);
  81. void SetLanguageEnabled(std::string const& l);
  82. bool GetLanguageEnabled(std::string const& l) const;
  83. std::vector<std::string> GetEnabledLanguages() const;
  84. void SetEnabledLanguages(std::vector<std::string> const& langs);
  85. void ClearEnabledLanguages();
  86. bool GetIsInTryCompile() const;
  87. void SetIsInTryCompile(bool b);
  88. cmCommand* GetCommand(std::string const& name) const;
  89. void AddCommand(cmCommand* command);
  90. void RemoveUnscriptableCommands();
  91. void RenameCommand(std::string const& oldName, std::string const& newName);
  92. void RemoveUserDefinedCommands();
  93. std::vector<std::string> GetCommandNames() const;
  94. void SetGlobalProperty(const std::string& prop, const char *value);
  95. void AppendGlobalProperty(const std::string& prop,
  96. const char *value,bool asString=false);
  97. const char *GetGlobalProperty(const std::string& prop);
  98. bool GetGlobalPropertyAsBool(const std::string& prop);
  99. const char* GetSourceDirectory() const;
  100. void SetSourceDirectory(std::string const& sourceDirectory);
  101. const char* GetBinaryDirectory() const;
  102. void SetBinaryDirectory(std::string const& binaryDirectory);
  103. private:
  104. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  105. std::vector<std::string> EnabledLanguages;
  106. std::map<std::string, cmCommand*> Commands;
  107. cmPropertyMap GlobalProperties;
  108. cmake* CMakeInstance;
  109. std::vector<std::string> Locations;
  110. std::vector<std::string> OutputLocations;
  111. std::vector<PositionType> ParentPositions;
  112. std::string SourceDirectory;
  113. std::string BinaryDirectory;
  114. bool IsInTryCompile;
  115. };
  116. #endif