cmIDEOptions.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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(const char* 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(const char* 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. typedef std::vector<std::string> derived;
  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_space(std::string const& r)
  60. {
  61. this->resize(1);
  62. std::string& l = this->operator[](0);
  63. if (!l.empty()) {
  64. l += " ";
  65. }
  66. l += r;
  67. return *this;
  68. }
  69. };
  70. std::map<std::string, FlagValue> FlagMap;
  71. // Preprocessor definitions.
  72. std::vector<std::string> Defines;
  73. // Include directories.
  74. std::vector<std::string> Includes;
  75. bool DoingDefine;
  76. bool AllowDefine;
  77. bool DoingInclude;
  78. bool AllowInclude;
  79. bool AllowSlash;
  80. cmIDEFlagTable const* DoingFollowing;
  81. enum
  82. {
  83. FlagTableCount = 16
  84. };
  85. cmIDEFlagTable const* FlagTable[FlagTableCount];
  86. void HandleFlag(const char* flag);
  87. bool CheckFlagTable(cmIDEFlagTable const* table, const char* flag,
  88. bool& flag_handled);
  89. void FlagMapUpdate(cmIDEFlagTable const* entry, const char* new_value);
  90. virtual void StoreUnknownFlag(const char* flag) = 0;
  91. };
  92. #endif