forked from qt-creator/qt-creator
CMake: Cleanup CMakeCbpParser
Change-Id: I7fa193297e02ae8e3c5de88583f39409aeecf01f Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -48,10 +48,10 @@ namespace {
|
|||||||
int distance(const QString &targetDirectory, const FileName &fileName)
|
int distance(const QString &targetDirectory, const FileName &fileName)
|
||||||
{
|
{
|
||||||
const QString commonParent = commonPath(QStringList() << targetDirectory << fileName.toString());
|
const QString commonParent = commonPath(QStringList() << targetDirectory << fileName.toString());
|
||||||
return targetDirectory.mid(commonParent.size()).count(QLatin1Char('/'))
|
return targetDirectory.mid(commonParent.size()).count('/')
|
||||||
+ fileName.toString().mid(commonParent.size()).count(QLatin1Char('/'));
|
+ fileName.toString().mid(commonParent.size()).count('/');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
// called after everything is parsed
|
// called after everything is parsed
|
||||||
// this function tries to figure out to which CMakeBuildTarget
|
// this function tries to figure out to which CMakeBuildTarget
|
||||||
@@ -64,7 +64,6 @@ void CMakeCbpParser::sortFiles()
|
|||||||
|
|
||||||
sort(fileNames);
|
sort(fileNames);
|
||||||
|
|
||||||
|
|
||||||
CMakeBuildTarget *last = 0;
|
CMakeBuildTarget *last = 0;
|
||||||
FileName parentDirectory;
|
FileName parentDirectory;
|
||||||
|
|
||||||
@@ -170,7 +169,7 @@ bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const QString &f
|
|||||||
|
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (name() == QLatin1String("CodeBlocks_project_file"))
|
if (name() == "CodeBlocks_project_file")
|
||||||
parseCodeBlocks_project_file();
|
parseCodeBlocks_project_file();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -182,7 +181,7 @@ bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const QString &f
|
|||||||
|
|
||||||
// There is always a clean target:
|
// There is always a clean target:
|
||||||
CMakeBuildTarget cleanTarget;
|
CMakeBuildTarget cleanTarget;
|
||||||
cleanTarget.title = QLatin1String("clean");
|
cleanTarget.title = "clean";
|
||||||
cleanTarget.targetType = UtilityType;
|
cleanTarget.targetType = UtilityType;
|
||||||
cleanTarget.workingDirectory = m_buildDirectory;
|
cleanTarget.workingDirectory = m_buildDirectory;
|
||||||
cleanTarget.sourceDirectory = m_sourceDirectory;
|
cleanTarget.sourceDirectory = m_sourceDirectory;
|
||||||
@@ -200,7 +199,7 @@ void CMakeCbpParser::parseCodeBlocks_project_file()
|
|||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
return;
|
return;
|
||||||
else if (name() == QLatin1String("Project"))
|
else if (name() == "Project")
|
||||||
parseProject();
|
parseProject();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -213,11 +212,11 @@ void CMakeCbpParser::parseProject()
|
|||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
return;
|
return;
|
||||||
else if (name() == QLatin1String("Option"))
|
else if (name() == "Option")
|
||||||
parseOption();
|
parseOption();
|
||||||
else if (name() == QLatin1String("Unit"))
|
else if (name() == "Unit")
|
||||||
parseUnit();
|
parseUnit();
|
||||||
else if (name() == QLatin1String("Build"))
|
else if (name() == "Build")
|
||||||
parseBuild();
|
parseBuild();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -230,7 +229,7 @@ void CMakeCbpParser::parseBuild()
|
|||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
return;
|
return;
|
||||||
else if (name() == QLatin1String("Target"))
|
else if (name() == "Target")
|
||||||
parseBuildTarget();
|
parseBuildTarget();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -241,23 +240,23 @@ void CMakeCbpParser::parseBuildTarget()
|
|||||||
{
|
{
|
||||||
m_buildTarget.clear();
|
m_buildTarget.clear();
|
||||||
|
|
||||||
if (attributes().hasAttribute(QLatin1String("title")))
|
if (attributes().hasAttribute("title"))
|
||||||
m_buildTarget.title = attributes().value(QLatin1String("title")).toString();
|
m_buildTarget.title = attributes().value("title").toString();
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement()) {
|
if (isEndElement()) {
|
||||||
if (!m_buildTarget.title.endsWith(QLatin1String("/fast"))
|
if (!m_buildTarget.title.endsWith("/fast")
|
||||||
&& !m_buildTarget.title.endsWith(QLatin1String("_automoc"))) {
|
&& !m_buildTarget.title.endsWith("_automoc")) {
|
||||||
if (m_buildTarget.executable.isEmpty() && m_buildTarget.targetType == ExecutableType)
|
if (m_buildTarget.executable.isEmpty() && m_buildTarget.targetType == ExecutableType)
|
||||||
m_buildTarget.targetType = UtilityType;
|
m_buildTarget.targetType = UtilityType;
|
||||||
m_buildTargets.append(m_buildTarget);
|
m_buildTargets.append(m_buildTarget);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (name() == QLatin1String("Compiler")) {
|
} else if (name() == "Compiler") {
|
||||||
parseCompiler();
|
parseCompiler();
|
||||||
} else if (name() == QLatin1String("Option")) {
|
} else if (name() == "Option") {
|
||||||
parseBuildTargetOption();
|
parseBuildTargetOption();
|
||||||
} else if (name() == QLatin1String("MakeCommands")) {
|
} else if (name() == "MakeCommands") {
|
||||||
parseMakeCommands();
|
parseMakeCommands();
|
||||||
} else if (isStartElement()) {
|
} else if (isStartElement()) {
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -267,10 +266,10 @@ void CMakeCbpParser::parseBuildTarget()
|
|||||||
|
|
||||||
void CMakeCbpParser::parseBuildTargetOption()
|
void CMakeCbpParser::parseBuildTargetOption()
|
||||||
{
|
{
|
||||||
if (attributes().hasAttribute(QLatin1String("output"))) {
|
if (attributes().hasAttribute("output")) {
|
||||||
m_buildTarget.executable = m_pathMapper(attributes().value(QLatin1String("output")).toString());
|
m_buildTarget.executable = m_pathMapper(attributes().value("output").toString());
|
||||||
} else if (attributes().hasAttribute(QLatin1String("type"))) {
|
} else if (attributes().hasAttribute("type")) {
|
||||||
const QStringRef value = attributes().value(QLatin1String("type"));
|
const QStringRef value = attributes().value("type");
|
||||||
if (value == "0" || value == "1")
|
if (value == "0" || value == "1")
|
||||||
m_buildTarget.targetType = ExecutableType;
|
m_buildTarget.targetType = ExecutableType;
|
||||||
else if (value == "2")
|
else if (value == "2")
|
||||||
@@ -279,8 +278,8 @@ void CMakeCbpParser::parseBuildTargetOption()
|
|||||||
m_buildTarget.targetType = DynamicLibraryType;
|
m_buildTarget.targetType = DynamicLibraryType;
|
||||||
else
|
else
|
||||||
m_buildTarget.targetType = UtilityType;
|
m_buildTarget.targetType = UtilityType;
|
||||||
} else if (attributes().hasAttribute(QLatin1String("working_dir"))) {
|
} else if (attributes().hasAttribute("working_dir")) {
|
||||||
m_buildTarget.workingDirectory = attributes().value(QLatin1String("working_dir")).toString();
|
m_buildTarget.workingDirectory = attributes().value("working_dir").toString();
|
||||||
|
|
||||||
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
|
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
|
||||||
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
|
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
|
||||||
@@ -320,11 +319,11 @@ QString CMakeCbpParser::projectName() const
|
|||||||
|
|
||||||
void CMakeCbpParser::parseOption()
|
void CMakeCbpParser::parseOption()
|
||||||
{
|
{
|
||||||
if (attributes().hasAttribute(QLatin1String("title")))
|
if (attributes().hasAttribute("title"))
|
||||||
m_projectName = attributes().value(QLatin1String("title")).toString();
|
m_projectName = attributes().value("title").toString();
|
||||||
|
|
||||||
if (attributes().hasAttribute(QLatin1String("compiler")))
|
if (attributes().hasAttribute("compiler"))
|
||||||
m_compiler = attributes().value(QLatin1String("compiler")).toString();
|
m_compiler = attributes().value("compiler").toString();
|
||||||
|
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
@@ -341,9 +340,9 @@ void CMakeCbpParser::parseMakeCommands()
|
|||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
return;
|
return;
|
||||||
else if (name() == QLatin1String("Build"))
|
else if (name() == "Build")
|
||||||
parseBuildTargetBuild();
|
parseBuildTargetBuild();
|
||||||
else if (name() == QLatin1String("Clean"))
|
else if (name() == "Clean")
|
||||||
parseBuildTargetClean();
|
parseBuildTargetClean();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -352,8 +351,8 @@ void CMakeCbpParser::parseMakeCommands()
|
|||||||
|
|
||||||
void CMakeCbpParser::parseBuildTargetBuild()
|
void CMakeCbpParser::parseBuildTargetBuild()
|
||||||
{
|
{
|
||||||
if (attributes().hasAttribute(QLatin1String("command")))
|
if (attributes().hasAttribute("command"))
|
||||||
m_buildTarget.makeCommand = m_pathMapper(attributes().value(QLatin1String("command")).toString());
|
m_buildTarget.makeCommand = m_pathMapper(attributes().value("command").toString());
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
@@ -380,7 +379,7 @@ void CMakeCbpParser::parseCompiler()
|
|||||||
readNext();
|
readNext();
|
||||||
if (isEndElement())
|
if (isEndElement())
|
||||||
return;
|
return;
|
||||||
else if (name() == QLatin1String("Add"))
|
else if (name() == "Add")
|
||||||
parseAdd();
|
parseAdd();
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -392,19 +391,19 @@ void CMakeCbpParser::parseAdd()
|
|||||||
// CMake only supports <Add option=\> and <Add directory=\>
|
// CMake only supports <Add option=\> and <Add directory=\>
|
||||||
const QXmlStreamAttributes addAttributes = attributes();
|
const QXmlStreamAttributes addAttributes = attributes();
|
||||||
|
|
||||||
QString includeDirectory = m_pathMapper(addAttributes.value(QLatin1String("directory")).toString());
|
QString includeDirectory = m_pathMapper(addAttributes.value("directory").toString());
|
||||||
|
|
||||||
// allow adding multiple times because order happens
|
// allow adding multiple times because order happens
|
||||||
if (!includeDirectory.isEmpty())
|
if (!includeDirectory.isEmpty())
|
||||||
m_buildTarget.includeFiles.append(includeDirectory);
|
m_buildTarget.includeFiles.append(includeDirectory);
|
||||||
|
|
||||||
QString compilerOption = addAttributes.value(QLatin1String("option")).toString();
|
QString compilerOption = addAttributes.value("option").toString();
|
||||||
// defining multiple times a macro to the same value makes no sense
|
// defining multiple times a macro to the same value makes no sense
|
||||||
if (!compilerOption.isEmpty() && !m_buildTarget.compilerOptions.contains(compilerOption)) {
|
if (!compilerOption.isEmpty() && !m_buildTarget.compilerOptions.contains(compilerOption)) {
|
||||||
m_buildTarget.compilerOptions.append(compilerOption);
|
m_buildTarget.compilerOptions.append(compilerOption);
|
||||||
int macroNameIndex = compilerOption.indexOf(QLatin1String("-D")) + 2;
|
int macroNameIndex = compilerOption.indexOf("-D") + 2;
|
||||||
if (macroNameIndex != 1) {
|
if (macroNameIndex != 1) {
|
||||||
int assignIndex = compilerOption.indexOf(QLatin1Char('='), macroNameIndex);
|
int assignIndex = compilerOption.indexOf('=', macroNameIndex);
|
||||||
if (assignIndex != -1)
|
if (assignIndex != -1)
|
||||||
compilerOption[assignIndex] = ' ';
|
compilerOption[assignIndex] = ' ';
|
||||||
m_buildTarget.defines.append("#define ");
|
m_buildTarget.defines.append("#define ");
|
||||||
@@ -424,30 +423,28 @@ void CMakeCbpParser::parseAdd()
|
|||||||
|
|
||||||
void CMakeCbpParser::parseUnit()
|
void CMakeCbpParser::parseUnit()
|
||||||
{
|
{
|
||||||
//qDebug()<<stream.attributes().value("filename");
|
|
||||||
FileName fileName =
|
FileName fileName =
|
||||||
FileName::fromString(m_pathMapper(FileName::fromUserInput(
|
FileName::fromString(m_pathMapper(FileName::fromUserInput(attributes().value("filename")
|
||||||
attributes().value(QLatin1String("filename"))
|
.toString()).toString()));
|
||||||
.toString()).toString()));
|
|
||||||
|
|
||||||
m_parsingCMakeUnit = false;
|
m_parsingCMakeUnit = false;
|
||||||
m_unitTargets.clear();
|
m_unitTargets.clear();
|
||||||
while (!atEnd()) {
|
while (!atEnd()) {
|
||||||
readNext();
|
readNext();
|
||||||
if (isEndElement()) {
|
if (isEndElement()) {
|
||||||
if (!fileName.endsWith(QLatin1String(".rule")) && !m_processedUnits.contains(fileName)) {
|
if (!fileName.endsWith(".rule") && !m_processedUnits.contains(fileName)) {
|
||||||
// Now check whether we found a virtual element beneath
|
// Now check whether we found a virtual element beneath
|
||||||
if (m_parsingCMakeUnit) {
|
if (m_parsingCMakeUnit) {
|
||||||
m_cmakeFileList.append( new FileNode(fileName, ProjectFileType, false));
|
m_cmakeFileList.append( new FileNode(fileName, ProjectFileType, false));
|
||||||
} else {
|
} else {
|
||||||
bool generated = false;
|
bool generated = false;
|
||||||
QString onlyFileName = fileName.fileName();
|
QString onlyFileName = fileName.fileName();
|
||||||
if ( (onlyFileName.startsWith(QLatin1String("moc_")) && onlyFileName.endsWith(QLatin1String(".cxx")))
|
if ( (onlyFileName.startsWith("moc_") && onlyFileName.endsWith(".cxx"))
|
||||||
|| (onlyFileName.startsWith(QLatin1String("ui_")) && onlyFileName.endsWith(QLatin1String(".h")))
|
|| (onlyFileName.startsWith("ui_") && onlyFileName.endsWith(".h"))
|
||||||
|| (onlyFileName.startsWith(QLatin1String("qrc_")) && onlyFileName.endsWith(QLatin1String(".cxx"))))
|
|| (onlyFileName.startsWith("qrc_") && onlyFileName.endsWith(".cxx")))
|
||||||
generated = true;
|
generated = true;
|
||||||
|
|
||||||
if (fileName.endsWith(QLatin1String(".qrc")))
|
if (fileName.endsWith(".qrc"))
|
||||||
m_fileList.append( new FileNode(fileName, ResourceType, generated));
|
m_fileList.append( new FileNode(fileName, ResourceType, generated));
|
||||||
else
|
else
|
||||||
m_fileList.append( new FileNode(fileName, SourceType, generated));
|
m_fileList.append( new FileNode(fileName, SourceType, generated));
|
||||||
@@ -456,7 +453,7 @@ void CMakeCbpParser::parseUnit()
|
|||||||
m_processedUnits.insert(fileName);
|
m_processedUnits.insert(fileName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (name() == QLatin1String("Option")) {
|
} else if (name() == "Option") {
|
||||||
parseUnitOption();
|
parseUnitOption();
|
||||||
} else if (isStartElement()) {
|
} else if (isStartElement()) {
|
||||||
parseUnknownElement();
|
parseUnknownElement();
|
||||||
@@ -467,8 +464,8 @@ void CMakeCbpParser::parseUnit()
|
|||||||
void CMakeCbpParser::parseUnitOption()
|
void CMakeCbpParser::parseUnitOption()
|
||||||
{
|
{
|
||||||
const QXmlStreamAttributes optionAttributes = attributes();
|
const QXmlStreamAttributes optionAttributes = attributes();
|
||||||
m_parsingCMakeUnit = optionAttributes.hasAttribute(QLatin1String("virtualFolder"));
|
m_parsingCMakeUnit = optionAttributes.hasAttribute("virtualFolder");
|
||||||
const QString target = optionAttributes.value(QLatin1String("target")).toString();
|
const QString target = optionAttributes.value("target").toString();
|
||||||
if (!target.isEmpty())
|
if (!target.isEmpty())
|
||||||
m_unitTargets.append(target);
|
m_unitTargets.append(target);
|
||||||
|
|
||||||
@@ -523,6 +520,5 @@ QString CMakeCbpParser::compilerName() const
|
|||||||
return m_compiler;
|
return m_compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CMakeProjectManager
|
} // namespace CMakeProjectManager
|
||||||
|
|||||||
Reference in New Issue
Block a user