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