forked from qt-creator/qt-creator
CMake: Read macro definitions
The CodeBlocks generator writes for each macro definition <Add option=-D... /> (also make getters const) Task-number: QTCREATORBUG-3922 Change-Id: I93e10397e76ad4f34126a76c4c36e4529d48d0ad Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
committed by
Daniel Teske
parent
566fa173b4
commit
b3c4aa99da
@@ -293,6 +293,10 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
allIncludePaths.append(projectDirectory());
|
allIncludePaths.append(projectDirectory());
|
||||||
allIncludePaths.append(cbpparser.includeFiles());
|
allIncludePaths.append(cbpparser.includeFiles());
|
||||||
|
|
||||||
|
QByteArray allDefines;
|
||||||
|
allDefines.append(activeBC->toolChain()->predefinedMacros(QStringList()));
|
||||||
|
allDefines.append(cbpparser.defines());
|
||||||
|
|
||||||
QStringList allFrameworkPaths;
|
QStringList allFrameworkPaths;
|
||||||
QList<ProjectExplorer::HeaderPath> allHeaderPaths;
|
QList<ProjectExplorer::HeaderPath> allHeaderPaths;
|
||||||
if (activeBC->toolChain())
|
if (activeBC->toolChain())
|
||||||
@@ -310,7 +314,7 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
|
CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
|
||||||
if (pinfo.includePaths() != allIncludePaths
|
if (pinfo.includePaths() != allIncludePaths
|
||||||
|| pinfo.sourceFiles() != m_files
|
|| pinfo.sourceFiles() != m_files
|
||||||
|| pinfo.defines() != (activeBC->toolChain() ? activeBC->toolChain()->predefinedMacros(QStringList()) : QByteArray())
|
|| pinfo.defines() != allDefines
|
||||||
|| pinfo.frameworkPaths() != allFrameworkPaths) {
|
|| pinfo.frameworkPaths() != allFrameworkPaths) {
|
||||||
pinfo.clearProjectParts();
|
pinfo.clearProjectParts();
|
||||||
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
|
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
|
||||||
@@ -318,7 +322,7 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
part->includePaths = allIncludePaths;
|
part->includePaths = allIncludePaths;
|
||||||
// TODO we only want C++ files, not all other stuff that might be in the project
|
// TODO we only want C++ files, not all other stuff that might be in the project
|
||||||
part->sourceFiles = m_files;
|
part->sourceFiles = m_files;
|
||||||
part->defines = (activeBC->toolChain() ? activeBC->toolChain()->predefinedMacros(QStringList()) : QByteArray()); // TODO this is to simplistic
|
part->defines = allDefines;
|
||||||
part->frameworkPaths = allFrameworkPaths;
|
part->frameworkPaths = allFrameworkPaths;
|
||||||
part->language = CPlusPlus::CppModelManagerInterface::CXX;
|
part->language = CPlusPlus::CppModelManagerInterface::CXX;
|
||||||
pinfo.appendProjectPart(part);
|
pinfo.appendProjectPart(part);
|
||||||
@@ -1085,7 +1089,31 @@ void CMakeCbpParser::parseCompiler()
|
|||||||
|
|
||||||
void CMakeCbpParser::parseAdd()
|
void CMakeCbpParser::parseAdd()
|
||||||
{
|
{
|
||||||
m_includeFiles.append(attributes().value("directory").toString());
|
// CMake only supports <Add option=\> and <Add directory=\>
|
||||||
|
const QXmlStreamAttributes addAttributes = attributes();
|
||||||
|
|
||||||
|
const QString includeDirectory = addAttributes.value("directory").toString();
|
||||||
|
// allow adding multiple times because order happens
|
||||||
|
if (!includeDirectory.isEmpty()) {
|
||||||
|
m_includeFiles.append(includeDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString compilerOption = addAttributes.value("option").toString();
|
||||||
|
// defining multiple times a macro to the same value makes no sense
|
||||||
|
if (!compilerOption.isEmpty() && !m_compilerOptions.contains(compilerOption)) {
|
||||||
|
m_compilerOptions.append(compilerOption);
|
||||||
|
int macroNameIndex = compilerOption.indexOf("-D") + 2;
|
||||||
|
if (macroNameIndex != 1) {
|
||||||
|
int assignIndex = compilerOption.indexOf('=', macroNameIndex);
|
||||||
|
if (assignIndex != -1) {
|
||||||
|
compilerOption[assignIndex] = ' ';
|
||||||
|
}
|
||||||
|
m_defines.append("#define ");
|
||||||
|
m_defines.append(compilerOption.mid(macroNameIndex).toAscii());
|
||||||
|
m_defines.append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement()) {
|
if (isEndElement()) {
|
||||||
@@ -1183,6 +1211,11 @@ QStringList CMakeCbpParser::includeFiles()
|
|||||||
return m_includeFiles;
|
return m_includeFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray CMakeCbpParser::defines() const
|
||||||
|
{
|
||||||
|
return m_defines;
|
||||||
|
}
|
||||||
|
|
||||||
QList<CMakeBuildTarget> CMakeCbpParser::buildTargets()
|
QList<CMakeBuildTarget> CMakeCbpParser::buildTargets()
|
||||||
{
|
{
|
||||||
return m_buildTargets;
|
return m_buildTargets;
|
||||||
|
@@ -162,9 +162,11 @@ public:
|
|||||||
QList<ProjectExplorer::FileNode *> cmakeFileList();
|
QList<ProjectExplorer::FileNode *> cmakeFileList();
|
||||||
QStringList includeFiles();
|
QStringList includeFiles();
|
||||||
QList<CMakeBuildTarget> buildTargets();
|
QList<CMakeBuildTarget> buildTargets();
|
||||||
|
QByteArray defines() const;
|
||||||
QString projectName() const;
|
QString projectName() const;
|
||||||
QString compilerName() const;
|
QString compilerName() const;
|
||||||
bool hasCMakeFiles();
|
bool hasCMakeFiles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseCodeBlocks_project_file();
|
void parseCodeBlocks_project_file();
|
||||||
void parseProject();
|
void parseProject();
|
||||||
@@ -186,6 +188,8 @@ private:
|
|||||||
QSet<QString> m_processedUnits;
|
QSet<QString> m_processedUnits;
|
||||||
bool m_parsingCmakeUnit;
|
bool m_parsingCmakeUnit;
|
||||||
QStringList m_includeFiles;
|
QStringList m_includeFiles;
|
||||||
|
QStringList m_compilerOptions;
|
||||||
|
QByteArray m_defines;
|
||||||
|
|
||||||
CMakeBuildTarget m_buildTarget;
|
CMakeBuildTarget m_buildTarget;
|
||||||
bool m_buildTargetType;
|
bool m_buildTargetType;
|
||||||
|
Reference in New Issue
Block a user