@@ -108,6 +108,64 @@ std::string ImportProject::collectArgs(const std::string &cmd, std::vector<std::
108108 return " " ;
109109}
110110
111+ void ImportProject::parseArgs (FileSettings &fs, const std::vector<std::string> &args)
112+ {
113+ std::string defs;
114+ std::string optArg;
115+ auto argPtr = args.cbegin ();
116+
117+ // Check for an option and extract its argument
118+ const auto getOptArg = [&](const std::string &name) {
119+ if (argPtr == args.cend ())
120+ return false ;
121+ if (!startsWith (*argPtr, name))
122+ return false ;
123+ if (argPtr->size () == name.size ()) {
124+ // Flag and argument are separated
125+ argPtr++;
126+ if (argPtr == args.cend ())
127+ return false ;
128+ optArg = *argPtr;
129+ } else {
130+ // Flag and argument are concatenated
131+ optArg = argPtr->substr (name.size ());
132+ }
133+ return true ;
134+ };
135+
136+ for (; argPtr != args.cend (); argPtr++) {
137+ if (getOptArg (" -I" ) || getOptArg (" /I" )) {
138+ if (std::find (fs.includePaths .cbegin (), fs.includePaths .cend (), optArg) == fs.includePaths .cend ())
139+ fs.includePaths .push_back (std::move (optArg));
140+ } else if (getOptArg (" -isystem" )) {
141+ fs.systemIncludePaths .push_back (std::move (optArg));
142+ } else if (getOptArg (" -D" ) || getOptArg (" /D" )) {
143+ defs += optArg + " ;" ;
144+ } else if (getOptArg (" -U" ) || getOptArg (" /U" )) {
145+ fs.undefs .insert (std::move (optArg));
146+ } else if (getOptArg (" -std=" ) || getOptArg (" /std:" )) {
147+ fs.standard = std::move (optArg);
148+ } else if (getOptArg (" -f" )) {
149+ if (optArg == " pic" )
150+ defs += " __pic__;" ;
151+ else if (optArg == " PIC" )
152+ defs += " __PIC__;" ;
153+ else if (optArg == " pie" )
154+ defs += " __pie__;" ;
155+ else if (optArg == " PIE" )
156+ defs += " __PIE__;" ;
157+ } else if (getOptArg (" -m" )) {
158+ if (optArg == " unicode" )
159+ defs += " UNICODE;" ;
160+ }
161+
162+ if (argPtr == args.cend ())
163+ break ;
164+ }
165+
166+ fsSetDefines (fs, std::move (defs));
167+ }
168+
111169void ImportProject::ignorePaths (const std::vector<std::string> &ipaths, bool debug)
112170{
113171 PathMatch matcher (ipaths, Path::getCurrentPath ());
0 commit comments