Commit ea1a9248 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: split defines into project-defined and toolchain-defined.

So we can ignore possibly problematic toolchain-defines, while can still
unconditionally apply project-defines.

Change-Id: I7cb96f35a963d080011fe888ef71bfc098dd33ef
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 18313bdb
......@@ -433,7 +433,7 @@ void AutotoolsProject::updateCppCodeModel()
part->files << CppTools::ProjectFile(file, CppTools::ProjectFile::CXXSource);
part->includePaths += m_makefileParserThread->includePaths();
part->defines += m_makefileParserThread->defines();
part->projectDefines += m_makefileParserThread->defines();
pinfo.appendProjectPart(part);
modelManager->updateProjectInfo(pinfo);
......
......@@ -350,7 +350,7 @@ bool CMakeProject::parseCMakeLists()
// This explicitly adds -I. to the include paths
part->includePaths += projectDirectory();
part->includePaths += cbpparser.includeFiles();
part->defines += cbpparser.defines();
part->projectDefines += cbpparser.defines();
CppTools::ProjectFileAdder adder(part->files);
foreach (const QString &file, m_files)
......
......@@ -64,7 +64,8 @@ namespace CppTools {
uint qHash(const ProjectPart &p)
{
uint h = qHash(p.defines) ^ p.cVersion ^ p.cxxVersion ^ p.cxxExtensions ^ p.qtVersion;
uint h = qHash(p.toolchainDefines) ^ qHash(p.projectDefines) ^ p.cVersion ^ p.cxxVersion
^ p.cxxExtensions ^ p.qtVersion;
foreach (const QString &i, p.includePaths)
h ^= qHash(i);
......@@ -78,7 +79,9 @@ uint qHash(const ProjectPart &p)
bool operator==(const ProjectPart &p1,
const ProjectPart &p2)
{
if (p1.defines != p2.defines)
if (p1.toolchainDefines != p2.toolchainDefines)
return false;
if (p1.projectDefines != p2.projectDefines)
return false;
if (p1.cVersion != p2.cVersion)
return false;
......@@ -363,6 +366,22 @@ QStringList CppModelManager::internalFrameworkPaths() const
return frameworkPaths;
}
static void addUnique(const QList<QByteArray> &defs, QByteArray *macros, QSet<QByteArray> *alreadyIn)
{
Q_ASSERT(macros);
Q_ASSERT(alreadyIn);
foreach (const QByteArray &def, defs) {
if (def.trimmed().isEmpty())
continue;
if (!alreadyIn->contains(def)) {
macros->append(def);
macros->append('\n');
alreadyIn->insert(def);
}
}
}
QByteArray CppModelManager::internalDefinedMacros() const
{
QByteArray macros;
......@@ -372,14 +391,8 @@ QByteArray CppModelManager::internalDefinedMacros() const
it.next();
const ProjectInfo pinfo = it.value();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
const QList<QByteArray> defs = part->defines.split('\n');
foreach (const QByteArray &def, defs) {
if (!alreadyIn.contains(def)) {
macros += def;
macros.append('\n');
alreadyIn.insert(def);
}
}
addUnique(part->toolchainDefines.split('\n'), &macros, &alreadyIn);
addUnique(part->projectDefines.split('\n'), &macros, &alreadyIn);
}
}
return macros;
......@@ -422,7 +435,8 @@ void CppModelManager::dumpModelManagerConfiguration()
qDebug() << "cxxExtensions:" << cxxExtensions;
qDebug() << "Qt version:" << part->qtVersion;
qDebug() << "precompiled header:" << part->precompiledHeaders;
qDebug() << "defines:" << part->defines;
qDebug() << "toolchain defines:" << part->toolchainDefines;
qDebug() << "project defines:" << part->projectDefines;
qDebug() << "includes:" << part->includePaths;
qDebug() << "frameworkPaths:" << part->frameworkPaths;
qDebug() << "files:" << part->files;
......@@ -795,7 +809,7 @@ ProjectPart::Ptr CppModelManager::fallbackProjectPart() const
{
ProjectPart::Ptr part(new ProjectPart);
part->defines = m_definedMacros;
part->projectDefines = m_definedMacros;
part->includePaths = m_includePaths;
part->frameworkPaths = m_frameworkPaths;
part->cVersion = ProjectPart::C11;
......
......@@ -217,7 +217,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean()
ProjectPart::Ptr part(new ProjectPart);
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->projectDefines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths = QStringList() << testDataDir.includeDir(false);
part->frameworkPaths = QStringList() << testDataDir.frameworksDir(false);
pi.appendProjectPart(part);
......@@ -251,7 +251,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
ProjectPart::Ptr part(new ProjectPart);
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->projectDefines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths << testDataDir.includeDir();
part->frameworkPaths << testDataDir.frameworksDir();
const QString &source = testDataDir.fileFromSourcesDir(
......@@ -300,7 +300,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
ProjectPart::Ptr part(new ProjectPart);
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->projectDefines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths = QStringList() << testDataDir.includeDir(false);
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
pi.appendProjectPart(part);
......@@ -320,7 +320,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
QVERIFY(macrosInHeaderBefore.first().name() == "test_modelmanager_refresh_h");
// Introduce a define that will enable another define once the document is reparsed.
part->defines = QByteArray("#define TEST_DEFINE 1\n");
part->projectDefines = QByteArray("#define TEST_DEFINE 1\n");
pi.clearProjectParts();
pi.appendProjectPart(part);
mm->updateProjectInfo(pi);
......@@ -377,7 +377,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
ProjectPart::Ptr part(new ProjectPart);
// Simulate project configuration change by having different defines each time.
defines += "\n#define ANOTHER_DEFINE";
part->defines = defines;
part->projectDefines = defines;
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader));
......@@ -810,7 +810,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
part1->files.append(ProjectFile(header, ProjectFile::CXXHeader));
part1->cxxVersion = ProjectPart::CXX11;
part1->qtVersion = ProjectPart::NoQt;
part1->defines = QByteArray("#define SUB1\n");
part1->projectDefines = QByteArray("#define SUB1\n");
part1->includePaths = QStringList() << testDataDirectory.includeDir(false);
ProjectPart::Ptr part2(new ProjectPart);
......@@ -818,7 +818,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
part2->files.append(ProjectFile(header, ProjectFile::CXXHeader));
part2->cxxVersion = ProjectPart::CXX11;
part2->qtVersion = ProjectPart::NoQt;
part2->defines = QByteArray("#define SUB2\n");
part2->projectDefines = QByteArray("#define SUB2\n");
part2->includePaths = QStringList() << testDataDirectory.includeDir(false);
ProjectInfo pi = mm->projectInfo(project);
......
......@@ -161,13 +161,7 @@ void ProjectPart::evaluateToolchain(const ToolChain *tc,
else
includePaths << header.path();
const QByteArray macros = tc->predefinedMacros(cxxflags);
if (!macros.isEmpty()) {
if (!defines.isEmpty())
defines += '\n';
defines += macros;
defines += '\n';
}
toolchainDefines = tc->predefinedMacros(cxxflags);
}
static CppModelManagerInterface *g_instance = 0;
......@@ -235,5 +229,6 @@ void CppModelManagerInterface::ProjectInfo::appendProjectPart(const ProjectPart:
// Update defines
if (!m_defines.isEmpty())
m_defines.append('\n');
m_defines.append(part->defines);
m_defines.append(part->toolchainDefines);
m_defines.append(part->projectDefines);
}
......@@ -106,7 +106,8 @@ public:
QString projectFile;
ProjectExplorer::Project *project;
QList<ProjectFile> files;
QByteArray defines;
QByteArray projectDefines;
QByteArray toolchainDefines;
QStringList includePaths;
QStringList frameworkPaths;
QStringList precompiledHeaders;
......
......@@ -69,7 +69,8 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
}
if (m_projectPart) {
configFile += m_projectPart->defines;
configFile += m_projectPart->toolchainDefines;
configFile += m_projectPart->projectDefines;
includePaths = m_projectPart->includePaths;
frameworkPaths = m_projectPart->frameworkPaths;
if (m_usePrecompiledHeaders)
......
......@@ -265,7 +265,7 @@ void GenericProject::refresh(RefreshOptions options)
}
part->cxxVersion = CppTools::ProjectPart::CXX11; // assume C++11
part->defines += m_defines;
part->projectDefines += m_defines;
// ### add _defines.
......
......@@ -643,7 +643,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
part->includePaths += grpIncludePaths;
part->frameworkPaths += grpFrameworkPaths;
part->precompiledHeaders = QStringList(pch);
part->defines += grpDefines;
part->projectDefines += grpDefines;
pinfo.appendProjectPart(part);
}
}
......
......@@ -528,7 +528,7 @@ void QmakeProject::updateCppCodeModel()
SysRootKitInformation::sysRoot(k));
// part->defines
part->defines += pro->cxxDefines();
part->projectDefines += pro->cxxDefines();
// part->includePaths, part->frameworkPaths
part->includePaths.append(pro->variableValue(IncludePathVar));
......
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