diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp old mode 100755 new mode 100644 index 337f3ffd4..0fda30fb8 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -119,16 +119,6 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS continue; QStringList args; -#ifdef Q_OS_WIN - // To create compile_commands.json in windows see: - // https://bitsmaker.gitlab.io/post/clang-tidy-from-vs2015/ - - // TODO: Replace the "QDir::homePath()" - args << "-isystem" << (QDir::homePath() + "/include"); - args << "-isystem" << (QDir::homePath() + "/include/c++"); - args << "-isystem" << (QDir::homePath() + "/include/c++/i686-w64-mingw32"); - args << "-fno-ms-compatibility"; -#endif for (std::list::const_iterator I = fileSettings->includePaths.begin(); I != fileSettings->includePaths.end(); ++I) args << ("-I" + QString::fromStdString(*I)); for (std::list::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i) @@ -136,8 +126,36 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS foreach (QString D, QString::fromStdString(fileSettings->defines).split(";")) { args << ("-D" + D); } + + if (!mClangPath.isEmpty()) { + QDir dir(mClangPath + "/../lib/clang"); + foreach (QString ver, dir.entryList()) { + QString includePath = dir.absolutePath() + '/' + ver + "/include"; + if (ver[0] != '.' && QDir(includePath).exists()) { + args << "-isystem" << includePath; + break; + } + } + } + +#ifdef Q_OS_WIN + // To create compile_commands.json in windows see: + // https://bitsmaker.gitlab.io/post/clang-tidy-from-vs2015/ + + foreach (QString s, mVsIncludePaths.split(";")) { + if (!s.isEmpty()) { + s.replace("\\", "/"); + args << "-isystem" << s; + } + } + + args << "-fno-ms-compatibility"; +#endif + if (!fileSettings->standard.empty()) - args << (" -std=" + QString::fromStdString(fileSettings->standard)); + args << ("-std=" + QString::fromStdString(fileSettings->standard)); + else if (!mVsIncludePaths.isEmpty() && fileName.endsWith(".cpp")) + args << "-std=c++14"; QString analyzerInfoFile; @@ -149,7 +167,6 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS QStringList args2(args); args2.insert(0,"-E"); args2 << fileName; - qDebug() << cmd << args2; QProcess process; process.start(cmd,args2); process.waitForFinished(); @@ -192,7 +209,10 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS { QString debug(cmd); foreach (QString arg, args) { - debug += ' ' + arg; + if (arg.contains(" ")) + debug += " \"" + arg + '\"'; + else + debug += ' ' + arg; } qDebug() << debug; } diff --git a/gui/checkthread.h b/gui/checkthread.h index c8fce5fbb..7728fde86 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -56,6 +56,10 @@ public: mAddons = addons; } + void setVsIncludePaths(const QString &s) { + mVsIncludePaths = s; + } + void setDataDir(const QString &dataDir) { mDataDir = dataDir; } @@ -120,6 +124,7 @@ private: QStringList mFiles; bool mAnalyseWholeProgram; QStringList mAddons; + QString mVsIncludePaths; QString mDataDir; QString mClangPath; }; diff --git a/gui/common.h b/gui/common.h index f98e3a68a..330cb77b0 100644 --- a/gui/common.h +++ b/gui/common.h @@ -80,6 +80,7 @@ #define SETTINGS_APPLICATION_DEFAULT "Default Application" #define SETTINGS_LANGUAGE "Application language" #define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths" +#define SETTINGS_VS_INCLUDE_PATHS "Visual studio include paths" #define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions" #define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors" #define SETTINGS_MRU_PROJECTS "MRU Projects" diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6b50df1d1..5ec6fff32 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -414,6 +414,7 @@ void MainWindow::doAnalyzeProject(ImportProject p) //mThread->SetanalyzeProject(true); if (mProjectFile) { mThread->setAddons(mProjectFile->getAddons()); + mThread->setVsIncludePaths(mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString()); #ifdef Q_OS_WIN // Try to autodetect clang if (QFileInfo("C:/Program Files/LLVM/bin/clang.exe").exists()) diff --git a/gui/settings.ui b/gui/settings.ui index 1f2b1f0e6..c2243d460 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -240,6 +240,16 @@ + + + + <html><head/><body><p>Visual Studio include paths<br/>Open Visual Studio command prompt. Type &quot;SET INCLUDE&quot; and paste the outputs below:</p></body></html> + + + + + + diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index bcf486b3a..f48b486f9 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -54,6 +54,15 @@ SettingsDialog::SettingsDialog(ApplicationList *list, mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool())); mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool())); +#ifdef Q_OS_WIN + mUI.mLabelVsInclude->setVisible(true); + mUI.mEditVsInclude->setVisible(true); + mUI.mEditVsInclude->setText(settings.value(SETTINGS_VS_INCLUDE_PATHS, QString()).toString()); +#else + mUI.mLabelVsInclude->setVisible(false); + mUI.mEditVsInclude->setVisible(false); + mUI.mEditVsInclude->setText(QString()); +#endif connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok); connect(mUI.mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject); connect(mUI.mBtnAddApplication, SIGNAL(clicked()), @@ -177,6 +186,13 @@ void SettingsDialog::saveSettingValues() const saveCheckboxValue(&settings, mUI.mShowStatistics, SETTINGS_SHOW_STATISTICS); saveCheckboxValue(&settings, mUI.mShowErrorId, SETTINGS_SHOW_ERROR_ID); +#ifdef Q_OS_WIN + QString vsIncludePaths = mUI.mEditVsInclude->text(); + if (vsIncludePaths.startsWith("INCLUDE=")) + vsIncludePaths.remove(0, 8); + settings.setValue(SETTINGS_VS_INCLUDE_PATHS, vsIncludePaths); +#endif + const QListWidgetItem *currentLang = mUI.mListLanguages->currentItem(); if (currentLang) { const QString langcode = currentLang->data(LangCodeRole).toString(); diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 71bf7f18d..de1500bb7 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -93,6 +93,7 @@ void ThreadHandler::check(const Settings &settings) for (int i = 0; i < mRunningThreadCount; i++) { mThreads[i]->setAddons(mAddons); + mThreads[i]->setVsIncludePaths(mVsIncludePaths); mThreads[i]->setClangPath(mClangPath); mThreads[i]->setDataDir(mDataDir); mThreads[i]->check(settings); diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 4821eb222..72e724663 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -75,6 +75,10 @@ public: mAddons = addons; } + void setVsIncludePaths(const QString &s) { + mVsIncludePaths = s; + } + void setClangPath(const QString &p) { mClangPath = p; } @@ -246,6 +250,7 @@ protected: bool mAnalyseWholeProgram; QStringList mAddons; + QString mVsIncludePaths; QString mClangPath; QString mDataDir;