diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 5dff8d26f..42f51d486 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -917,7 +917,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } } - mSettings->loadCppcheckCfg(Path::getPathFromFilename(argv[0]) + "cppcheck.cfg"); + mSettings->loadCppcheckCfg(argv[0]); // Default template format.. if (mSettings->templateFormat.empty()) { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 812970e66..dc2888ace 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -508,9 +508,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar checkSettings.checkLibrary = checkLibrary; checkSettings.checkConfiguration = checkConfiguration; - const QString applicationFilePath = QCoreApplication::applicationFilePath(); - const QString appPath = QFileInfo(applicationFilePath).canonicalPath(); - checkSettings.loadCppcheckCfg(appPath.toStdString() + "/cppcheck.cfg"); + checkSettings.loadCppcheckCfg(QCoreApplication::applicationFilePath().toStdString()); if (mProjectFile) qDebug() << "Checking project file" << mProjectFile->getFilename(); diff --git a/lib/settings.cpp b/lib/settings.cpp index 64085830f..359fd3c77 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -76,9 +76,15 @@ Settings::Settings() certainty.setEnabled(Certainty::normal, true); } -void Settings::loadCppcheckCfg(const std::string &filename) +void Settings::loadCppcheckCfg(const std::string &exename) { - std::ifstream fin(filename); + std::string fileName = Path::getPathFromFilename(exename) + "cppcheck.cfg"; +#ifdef FILESDIR + if (Path::fileExists(FILESDIR "/cppcheck.cfg")) + fileName = FILESDIR "/cppcheck.cfg"; +#endif + + std::ifstream fin(fileName); if (!fin.is_open()) return; picojson::value json; @@ -90,7 +96,7 @@ void Settings::loadCppcheckCfg(const std::string &filename) for (const picojson::value &v : obj["addons"].get()) { const std::string &s = v.get(); if (!Path::isAbsolute(s)) - addons.push_back(Path::getPathFromFilename(filename) + s); + addons.push_back(Path::getPathFromFilename(fileName) + s); else addons.push_back(s); } diff --git a/lib/settings.h b/lib/settings.h index 6447816e7..e1c29b865 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -95,7 +95,7 @@ private: public: Settings(); - void loadCppcheckCfg(const std::string &filename); + void loadCppcheckCfg(const std::string &exepath); /** @brief addons, either filename of python/json file or json data */ std::list addons;