2323#include " token.h"
2424#include " tinyxml2.h"
2525#include < fstream>
26- #include < map>
2726// #include <iostream>
2827
2928void ImportProject::ignorePaths (std::vector<std::string> &ipaths)
@@ -92,7 +91,7 @@ void ImportProject::FileSettings::setDefines(std::string defs)
9291 defines.swap (defs);
9392}
9493
95- void ImportProject::FileSettings::setIncludePaths (const std::string &basepath, const std::list<std::string> &in)
94+ void ImportProject::FileSettings::setIncludePaths (const std::string &basepath, const std::list<std::string> &in, const std::map<std::string, std::string> &variables )
9695{
9796 std::list<std::string> I;
9897 for (std::list<std::string>::const_iterator it = in.begin (); it != in.end (); ++it) {
@@ -107,9 +106,22 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
107106 I.push_back (s);
108107 continue ;
109108 }
109+
110110 if (s[s.size ()-1U ] == ' /' ) // this is a temporary hack, simplifyPath can crash if path ends with '/'
111111 s.erase (s.size () - 1U );
112- s = Path::simplifyPath (basepath + s);
112+
113+ if (s.compare (0 ,2 ," $(" )==0 ) {
114+ std::string::size_type end = s.find (" )" );
115+ if (end == std::string::npos)
116+ continue ;
117+ const std::string &var = s.substr (2 ,end-2 );
118+ std::map<std::string, std::string>::const_iterator it1 = variables.find (var);
119+ if (it1 == variables.end ())
120+ continue ;
121+ s = Path::simplifyPath (it1->second + s.substr (end+1 ));
122+ } else {
123+ s = Path::simplifyPath (basepath + s);
124+ }
113125 if (s.empty ())
114126 continue ;
115127 I.push_back (s + ' /' );
@@ -130,7 +142,8 @@ void ImportProject::import(const std::string &filename)
130142 path += ' /' ;
131143 importSln (fin,path);
132144 } else if (filename.find (" .vcxproj" ) != std::string::npos) {
133- importVcxproj (filename);
145+ std::map<std::string, std::string> variables;
146+ importVcxproj (filename, variables);
134147 }
135148}
136149
@@ -180,7 +193,8 @@ void ImportProject::importCompileCommands(std::istream &istr)
180193 else if (F==' I' )
181194 fs.includePaths .push_back (fval);
182195 }
183- fs.setIncludePaths (directory, fs.includePaths );
196+ std::map<std::string, std::string> variables;
197+ fs.setIncludePaths (directory, fs.includePaths , variables);
184198 fs.setDefines (fs.defines );
185199 fileSettings.push_back (fs);
186200 }
@@ -191,6 +205,8 @@ void ImportProject::importCompileCommands(std::istream &istr)
191205
192206void ImportProject::importSln (std::istream &istr, const std::string &path)
193207{
208+ std::map<std::string,std::string> variables;
209+ variables[" SolutionDir" ] = path;
194210 std::string line;
195211 while (std::getline (istr,line)) {
196212 if (line.compare (0 ,8 ," Project(" )!=0 )
@@ -203,7 +219,7 @@ void ImportProject::importSln(std::istream &istr, const std::string &path)
203219 continue ;
204220 const std::string vcxproj (line.substr (pos1+1 , pos-pos1+7 ));
205221 // std::cout << "Importing " << vcxproj << "..." << std::endl;
206- importVcxproj (path + Path::fromNativeSeparators (vcxproj));
222+ importVcxproj (path + Path::fromNativeSeparators (vcxproj), variables );
207223 }
208224}
209225
@@ -296,8 +312,10 @@ static std::list<std::string> toStringList(const std::string &s)
296312 return ret;
297313}
298314
299- void ImportProject::importVcxproj (const std::string &filename)
315+ void ImportProject::importVcxproj (const std::string &filename, std::map<std::string, std::string> variables )
300316{
317+ variables[" ProjectDir" ] = Path::getPathFromFilename (filename);
318+
301319 std::list<ProjectConfiguration> projectConfigurationList;
302320 std::list<std::string> compileList;
303321 std::list<ItemDefinitionGroup> itemDefinitionGroupList;
@@ -352,7 +370,7 @@ void ImportProject::importVcxproj(const std::string &filename)
352370 if (useOfMfc)
353371 fs.defines += " ;__AFXWIN_H__" ;
354372 fs.setDefines (fs.defines );
355- fs.setIncludePaths (Path::getPathFromFilename (filename), toStringList (i->additionalIncludePaths ));
373+ fs.setIncludePaths (Path::getPathFromFilename (filename), toStringList (i->additionalIncludePaths ), variables );
356374 fileSettings.push_back (fs);
357375 }
358376 }
0 commit comments