@@ -866,8 +866,10 @@ bool ImportProject::importVcxproj(const std::string& filename, std::map<std::str
866866 for (const tinyxml2::XMLElement* e = node->FirstChildElement (); e; e = e->NextSiblingElement ()) {
867867 if (std::strcmp (e->Name (), " ClCompile" ) == 0 ) {
868868 const char * include = e->Attribute (" Include" );
869- if (include && Path::acceptFile (include))
870- compileList.emplace_back (include);
869+ if (include && Path::acceptFile (include)) {
870+ std::string toInclude = Path::simplifyPath (Path::isAbsolute (include) ? include : Path::getPathFromFilename (filename) + include);
871+ compileList.emplace_back (toInclude);
872+ }
871873 }
872874 }
873875 }
@@ -895,7 +897,14 @@ bool ImportProject::importVcxproj(const std::string& filename, std::map<std::str
895897 const char * projectAttribute = e->Attribute (" Project" );
896898 if (projectAttribute)
897899 {
898- std::string pathToSharedItemsFile (projectAttribute);
900+ // Path to shared items project is relative to current project directory,
901+ // unless the string starts with $(SolutionDir)
902+ std::string pathToSharedItemsFile;
903+ if (std::string (projectAttribute).rfind (" $(SolutionDir)" , 0 ) == 0 ) {
904+ pathToSharedItemsFile = std::string (projectAttribute);
905+ } else {
906+ pathToSharedItemsFile = variables[" ProjectDir" ] + std::string (projectAttribute);
907+ }
899908 if (!simplifyPathWithVariables (pathToSharedItemsFile, variables)) {
900909 printError (" Could not simplify path to referenced shared items project" );
901910 exit (-1 );
@@ -908,9 +917,21 @@ bool ImportProject::importVcxproj(const std::string& filename, std::map<std::str
908917 }
909918 }
910919
920+ // Include shared items project files
921+ std::vector<std::string> sharedItemsIncludePaths{};
922+ for (const auto & sharedProject : sharedItemsProjects) {
923+ for (const auto & file : sharedProject.sourceFiles ) {
924+ std::string pathToFile = Path::simplifyPath (Path::getPathFromFilename (sharedProject.pathToProjectFile ) + file);
925+ compileList.emplace_back (std::move (pathToFile));
926+ }
927+ for (const auto & p : sharedProject.includePaths ) {
928+ std::string path = Path::simplifyPath (Path::getPathFromFilename (sharedProject.pathToProjectFile ) + p);
929+ sharedItemsIncludePaths.emplace_back (std::move (path));
930+ }
931+ }
932+
911933 // Project files
912- for (const std::string& c : compileList) {
913- const std::string cfilename = Path::simplifyPath (Path::isAbsolute (c) ? c : Path::getPathFromFilename (filename) + c);
934+ for (const std::string& cfilename : compileList) {
914935 if (!fileFilters.empty () && !matchglobs (fileFilters, cfilename))
915936 continue ;
916937
@@ -956,63 +977,10 @@ bool ImportProject::importVcxproj(const std::string& filename, std::map<std::str
956977 }
957978 fs.setDefines (fs.defines );
958979 fs.setIncludePaths (Path::getPathFromFilename (filename), toStringList (includePath + ' ;' + additionalIncludePaths), variables);
959- fileSettings.push_back (std::move (fs));
960- }
961- }
962-
963- // Shared items files
964- for (const auto & sharedProject : sharedItemsProjects) {
965- for (const auto & c : sharedProject.sourceFiles ) {
966- const std::string cfilename = Path::simplifyPath (c);
967- if (!fileFilters.empty () && !matchglobs (fileFilters, cfilename))
968- continue ;
969-
970- for (const ProjectConfiguration& p : projectConfigurationList) {
971- if (!guiProject.checkVsConfigs .empty ()) {
972- const bool doChecking = std::any_of (guiProject.checkVsConfigs .cbegin (), guiProject.checkVsConfigs .cend (), [&](const std::string& c) {
973- return c == p.configuration ;
974- });
975- if (!doChecking)
976- continue ;
977- }
978-
979- FileSettings fs;
980- fs.filename = cfilename;
981- fs.cfg = p.name ;
982- fs.msc = true ;
983- fs.useMfc = useOfMfc;
984- fs.defines = " _WIN32=1" ;
985- if (p.platform == ProjectConfiguration::Win32)
986- fs.platformType = cppcheck::Platform::Type::Win32W;
987- else if (p.platform == ProjectConfiguration::x64) {
988- fs.platformType = cppcheck::Platform::Type::Win64;
989- fs.defines += " ;_WIN64=1" ;
990- }
991- std::string additionalIncludePaths;
992- for (const ItemDefinitionGroup& i : itemDefinitionGroupList) {
993- if (!i.conditionIsTrue (p))
994- continue ;
995- fs.standard = Standards::getCPP (i.cppstd );
996- fs.defines += ' ;' + i.preprocessorDefinitions ;
997- if (i.enhancedInstructionSet == " StreamingSIMDExtensions" )
998- fs.defines += " ;__SSE__" ;
999- else if (i.enhancedInstructionSet == " StreamingSIMDExtensions2" )
1000- fs.defines += " ;__SSE2__" ;
1001- else if (i.enhancedInstructionSet == " AdvancedVectorExtensions" )
1002- fs.defines += " ;__AVX__" ;
1003- else if (i.enhancedInstructionSet == " AdvancedVectorExtensions2" )
1004- fs.defines += " ;__AVX2__" ;
1005- else if (i.enhancedInstructionSet == " AdvancedVectorExtensions512" )
1006- fs.defines += " ;__AVX512__" ;
1007- additionalIncludePaths += ' ;' + i.additionalIncludePaths ;
1008- }
1009- fs.setDefines (fs.defines );
1010- fs.setIncludePaths (Path::getPathFromFilename (filename), toStringList (includePath + ' ;' + additionalIncludePaths), variables);
1011- for (const auto & toAddIncludePath : sharedProject.includePaths ) {
1012- fs.includePaths .emplace_back (Path::simplifyPath (toAddIncludePath));
1013- }
1014- fileSettings.push_back (std::move (fs));
980+ for (const auto & path : sharedItemsIncludePaths) {
981+ fs.includePaths .emplace_back (path);
1015982 }
983+ fileSettings.push_back (std::move (fs));
1016984 }
1017985 }
1018986
@@ -1040,12 +1008,6 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10401008 }
10411009 }
10421010
1043- std::string projectDir = Path::simplifyPath (Path::getPathFromFilename (filename));
1044- if (projectDir.empty ())
1045- {
1046- projectDir = std::string (" ./" );
1047- }
1048-
10491011 SharedItemsProject result{};
10501012 result.pathToProjectFile = filename;
10511013
@@ -1062,18 +1024,17 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10621024 }
10631025 for (const tinyxml2::XMLElement* node = rootnode->FirstChildElement (); node; node = node->NextSiblingElement ()) {
10641026 if (std::strcmp (node->Name (), " ItemGroup" ) == 0 ) {
1065- const char * labelAttribute = node->Attribute (" Label" );
10661027 for (const tinyxml2::XMLElement* e = node->FirstChildElement (); e; e = e->NextSiblingElement ()) {
10671028 if (std::strcmp (e->Name (), " ClCompile" ) == 0 ) {
10681029 const char * include = e->Attribute (" Include" );
10691030 if (include && Path::acceptFile (include)) {
1070- std::string filename = stringReplace (include, " $(MSBuildThisFileDirectory)" , projectDir );
1031+ std::string file = stringReplace (include, " $(MSBuildThisFileDirectory)" , " ./ " );
10711032
10721033 // Don't include file if it matches the filter
1073- if (!fileFilters.empty () && !matchglobs (fileFilters, filename ))
1034+ if (!fileFilters.empty () && !matchglobs (fileFilters, file ))
10741035 continue ;
10751036
1076- result.sourceFiles .emplace_back (filename );
1037+ result.sourceFiles .emplace_back (file );
10771038 } else {
10781039 printError (" Could not find shared items source file" );
10791040 exit (-1 );
@@ -1087,7 +1048,7 @@ ImportProject::SharedItemsProject ImportProject::importVcxitems(const std::strin
10871048 if (includePath == std::string (" %(AdditionalIncludeDirectories)" ))
10881049 continue ;
10891050
1090- result.includePaths .emplace_back (stringReplace (includePath, " $(MSBuildThisFileDirectory)" , projectDir ));
1051+ result.includePaths .emplace_back (stringReplace (includePath, " $(MSBuildThisFileDirectory)" , " ./ " ));
10911052 }
10921053 }
10931054 }
0 commit comments