Commit 346e84d2 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: introduce a project config file field in the projectPart.

This field is used by the generic project manager which passes the
".config" file in it. The advantage is that both the SnapshotUpdater and
the clang code model do not need to do anything smart, but can pass it
directly to the preprocessor.

Task-number: QTCREATORBUG-11390
Change-Id: I44fc7b20afd28fb59608412f2cce86af6f7e7d6b
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 36dccb42
......@@ -198,6 +198,9 @@ QStringList createClangOptions(const ProjectPart::Ptr &pPart, ProjectFile::Kind
result << QLatin1String("-fmacro-backtrace-limit=0");
result << QLatin1String("-fretain-comments-from-system-headers");
if (!pPart->projectConfigFile.isEmpty())
result << QLatin1String("-include") << pPart->projectConfigFile;
result << buildDefines(pPart->toolchainDefines, false);
result << buildDefines(pPart->projectDefines, false);
......
......@@ -560,14 +560,16 @@ void CppCodeModelInspectorDumper::dumpProjectInfos(
projectName = project->displayName();
projectFilePath = project->projectFilePath();
}
if (!part->projectConfigFile.isEmpty())
m_out << i3 << "Project Config File: " << part->projectConfigFile << "\n";
m_out << i2 << "Project Part \"" << part->projectFile << "\"{{{3\n";
m_out << i3 << "Project Part Name: " << part->displayName << "\n";
m_out << i3 << "Project Name : " << projectName << "\n";
m_out << i3 << "Project File : " << projectFilePath << "\n";
m_out << i3 << "C Version : " << toString(part->cVersion) << "\n";
m_out << i3 << "CXX Version : " << toString(part->cxxVersion) << "\n";
m_out << i3 << "CXX Extensions : " << toString(part->cxxExtensions) << "\n";
m_out << i3 << "Qt Version : " << toString(part->qtVersion) << "\n";
m_out << i3 << "Project Part Name : " << part->displayName << "\n";
m_out << i3 << "Project Name : " << projectName << "\n";
m_out << i3 << "Project File : " << projectFilePath << "\n";
m_out << i3 << "C Version : " << toString(part->cVersion) << "\n";
m_out << i3 << "CXX Version : " << toString(part->cxxVersion) << "\n";
m_out << i3 << "CXX Extensions : " << toString(part->cxxExtensions) << "\n";
m_out << i3 << "Qt Version : " << toString(part->qtVersion) << "\n";
if (!part->files.isEmpty()) {
m_out << i3 << "Files:{{{4\n";
......@@ -2246,6 +2248,9 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr &
<< qMakePair(QString::fromLatin1("CXX Extensions"), toString(part->cxxExtensions))
<< qMakePair(QString::fromLatin1("Qt Version"), toString(part->qtVersion))
;
if (!part->projectConfigFile.isEmpty())
table.prepend(qMakePair(QString::fromLatin1("Project Config File"),
part->projectConfigFile));
m_partGenericInfoModel->configure(table);
resizeColumns<KeyValueModel>(m_ui->partGeneralView);
......
......@@ -65,7 +65,7 @@ namespace CppTools {
uint qHash(const ProjectPart &p)
{
uint h = qHash(p.toolchainDefines) ^ qHash(p.projectDefines) ^ p.cVersion ^ p.cxxVersion
^ p.cxxExtensions ^ p.qtVersion;
^ p.cxxExtensions ^ p.qtVersion ^ qHash(p.projectConfigFile);
foreach (const QString &i, p.includePaths)
h ^= qHash(i);
......@@ -83,6 +83,8 @@ bool operator==(const ProjectPart &p1,
return false;
if (p1.projectDefines != p2.projectDefines)
return false;
if (p1.projectConfigFile != p2.projectConfigFile)
return false;
if (p1.cVersion != p2.cVersion)
return false;
if (p1.cxxVersion != p2.cxxVersion)
......@@ -393,6 +395,8 @@ QByteArray CppModelManager::internalDefinedMacros() const
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
addUnique(part->toolchainDefines.split('\n'), &macros, &alreadyIn);
addUnique(part->projectDefines.split('\n'), &macros, &alreadyIn);
if (!part->projectConfigFile.isEmpty())
macros += readProjectConfigFile(part);
}
}
return macros;
......@@ -434,6 +438,7 @@ void CppModelManager::dumpModelManagerConfiguration()
qDebug() << "cxxVersion:" << cxxVersion;
qDebug() << "cxxExtensions:" << cxxExtensions;
qDebug() << "Qt version:" << part->qtVersion;
qDebug() << "project config file:" << part->projectConfigFile;
qDebug() << "precompiled header:" << part->precompiledHeaders;
qDebug() << "toolchain defines:" << part->toolchainDefines;
qDebug() << "project defines:" << part->projectDefines;
......
......@@ -223,4 +223,24 @@ void CppModelManagerInterface::ProjectInfo::appendProjectPart(const ProjectPart:
m_defines.append('\n');
m_defines.append(part->toolchainDefines);
m_defines.append(part->projectDefines);
if (!part->projectConfigFile.isEmpty()) {
m_defines.append('\n');
m_defines += readProjectConfigFile(part);
m_defines.append('\n');
}
}
QByteArray CppModelManagerInterface::readProjectConfigFile(const ProjectPart::Ptr &part)
{
QByteArray result;
QFile f(part->projectConfigFile);
if (f.open(QIODevice::ReadOnly)) {
QTextStream is(&f);
result = is.readAll().toUtf8();
f.close();
}
return result;
}
......@@ -106,6 +106,7 @@ public:
QString projectFile;
ProjectExplorer::Project *project;
QList<ProjectFile> files;
QString projectConfigFile; // currently only used by the Generic Project Manager
QByteArray projectDefines;
QByteArray toolchainDefines;
QStringList includePaths;
......@@ -290,6 +291,9 @@ public slots:
virtual void updateModifiedSourceFiles() = 0;
virtual void GC() = 0;
protected:
static QByteArray readProjectConfigFile(const ProjectPart::Ptr &part);
};
} // namespace CppTools
......
......@@ -60,6 +60,7 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
QStringList includePaths;
QStringList frameworkPaths;
QStringList precompiledHeaders;
QString projectConfigFile;
updateProjectPart();
......@@ -73,6 +74,7 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
configFile += m_projectPart->projectDefines;
includePaths = m_projectPart->includePaths;
frameworkPaths = m_projectPart->frameworkPaths;
projectConfigFile = m_projectPart->projectConfigFile;
if (m_usePrecompiledHeaders)
precompiledHeaders = m_projectPart->precompiledHeaders;
}
......@@ -99,6 +101,11 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
invalidateSnapshot = true;
}
if (projectConfigFile != m_projectConfigFile) {
m_projectConfigFile = projectConfigFile;
invalidateSnapshot = true;
}
if (precompiledHeaders != m_precompiledHeaders) {
m_precompiledHeaders = precompiledHeaders;
invalidateSnapshot = true;
......@@ -160,6 +167,8 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
preproc.setIncludePaths(m_includePaths);
preproc.setFrameworkPaths(m_frameworkPaths);
preproc.run(configurationFileName);
if (!m_projectConfigFile.isEmpty())
preproc.run(m_projectConfigFile);
if (m_usePrecompiledHeaders) {
foreach (const QString &precompiledHeader, m_precompiledHeaders)
preproc.run(precompiledHeader);
......
......@@ -78,6 +78,7 @@ private:
QByteArray m_editorDefines;
QStringList m_includePaths;
QStringList m_frameworkPaths;
QString m_projectConfigFile;
QStringList m_precompiledHeaders;
CPlusPlus::Snapshot m_snapshot;
CPlusPlus::DependencyTable m_deps;
......
......@@ -218,15 +218,6 @@ void GenericProject::parseProject(RefreshOptions options)
// TODO: Possibly load some configuration from the project file
//QSettings projectInfo(m_fileName, QSettings::IniFormat);
m_defines.clear();
QFile configFile(configFileName());
if (configFile.open(QFile::ReadOnly)) {
// convert from local/file encoding to UTF-8
QTextStream configStream(&configFile);
m_defines = configStream.readAll().toUtf8();
}
}
if (options & Files)
......@@ -265,7 +256,7 @@ void GenericProject::refresh(RefreshOptions options)
}
part->cxxVersion = CppTools::ProjectPart::CXX11; // assume C++11
part->projectDefines += m_defines;
part->projectConfigFile = configFileName();
// ### add _defines.
......@@ -348,11 +339,6 @@ QStringList GenericProject::files() const
return m_files;
}
QByteArray GenericProject::defines() const
{
return m_defines;
}
QString GenericProject::displayName() const
{
return m_projectName;
......
......@@ -81,7 +81,6 @@ public:
void refresh(RefreshOptions options);
QByteArray defines() const;
QStringList projectIncludePaths() const;
QStringList files() const;
......@@ -108,7 +107,6 @@ private:
QStringList m_files;
QHash<QString, QString> m_rawListEntries;
QStringList m_projectIncludePaths;
QByteArray m_defines;
GenericProjectNode *m_rootNode;
QFuture<void> m_codeModelFuture;
......
......@@ -48,6 +48,11 @@
namespace GenericProjectManager {
namespace Internal {
static const char *const ConfigFileTemplate =
"// Add predefined macros for your project here. For example:\n"
"// #define THE_ANSWER 42\n"
;
//////////////////////////////////////////////////////////////////////////////
//
// GenericProjectWizardDialog
......@@ -189,7 +194,7 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
generatedIncludesFile.setContents(includePaths.join(QLatin1String("\n")));
Core::GeneratedFile generatedConfigFile(configFileName);
generatedConfigFile.setContents(QLatin1String("// ADD PREDEFINED MACROS HERE!\n"));
generatedConfigFile.setContents(QLatin1String(ConfigFileTemplate));
Core::GeneratedFiles files;
files.append(generatedFilesFile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment