Skip to content

Commit ed4d2c2

Browse files
committed
Load cppcheck.cfg in FILESDIR if that is specified
1 parent b2f1a0a commit ed4d2c2

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
917917
}
918918
}
919919

920-
mSettings->loadCppcheckCfg(Path::getPathFromFilename(argv[0]) + "cppcheck.cfg");
920+
mSettings->loadCppcheckCfg(argv[0]);
921921

922922
// Default template format..
923923
if (mSettings->templateFormat.empty()) {

gui/mainwindow.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
508508
checkSettings.checkLibrary = checkLibrary;
509509
checkSettings.checkConfiguration = checkConfiguration;
510510

511-
const QString applicationFilePath = QCoreApplication::applicationFilePath();
512-
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
513-
checkSettings.loadCppcheckCfg(appPath.toStdString() + "/cppcheck.cfg");
511+
checkSettings.loadCppcheckCfg(QCoreApplication::applicationFilePath().toStdString());
514512

515513
if (mProjectFile)
516514
qDebug() << "Checking project file" << mProjectFile->getFilename();

lib/settings.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ Settings::Settings()
7676
certainty.setEnabled(Certainty::normal, true);
7777
}
7878

79-
void Settings::loadCppcheckCfg(const std::string &filename)
79+
void Settings::loadCppcheckCfg(const std::string &exename)
8080
{
81-
std::ifstream fin(filename);
81+
std::string fileName = Path::getPathFromFilename(exename) + "cppcheck.cfg";
82+
#ifdef FILESDIR
83+
if (Path::fileExists(FILESDIR "/cppcheck.cfg"))
84+
fileName = FILESDIR "/cppcheck.cfg";
85+
#endif
86+
87+
std::ifstream fin(fileName);
8288
if (!fin.is_open())
8389
return;
8490
picojson::value json;
@@ -90,7 +96,7 @@ void Settings::loadCppcheckCfg(const std::string &filename)
9096
for (const picojson::value &v : obj["addons"].get<picojson::array>()) {
9197
const std::string &s = v.get<std::string>();
9298
if (!Path::isAbsolute(s))
93-
addons.push_back(Path::getPathFromFilename(filename) + s);
99+
addons.push_back(Path::getPathFromFilename(fileName) + s);
94100
else
95101
addons.push_back(s);
96102
}

lib/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CPPCHECKLIB Settings : public cppcheck::Platform {
9595
public:
9696
Settings();
9797

98-
void loadCppcheckCfg(const std::string &filename);
98+
void loadCppcheckCfg(const std::string &exepath);
9999

100100
/** @brief addons, either filename of python/json file or json data */
101101
std::list<std::string> addons;

0 commit comments

Comments
 (0)