GUI: Added CFGDIR qmake flag
This commit is contained in:
parent
ac91aa4fdf
commit
c143b02e67
@ -145,3 +145,9 @@ win32 {
|
|||||||
HEADERS += ../lib/version.h
|
HEADERS += ../lib/version.h
|
||||||
LIBS += -lshlwapi
|
LIBS += -lshlwapi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# CFGDIR=xyz
|
||||||
|
contains(CFGDIR, .+) {
|
||||||
|
DEFINES += CFGDIR=\\\"$${CFGDIR}\\\"
|
||||||
|
}
|
||||||
|
@ -512,6 +512,31 @@ void MainWindow::AddIncludeDirs(const QStringList &includeDirs, Settings &result
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWindow::LoadLibrary(Library *library, QString filename)
|
||||||
|
{
|
||||||
|
// Try to load the library from the project folder..
|
||||||
|
if (mProject) {
|
||||||
|
QString path = QFileInfo(mProject->GetProjectFile()->GetFilename()).canonicalPath();
|
||||||
|
if (library->load(NULL, (path+"/"+filename).toLatin1()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Library::cfgdir() && library->load(NULL, (Library::cfgdir()+('/'+filename)).toLatin1()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Try to load the library from the application folder..
|
||||||
|
QString path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
|
if (library->load(NULL, (path+"/"+filename).toLatin1()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Try to load the library from the cfg subfolder..
|
||||||
|
path = path + "/cfg";
|
||||||
|
if (library->load(NULL, (path+"/"+filename).toLatin1()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Settings MainWindow::GetCppcheckSettings()
|
Settings MainWindow::GetCppcheckSettings()
|
||||||
{
|
{
|
||||||
Settings result;
|
Settings result;
|
||||||
@ -533,23 +558,8 @@ Settings MainWindow::GetCppcheckSettings()
|
|||||||
QStringList libraries = pfile->GetLibraries();
|
QStringList libraries = pfile->GetLibraries();
|
||||||
foreach(QString library, libraries) {
|
foreach(QString library, libraries) {
|
||||||
const QString filename = library + ".cfg";
|
const QString filename = library + ".cfg";
|
||||||
|
if (!LoadLibrary(&result.library, filename))
|
||||||
// Try to load the library from the project folder..
|
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename));
|
||||||
QString path = QFileInfo(pfile->GetFilename()).canonicalPath();
|
|
||||||
if (result.library.load("", (path+"/"+filename).toLatin1()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Try to load the library from the application folder..
|
|
||||||
path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
|
||||||
if (result.library.load("", (path+"/"+filename).toLatin1()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Try to load the library from the cfg subfolder..
|
|
||||||
path = path + "/cfg";
|
|
||||||
if (result.library.load("", (path+"/"+filename).toLatin1()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only check the given -D configuration
|
// Only check the given -D configuration
|
||||||
@ -586,11 +596,10 @@ Settings MainWindow::GetCppcheckSettings()
|
|||||||
result.standards.c = mSettings->value(SETTINGS_STD_C99, true).toBool() ? Standards::C99 : (mSettings->value(SETTINGS_STD_C11, false).toBool() ? Standards::C11 : Standards::C89);
|
result.standards.c = mSettings->value(SETTINGS_STD_C99, true).toBool() ? Standards::C99 : (mSettings->value(SETTINGS_STD_C11, false).toBool() ? Standards::C11 : Standards::C89);
|
||||||
result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool();
|
result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool();
|
||||||
|
|
||||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
bool std = LoadLibrary(&result.library, "std.cfg");
|
||||||
bool std = result.library.load(applicationFilePath.toLatin1(), "std.cfg");
|
|
||||||
bool posix = true;
|
bool posix = true;
|
||||||
if (result.standards.posix)
|
if (result.standards.posix)
|
||||||
posix = result.library.load(applicationFilePath.toLatin1(), "posix.cfg");
|
posix = LoadLibrary(&result.library, "posix.cfg");
|
||||||
|
|
||||||
if (!std || !posix)
|
if (!std || !posix)
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken.").arg(!std ? "std.cfg" : "posix.cfg"));
|
QMessageBox::warning(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken.").arg(!std ? "std.cfg" : "posix.cfg"));
|
||||||
|
@ -424,6 +424,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
void LoadProjectFile(const QString &filePath);
|
void LoadProjectFile(const QString &filePath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Load library file
|
||||||
|
* @param Library library to use
|
||||||
|
* @param filename filename (no path)
|
||||||
|
* @return True if successful
|
||||||
|
*/
|
||||||
|
bool LoadLibrary(Library *library, QString filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update project MRU items in File-menu.
|
* @brief Update project MRU items in File-menu.
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "projectfiledialog.h"
|
#include "projectfiledialog.h"
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
@ -42,23 +43,33 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
|||||||
// Checkboxes for the libraries..
|
// Checkboxes for the libraries..
|
||||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||||
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
|
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
|
||||||
const QString searchPaths[] = { appPath, appPath + "/cfg", inf.canonicalPath() };
|
QStringList searchPaths;
|
||||||
for (int i = 0; i < 3; i++) {
|
if (Library::cfgdir())
|
||||||
QDir dir(searchPaths[i]);
|
searchPaths << Library::cfgdir();
|
||||||
|
searchPaths << inf.canonicalPath();
|
||||||
|
searchPaths << appPath;
|
||||||
|
searchPaths << (appPath + "/cfg");
|
||||||
|
QStringList libraries;
|
||||||
|
foreach(const QString path, searchPaths) {
|
||||||
|
QDir dir(path);
|
||||||
dir.setSorting(QDir::Name);
|
dir.setSorting(QDir::Name);
|
||||||
dir.setNameFilters(QStringList("*.cfg"));
|
dir.setNameFilters(QStringList("*.cfg"));
|
||||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||||
foreach(QFileInfo item, dir.entryInfoList()) {
|
foreach(QFileInfo item, dir.entryInfoList()) {
|
||||||
QString library = item.fileName();
|
libraries << item.fileName();
|
||||||
library.chop(4);
|
|
||||||
if (library.compare("std", Qt::CaseInsensitive) == 0)
|
|
||||||
continue;
|
|
||||||
QCheckBox *checkbox = new QCheckBox(this);
|
|
||||||
checkbox->setText(library);
|
|
||||||
mUI.librariesLayout->addWidget(checkbox);
|
|
||||||
mLibraryCheckboxes << checkbox;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
libraries.removeDuplicates();
|
||||||
|
libraries.sort();
|
||||||
|
foreach(QString library, libraries) {
|
||||||
|
library.chop(4);
|
||||||
|
if (library.compare("std", Qt::CaseInsensitive) == 0)
|
||||||
|
continue;
|
||||||
|
QCheckBox *checkbox = new QCheckBox(this);
|
||||||
|
checkbox->setText(library);
|
||||||
|
mUI.librariesLayout->addWidget(checkbox);
|
||||||
|
mLibraryCheckboxes << checkbox;
|
||||||
|
}
|
||||||
|
|
||||||
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(mUI.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir()));
|
connect(mUI.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir()));
|
||||||
|
@ -44,6 +44,15 @@ class CPPCHECKLIB Library {
|
|||||||
public:
|
public:
|
||||||
Library();
|
Library();
|
||||||
|
|
||||||
|
/** return cfgdir or NULL */
|
||||||
|
static const char *cfgdir() {
|
||||||
|
#ifdef CFGDIR
|
||||||
|
return CFGDIR;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool load(const char exename [], const char path []);
|
bool load(const char exename [], const char path []);
|
||||||
bool load(const tinyxml2::XMLDocument &doc);
|
bool load(const tinyxml2::XMLDocument &doc);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user