cmIDEOptions.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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>
  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 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 AddFlag(const char* flag, const char* value);
  24. void AddFlag(const char* flag, std::vector<std::string> const& value);
  25. void AppendFlag(std::string const& flag, std::string const& value);
  26. void AppendFlag(std::string const& flag,
  27. std::vector<std::string> const& value);
  28. void AppendFlagString(std::string const& flag, std::string const& value);
  29. void RemoveFlag(const char* flag);
  30. bool HasFlag(std::string const& flag) const;
  31. const char* GetFlag(const char* flag);
  32. protected:
  33. // create a map of xml tags to the values they should have in the output
  34. // for example, "BufferSecurityCheck" = "TRUE"
  35. // first fill this table with the values for the configuration
  36. // Debug, Release, etc,
  37. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  38. // and CMAKE_C_FLAGS
  39. // and overwrite or add new values to this map
  40. class FlagValue : public std::vector<std::string>
  41. {
  42. typedef std::vector<std::string> derived;
  43. public:
  44. FlagValue& operator=(std::string const& r)
  45. {
  46. this->resize(1);
  47. this->operator[](0) = r;
  48. return *this;
  49. }
  50. FlagValue& operator=(std::vector<std::string> const& r)
  51. {
  52. this->derived::operator=(r);
  53. return *this;
  54. }
  55. FlagValue& append_with_space(std::string const& r)
  56. {
  57. this->resize(1);
  58. std::string& l = this->operator[](0);
  59. if (!l.empty()) {
  60. l += " ";
  61. }
  62. l += r;
  63. return *this;
  64. }
  65. };
  66. std::map<std::string, FlagValue> FlagMap;
  67. // Preprocessor definitions.
  68. std::vector<std::string> Defines;
  69. bool DoingDefine;
  70. bool AllowDefine;
  71. bool AllowSlash;
  72. cmIDEFlagTable const* DoingFollowing;
  73. enum
  74. {
  75. FlagTableCount = 16
  76. };
  77. cmIDEFlagTable const* FlagTable[FlagTableCount];
  78. void HandleFlag(const char* flag);
  79. bool CheckFlagTable(cmIDEFlagTable const* table, const char* flag,
  80. bool& flag_handled);
  81. void FlagMapUpdate(cmIDEFlagTable const* entry, const char* new_value);
  82. virtual void StoreUnknownFlag(const char* flag) = 0;
  83. };
  84. #endif