From cc4c9032deae714df1ce24fa4ed14cec8d9b982c Mon Sep 17 00:00:00 2001 From: BNT Date: Sat, 11 Nov 2017 11:13:18 +0100 Subject: [PATCH] Support relative paths in Visual Studio projects properties (#995) * transform relative paths with the help of the project dir to absolute paths so the actual checker can resolve include paths defined in property sheets * fix coding style (one-line if) * add existing importproject testfile to visual studio project to appear when loading solution * also explicitly export struct from within class to enable linking in testrunner --- lib/importproject.cpp | 6 ++++++ lib/importproject.h | 2 +- test/testrunner.vcxproj | 1 + test/testrunner.vcxproj.filters | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 6a071790b..a980ad660 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -413,8 +413,14 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map *variables, std::string *includePath, const std::string &additionalIncludeDirectories, std::list &itemDefinitionGroupList) { std::string filename(props); + // variables cant be resolved if (!simplifyPathWithVariables(filename, *variables)) return; + + // prepend project dir (if it exists) to transform relative paths into absolute ones + if (!Path::isAbsolute(filename) && variables->count("ProjectDir") > 0) + filename = Path::getAbsoluteFilePath(variables->at("ProjectDir") + filename); + tinyxml2::XMLDocument doc; if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS) return; diff --git a/lib/importproject.h b/lib/importproject.h index 1933c87f8..7901a0790 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -48,7 +48,7 @@ namespace cppcheck { class CPPCHECKLIB ImportProject { public: /** File settings. Multiple configurations for a file is allowed. */ - struct FileSettings { + struct CPPCHECKLIB FileSettings { FileSettings() : platformType(cppcheck::Platform::Unspecified), msc(false), useMfc(false) {} std::string cfg; std::string filename; diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index 2b242006e..86032280d 100644 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -45,6 +45,7 @@ + diff --git a/test/testrunner.vcxproj.filters b/test/testrunner.vcxproj.filters index 1133e9811..7c74d5c08 100644 --- a/test/testrunner.vcxproj.filters +++ b/test/testrunner.vcxproj.filters @@ -199,6 +199,9 @@ Source Files + + Source Files +