@@ -385,6 +385,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
385385
386386 ImportProject::Type projectType = ImportProject::Type::NONE;
387387 ImportProject project;
388+ bool projectSettings = false ;
388389 std::string vsConfig;
389390
390391 std::string platform;
@@ -1132,16 +1133,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11321133 }
11331134 }
11341135
1135- // --project
1136- else if (std::strncmp (argv[i], " --project=" , 10 ) == 0 ) {
1136+ // --project, --project-settings
1137+ else if (std::strncmp (argv[i], " --project=" , 10 ) == 0 || std::strncmp (argv[i], " --project-settings= " , 19 ) == 0 ) {
11371138 if (projectType != ImportProject::Type::NONE)
11381139 {
11391140 mLogger .printError (" multiple --project options are not supported." );
11401141 return Result::Fail;
11411142 }
11421143
1144+ projectSettings = (std::strncmp (argv[i], " --project-settings=" , 19 ) == 0 );
1145+
11431146 mSettings .checkAllConfigurations = false ; // Can be overridden with --max-configs or --force
1144- std::string projectFile = argv[i]+ 10 ;
1147+ std::string projectFile = std::strchr ( argv[i], ' = ' ) + 1 ;
11451148 projectType = project.import (projectFile, &mSettings , &mSuppressions , isCppcheckPremium ());
11461149 if (projectType == ImportProject::Type::CPPCHECK_GUI) {
11471150 for (const std::string &lib : project.guiProject .libraries )
@@ -1582,6 +1585,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15821585 // mLogger.printMessage("whole program analysis requires --cppcheck-build-dir to be active with -j.");
15831586 }
15841587
1588+ if (projectSettings) {
1589+ mSettings .fileFilters .insert (mSettings .fileFilters .end (), mPathNames .cbegin (), mPathNames .cend ());
1590+ mPathNames .clear ();
1591+ }
1592+
15851593 if (!mPathNames .empty () && projectType != ImportProject::Type::NONE) {
15861594 mLogger .printError (" --project cannot be used in conjunction with source files." );
15871595 return Result::Fail;
@@ -1918,6 +1926,16 @@ void CmdLineParser::printHelp() const
19181926 " or Visual Studio Project (*.vcxproj) you can limit\n "
19191927 " the configuration cppcheck should check.\n "
19201928 " For example: '--project-configuration=Release|Win32'\n "
1929+ " --project-settings=<file>\n "
1930+ " IDE option: Import settings from project file. Preprocessor\n "
1931+ " settings, suppressions, coding standards, etc. are imported.\n "
1932+ " Unlike --project the files to analyse is not imported with this\n "
1933+ " option.\n "
1934+ " These two commands are effectively the same:\n "
1935+ " cppcheck --project=foo --file-filter=src/test.c\n "
1936+ " cppcheck --project-settings=foo src/test.c\n "
1937+ " Both commands will load the project foo and then analyse only the\n "
1938+ " file src/test.c\n "
19211939 " -q, --quiet Do not show progress reports.\n "
19221940 " Note that this option is not mutually exclusive with --verbose.\n "
19231941 " -rp=<paths>, --relative-paths=<paths>\n "
0 commit comments