Skip to content
Snippets Groups Projects
Commit 8df85570 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Initial work on pkg-config support.

parent 1db3f56d
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,12 @@ HEADERS = genericproject.h \
genericprojectmanager.h \
genericprojectconstants.h \
genericprojectnodes.h \
pkgconfigtool.h \
makestep.h
SOURCES = genericproject.cpp \
genericprojectplugin.cpp \
genericprojectmanager.cpp \
genericprojectnodes.cpp \
pkgconfigtool.cpp \
makestep.cpp
RESOURCES += genericproject.qrc
FORMS +=
#include "pkgconfigtool.h"
#include <QProcess>
#include <QTextStream>
#include <QtDebug>
using namespace GenericProjectManager::Internal;
PkgConfigTool::PkgConfigTool()
{ }
PkgConfigTool::~PkgConfigTool()
{ }
QList<PkgConfigTool::Package> PkgConfigTool::packages() const
{
if (_packages.isEmpty())
packages_helper();
return _packages;
}
void PkgConfigTool::packages_helper() const
{
QStringList args;
args.append(QLatin1String("--list-all"));
QProcess pkgconfig;
pkgconfig.start(QLatin1String("pkg-config"), args);
while (! pkgconfig.waitForFinished()) {
}
QTextStream in(&pkgconfig);
forever {
const QString line = in.readLine();
if (line.isNull())
break;
else if (line.isEmpty())
continue;
int i = 0;
for (; i != line.length(); ++i) {
if (line.at(i).isSpace())
break;
}
Package package;
package.name = line.left(i).trimmed();
package.description = line.mid(i).trimmed();
QStringList args;
args << package.name << QLatin1String("--cflags");
pkgconfig.start(QLatin1String("pkg-config"), args);
while (! pkgconfig.waitForFinished()) {
}
const QString cflags = QString::fromUtf8(pkgconfig.readAll());
int index = 0;
while (index != cflags.size()) {
const QChar ch = cflags.at(index);
if (ch.isSpace()) {
do { ++index; }
while (index < cflags.size() && cflags.at(index).isSpace());
}
else if (ch == QLatin1Char('-') && index + 1 < cflags.size()) {
++index;
const QChar opt = cflags.at(index);
if (opt == QLatin1Char('I')) {
// include paths.
int start = ++index;
for (; index < cflags.size(); ++index) {
if (cflags.at(index).isSpace())
break;
}
qDebug() << "*** add include path:" << cflags.mid(start, index - start);
package.includePaths.append(cflags.mid(start, index - start));
}
}
else {
for (; index < cflags.size(); ++index) {
if (cflags.at(index).isSpace())
break;
}
}
}
_packages.append(package);
}
}
#ifndef PKGCONFIGTOOL_H
#define PKGCONFIGTOOL_H
#include <QObject>
#include <QStringList>
namespace GenericProjectManager {
namespace Internal {
class PkgConfigTool: public QObject
{
Q_OBJECT
public:
struct Package {
QString name;
QString description;
QStringList includePaths;
QStringList defines;
QStringList undefines;
};
public:
PkgConfigTool();
virtual ~PkgConfigTool();
QList<Package> packages() const;
private:
void packages_helper() const;
private:
mutable QList<Package> _packages;
};
} // end of namespace Internal
} // end of namespace GenericProjectManager
#endif // PKGCONFIGTOOL_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment