Skip to content

Commit 095fd2b

Browse files
authored
add command line option to select single project configuration of loaded solution (#2523)
* add command line option to select single project configuration of loaded solution * Update cmdlineparser.cpp * Update manual.md * fix initialization
1 parent f9074e7 commit 095fd2b

5 files changed

Lines changed: 27 additions & 0 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
569569
mSettings->checkAllConfigurations = false; // Can be overridden with --max-configs or --force
570570
const std::string projectFile = argv[i]+10;
571571
ImportProject::Type projType = mSettings->project.import(projectFile, mSettings);
572+
mSettings->project.projectType = projType;
572573
if (projType == ImportProject::Type::CPPCHECK_GUI) {
573574
mPathNames = mSettings->project.guiProject.pathNames;
574575
for (const std::string &lib : mSettings->project.guiProject.libraries)
@@ -623,6 +624,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
623624
}
624625
}
625626

627+
// --project-configuration
628+
else if (std::strncmp(argv[i], "--project-configuration=", 24) == 0) {
629+
mVSConfig = argv[i] + 24;
630+
if (!mVSConfig.empty() && (mSettings->project.projectType == ImportProject::Type::VS_SLN || mSettings->project.projectType == ImportProject::Type::VS_VCXPROJ))
631+
mSettings->project.ignoreOtherConfigs(mVSConfig);
632+
}
633+
626634
// Report progress
627635
else if (std::strcmp(argv[i], "--report-progress") == 0) {
628636
mSettings->reportProgress = true;
@@ -1106,6 +1114,11 @@ void CmdLineParser::printHelp()
11061114
" or Borland C++ Builder 6 (*.bpr). The files to analyse,\n"
11071115
" include paths, defines, platform and undefines in\n"
11081116
" the specified file will be used.\n"
1117+
" --project-configuration=<config>\n"
1118+
" If used together with a Visual Studio Solution (*.sln)\n"
1119+
" or Visual Studio Project (*.vcxproj) you can limit\n"
1120+
" the configuration cppcheck should check.\n"
1121+
" For example: ""--project-configuration=Release|Win32"""
11091122
" --max-configs=<limit>\n"
11101123
" Maximum number of configurations to check in a file\n"
11111124
" before skipping it. Default is '12'. If used together\n"

cli/cmdlineparser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class CmdLineParser {
114114
bool mShowVersion;
115115
bool mShowErrorMessages;
116116
bool mExitAfterPrint;
117+
std::string mVSConfig;
117118
};
118119

119120
/// @}

lib/importproject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#include <sstream>
3535

3636

37+
ImportProject::ImportProject()
38+
{
39+
projectType = Type::UNKNOWN;
40+
}
41+
3742
void ImportProject::ignorePaths(const std::vector<std::string> &ipaths)
3843
{
3944
for (std::list<FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {

lib/importproject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class CPPCHECKLIB ImportProject {
8181
void setIncludePaths(const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);
8282
};
8383
std::list<FileSettings> fileSettings;
84+
Type projectType;
85+
86+
ImportProject();
8487

8588
void selectOneVsConfig(cppcheck::Platform::PlatformType platform);
8689

man/manual.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ Running Cppcheck on a Visual Studio project:
179179

180180
cppcheck --project=foobar.vcxproj
181181

182+
Both options will analyze all available configurations in the project(s).
183+
Limiting on a single configuration:
184+
185+
cppcheck --project=foobar.sln "--project-configuration=Release|Win32"
186+
182187
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.
183188

184189
To ignore certain folders in the project you can use `-i`. This will skip analysis of source files in the `foo` folder.

0 commit comments

Comments
 (0)