diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index f2945cc10..c311f21dc 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -569,6 +569,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings->checkAllConfigurations = false; // Can be overridden with --max-configs or --force const std::string projectFile = argv[i]+10; ImportProject::Type projType = mSettings->project.import(projectFile, mSettings); + mSettings->project.projectType = projType; if (projType == ImportProject::Type::CPPCHECK_GUI) { mPathNames = mSettings->project.guiProject.pathNames; for (const std::string &lib : mSettings->project.guiProject.libraries) @@ -623,6 +624,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } } + // --project-configuration + else if (std::strncmp(argv[i], "--project-configuration=", 24) == 0) { + mVSConfig = argv[i] + 24; + if (!mVSConfig.empty() && (mSettings->project.projectType == ImportProject::Type::VS_SLN || mSettings->project.projectType == ImportProject::Type::VS_VCXPROJ)) + mSettings->project.ignoreOtherConfigs(mVSConfig); + } + // Report progress else if (std::strcmp(argv[i], "--report-progress") == 0) { mSettings->reportProgress = true; @@ -1106,6 +1114,11 @@ void CmdLineParser::printHelp() " or Borland C++ Builder 6 (*.bpr). The files to analyse,\n" " include paths, defines, platform and undefines in\n" " the specified file will be used.\n" + " --project-configuration=\n" + " If used together with a Visual Studio Solution (*.sln)\n" + " or Visual Studio Project (*.vcxproj) you can limit\n" + " the configuration cppcheck should check.\n" + " For example: ""--project-configuration=Release|Win32""" " --max-configs=\n" " Maximum number of configurations to check in a file\n" " before skipping it. Default is '12'. If used together\n" diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index dc977f418..4b7f1f321 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -114,6 +114,7 @@ private: bool mShowVersion; bool mShowErrorMessages; bool mExitAfterPrint; + std::string mVSConfig; }; /// @} diff --git a/lib/importproject.cpp b/lib/importproject.cpp index b99f71d48..b2980f232 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -34,6 +34,11 @@ #include +ImportProject::ImportProject() +{ + projectType = Type::UNKNOWN; +} + void ImportProject::ignorePaths(const std::vector &ipaths) { for (std::list::iterator it = fileSettings.begin(); it != fileSettings.end();) { diff --git a/lib/importproject.h b/lib/importproject.h index 948f57cb1..aeb67c654 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -81,6 +81,9 @@ public: void setIncludePaths(const std::string &basepath, const std::list &in, std::map &variables); }; std::list fileSettings; + Type projectType; + + ImportProject(); void selectOneVsConfig(cppcheck::Platform::PlatformType platform); diff --git a/man/manual.md b/man/manual.md index c14d62a2c..1d279dd81 100644 --- a/man/manual.md +++ b/man/manual.md @@ -179,6 +179,11 @@ Running Cppcheck on a Visual Studio project: cppcheck --project=foobar.vcxproj +Both options will analyze all available configurations in the project(s). +Limiting on a single configuration: + + cppcheck --project=foobar.sln "--project-configuration=Release|Win32" + In the `Cppcheck GUI` you have the choice to only analyze a single debug configuration. If you want to use this choice on the command line then create a `Cppcheck GUI` project with this activated and then import the GUI project file on the command line. To ignore certain folders in the project you can use `-i`. This will skip analysis of source files in the `foo` folder.