cmIDEOptions.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmIDEOptions_h
  4. #define cmIDEOptions_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. struct cmIDEFlagTable;
  10. /** \class cmIDEOptions
  11. * \brief Superclass for IDE option processing
  12. */
  13. class cmIDEOptions
  14. {
  15. public:
  16. cmIDEOptions();
  17. virtual ~cmIDEOptions();
  18. // Store definitions, includes and flags.
  19. void AddDefine(const std::string& define);
  20. void AddDefines(std::string const& defines);
  21. void AddDefines(const std::vector<std::string>& defines);
  22. std::vector<std::string> const& GetDefines() const;
  23. void AddInclude(const std::string& includes);
  24. void AddIncludes(std::string const& includes);
  25. void AddIncludes(const std::vector<std::string>& includes);
  26. std::vector<std::string> const& GetIncludes() const;
  27. void AddFlag(std::string const& flag, std::string const& value);
  28. void AddFlag(std::string const& flag, std::vector<std::string> const& value);
  29. void AppendFlag(std::string const& flag, std::string const& value);
  30. void AppendFlag(std::string const& flag,
  31. std::vector<std::string> const& value);
  32. void AppendFlagString(std::string const& flag, std::string const& value);
  33. void RemoveFlag(std::string const& flag);
  34. bool HasFlag(std::string const& flag) const;
  35. const char* GetFlag(std::string const& flag) const;
  36. protected:
  37. // create a map of xml tags to the values they should have in the output
  38. // for example, "BufferSecurityCheck" = "TRUE"
  39. // first fill this table with the values for the configuration
  40. // Debug, Release, etc,
  41. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  42. // and CMAKE_C_FLAGS
  43. // and overwrite or add new values to this map
  44. class FlagValue : public std::vector<std::string>
  45. {
  46. using derived = std::vector<std::string>;
  47. public:
  48. FlagValue& operator=(std::string const& r)
  49. {
  50. this->resize(1);
  51. this->operator[](0) = r;
  52. return *this;
  53. }
  54. FlagValue& operator=(std::vector<std::string> const& r)
  55. {
  56. this->derived::operator=(r);
  57. return *this;
  58. }
  59. FlagValue& append_with_comma(std::string const& r)
  60. {
  61. return append_with_separator(r, ',');
  62. }
  63. FlagValue& append_with_space(std::string const& r)
  64. {
  65. return append_with_separator(r, ' ');
  66. }
  67. private:
  68. FlagValue& append_with_separator(std::string const& r, char separator)
  69. {
  70. this->resize(1);
  71. std::string& l = this->operator[](0);
  72. if (!l.empty()) {
  73. l += separator;
  74. }
  75. l += r;
  76. return *this;
  77. }
  78. };
  79. std::map<std::string, FlagValue> FlagMap;
  80. // Preprocessor definitions.
  81. std::vector<std::string> Defines;
  82. // Include directories.
  83. std::vector<std::string> Includes;
  84. bool DoingDefine;
  85. bool AllowDefine;
  86. bool DoingInclude;
  87. bool AllowInclude;
  88. bool AllowSlash;
  89. cmIDEFlagTable const* DoingFollowing;
  90. enum
  91. {
  92. FlagTableCount = 16
  93. };
  94. cmIDEFlagTable const* FlagTable[FlagTableCount];
  95. void HandleFlag(std::string const& flag);
  96. bool CheckFlagTable(cmIDEFlagTable const* table, std::string const& flag,
  97. bool& flag_handled);
  98. void FlagMapUpdate(cmIDEFlagTable const* entry,
  99. std::string const& new_value);
  100. virtual void StoreUnknownFlag(std::string const& flag) = 0;
  101. };
  102. #endif