GUI: Added CFGDIR qmake flag
This commit is contained in:
parent
ac91aa4fdf
commit
c143b02e67
|
@ -145,3 +145,9 @@ win32 {
|
|||
HEADERS += ../lib/version.h
|
||||
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 result;
|
||||
|
@ -533,23 +558,8 @@ Settings MainWindow::GetCppcheckSettings()
|
|||
QStringList libraries = pfile->GetLibraries();
|
||||
foreach(QString library, libraries) {
|
||||
const QString filename = library + ".cfg";
|
||||
|
||||
// Try to load the library from the project folder..
|
||||
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));
|
||||
if (!LoadLibrary(&result.library, filename))
|
||||
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename));
|
||||
}
|
||||
|
||||
// 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.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool();
|
||||
|
||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||
bool std = result.library.load(applicationFilePath.toLatin1(), "std.cfg");
|
||||
bool std = LoadLibrary(&result.library, "std.cfg");
|
||||
bool posix = true;
|
||||
if (result.standards.posix)
|
||||
posix = result.library.load(applicationFilePath.toLatin1(), "posix.cfg");
|
||||
posix = LoadLibrary(&result.library, "posix.cfg");
|
||||
|
||||
if (!std || !posix)
|
||||
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);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QSettings>
|
||||
#include "common.h"
|
||||
#include "projectfiledialog.h"
|
||||
#include "library.h"
|
||||
|
||||
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
|
@ -42,23 +43,33 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
|||
// Checkboxes for the libraries..
|
||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
|
||||
const QString searchPaths[] = { appPath, appPath + "/cfg", inf.canonicalPath() };
|
||||
for (int i = 0; i < 3; i++) {
|
||||
QDir dir(searchPaths[i]);
|
||||
QStringList searchPaths;
|
||||
if (Library::cfgdir())
|
||||
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.setNameFilters(QStringList("*.cfg"));
|
||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach(QFileInfo item, dir.entryInfoList()) {
|
||||
QString library = 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 << item.fileName();
|
||||
}
|
||||
}
|
||||
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.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir()));
|
||||
|
|
|
@ -44,6 +44,15 @@ class CPPCHECKLIB Library {
|
|||
public:
|
||||
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 tinyxml2::XMLDocument &doc);
|
||||
|
||||
|
|
Loading…
Reference in New Issue