2015-03-10 10:22:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-03-10 10:22:38 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-03-10 10:22:38 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-03-10 10:22:38 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cmakecbpparser.h"
|
2015-03-10 15:47:09 +01:00
|
|
|
#include "cmakekitinformation.h"
|
|
|
|
|
#include "cmaketool.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
// CMakeCbpParser
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
namespace {
|
2016-10-13 12:02:52 +02:00
|
|
|
int distance(const FileName &targetDirectory, const FileName &fileName)
|
2015-03-10 10:22:38 +01:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
const QString commonParent = commonPath(QStringList({targetDirectory.toString(), fileName.toString()}));
|
2016-10-13 12:02:52 +02:00
|
|
|
return targetDirectory.toString().mid(commonParent.size()).count('/')
|
2016-10-17 13:12:02 +02:00
|
|
|
+ fileName.toString().mid(commonParent.size()).count('/');
|
2015-03-10 10:22:38 +01:00
|
|
|
}
|
2016-10-17 13:12:02 +02:00
|
|
|
} // namespace
|
2015-03-10 10:22:38 +01:00
|
|
|
|
|
|
|
|
// called after everything is parsed
|
|
|
|
|
// this function tries to figure out to which CMakeBuildTarget
|
|
|
|
|
// each file belongs, so that it gets the appropriate defines and
|
|
|
|
|
// compiler flags
|
|
|
|
|
void CMakeCbpParser::sortFiles()
|
|
|
|
|
{
|
|
|
|
|
QLoggingCategory log("qtc.cmakeprojectmanager.filetargetmapping");
|
2016-10-13 11:36:00 +02:00
|
|
|
FileNameList fileNames = transform(m_fileList, &FileNode::filePath);
|
2015-03-10 10:22:38 +01:00
|
|
|
|
2016-10-13 11:36:00 +02:00
|
|
|
sort(fileNames);
|
2015-03-10 10:22:38 +01:00
|
|
|
|
|
|
|
|
CMakeBuildTarget *last = 0;
|
|
|
|
|
FileName parentDirectory;
|
|
|
|
|
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
qCDebug(log) << "# Pre Dump #";
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
foreach (const CMakeBuildTarget &target, m_buildTargets)
|
|
|
|
|
qCDebug(log) << target.title << target.sourceDirectory <<
|
|
|
|
|
target.includeFiles << target.defines << target.files << "\n";
|
|
|
|
|
|
|
|
|
|
// find a good build target to fall back
|
|
|
|
|
int fallbackIndex = 0;
|
|
|
|
|
{
|
|
|
|
|
int bestIncludeCount = -1;
|
|
|
|
|
for (int i = 0; i < m_buildTargets.size(); ++i) {
|
|
|
|
|
const CMakeBuildTarget &target = m_buildTargets.at(i);
|
|
|
|
|
if (target.includeFiles.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
if (target.sourceDirectory == m_sourceDirectory
|
|
|
|
|
&& target.includeFiles.count() > bestIncludeCount) {
|
|
|
|
|
bestIncludeCount = target.includeFiles.count();
|
|
|
|
|
fallbackIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
qCDebug(log) << "# Sorting #";
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
|
|
|
|
|
foreach (const FileName &fileName, fileNames) {
|
|
|
|
|
qCDebug(log) << fileName;
|
2016-08-17 12:45:53 +02:00
|
|
|
const QStringList unitTargets = m_unitTargetMap[fileName];
|
|
|
|
|
if (!unitTargets.isEmpty()) {
|
|
|
|
|
// cmake >= 3.3:
|
|
|
|
|
foreach (const QString &unitTarget, unitTargets) {
|
2016-10-13 11:36:00 +02:00
|
|
|
int index = indexOf(m_buildTargets, equal(&CMakeBuildTarget::title, unitTarget));
|
2016-08-17 12:45:53 +02:00
|
|
|
if (index != -1) {
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildTargets[index].files.append(fileName);
|
2016-08-17 12:45:53 +02:00
|
|
|
qCDebug(log) << " into" << m_buildTargets[index].title << "(target attribute)";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-04-21 12:42:17 -07:00
|
|
|
}
|
2016-08-17 12:45:53 +02:00
|
|
|
continue;
|
2015-04-21 12:42:17 -07:00
|
|
|
}
|
2016-08-17 12:45:53 +02:00
|
|
|
|
|
|
|
|
// fallback for cmake < 3.3:
|
2015-03-10 10:22:38 +01:00
|
|
|
if (fileName.parentDir() == parentDirectory && last) {
|
|
|
|
|
// easy case, same parent directory as last file
|
2016-10-13 12:02:52 +02:00
|
|
|
last->files.append(fileName);
|
2015-04-21 12:42:17 -07:00
|
|
|
qCDebug(log) << " into" << last->title << "(same parent)";
|
2015-03-10 10:22:38 +01:00
|
|
|
} else {
|
|
|
|
|
int bestDistance = std::numeric_limits<int>::max();
|
|
|
|
|
int bestIndex = -1;
|
|
|
|
|
int bestIncludeCount = -1;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_buildTargets.size(); ++i) {
|
|
|
|
|
const CMakeBuildTarget &target = m_buildTargets.at(i);
|
|
|
|
|
if (target.includeFiles.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
int dist = distance(target.sourceDirectory, fileName);
|
|
|
|
|
qCDebug(log) << "distance to target" << target.title << dist;
|
|
|
|
|
if (dist < bestDistance ||
|
|
|
|
|
(dist == bestDistance &&
|
|
|
|
|
target.includeFiles.count() > bestIncludeCount)) {
|
|
|
|
|
bestDistance = dist;
|
|
|
|
|
bestIncludeCount = target.includeFiles.count();
|
|
|
|
|
bestIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bestIndex == -1 && !m_buildTargets.isEmpty()) {
|
|
|
|
|
bestIndex = fallbackIndex;
|
|
|
|
|
qCDebug(log) << " using fallbackIndex";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bestIndex != -1) {
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildTargets[bestIndex].files.append(fileName);
|
2015-03-10 10:22:38 +01:00
|
|
|
last = &m_buildTargets[bestIndex];
|
|
|
|
|
parentDirectory = fileName.parentDir();
|
|
|
|
|
qCDebug(log) << " into" << last->title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
qCDebug(log) << "# After Dump #";
|
|
|
|
|
qCDebug(log) << "###############";
|
|
|
|
|
foreach (const CMakeBuildTarget &target, m_buildTargets)
|
|
|
|
|
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const FileName &fileName,
|
|
|
|
|
const FileName &sourceDirectory)
|
2015-03-10 10:22:38 +01:00
|
|
|
{
|
2016-10-13 12:02:52 +02:00
|
|
|
|
2016-10-13 11:36:00 +02:00
|
|
|
m_pathMapper = mapper;
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildDirectory = FileName::fromString(fileName.toFileInfo().absolutePath());
|
2015-03-10 10:22:38 +01:00
|
|
|
m_sourceDirectory = sourceDirectory;
|
|
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
QFile fi(fileName.toString());
|
2015-03-10 10:22:38 +01:00
|
|
|
if (fi.exists() && fi.open(QFile::ReadOnly)) {
|
|
|
|
|
setDevice(&fi);
|
|
|
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
2016-10-17 13:12:02 +02:00
|
|
|
if (name() == "CodeBlocks_project_file")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseCodeBlocks_project_file();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortFiles();
|
|
|
|
|
|
|
|
|
|
fi.close();
|
2016-01-07 11:47:56 +01:00
|
|
|
|
2015-03-10 10:22:38 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseCodeBlocks_project_file()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Project")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseProject();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseProject()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Option")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseOption();
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Unit")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseUnit();
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Build")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseBuild();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuild()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Target")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseBuildTarget();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuildTarget()
|
|
|
|
|
{
|
|
|
|
|
m_buildTarget.clear();
|
|
|
|
|
|
2016-10-17 13:12:02 +02:00
|
|
|
if (attributes().hasAttribute("title"))
|
|
|
|
|
m_buildTarget.title = attributes().value("title").toString();
|
2015-03-10 10:22:38 +01:00
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement()) {
|
2016-10-17 13:12:02 +02:00
|
|
|
if (!m_buildTarget.title.endsWith("/fast")
|
|
|
|
|
&& !m_buildTarget.title.endsWith("_automoc")) {
|
2016-08-17 11:13:39 +02:00
|
|
|
if (m_buildTarget.executable.isEmpty() && m_buildTarget.targetType == ExecutableType)
|
|
|
|
|
m_buildTarget.targetType = UtilityType;
|
2015-03-10 10:22:38 +01:00
|
|
|
m_buildTargets.append(m_buildTarget);
|
2016-08-17 11:13:39 +02:00
|
|
|
}
|
2015-03-10 10:22:38 +01:00
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (name() == "Compiler") {
|
2015-03-10 10:22:38 +01:00
|
|
|
parseCompiler();
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (name() == "Option") {
|
2015-03-10 10:22:38 +01:00
|
|
|
parseBuildTargetOption();
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (name() == "MakeCommands") {
|
2015-03-10 10:22:38 +01:00
|
|
|
parseMakeCommands();
|
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuildTargetOption()
|
|
|
|
|
{
|
2016-10-17 13:12:02 +02:00
|
|
|
if (attributes().hasAttribute("output")) {
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildTarget.executable = m_pathMapper(FileName::fromString(attributes().value("output").toString()));
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (attributes().hasAttribute("type")) {
|
|
|
|
|
const QStringRef value = attributes().value("type");
|
2016-08-17 11:13:39 +02:00
|
|
|
if (value == "0" || value == "1")
|
|
|
|
|
m_buildTarget.targetType = ExecutableType;
|
|
|
|
|
else if (value == "2")
|
|
|
|
|
m_buildTarget.targetType = StaticLibraryType;
|
|
|
|
|
else if (value == "3")
|
|
|
|
|
m_buildTarget.targetType = DynamicLibraryType;
|
|
|
|
|
else
|
|
|
|
|
m_buildTarget.targetType = UtilityType;
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (attributes().hasAttribute("working_dir")) {
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildTarget.workingDirectory = FileName::fromUserInput(attributes().value("working_dir").toString());
|
2015-10-25 14:23:00 +01:00
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory.toString()
|
2015-10-25 14:23:00 +01:00
|
|
|
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
|
|
|
|
|
if (cmakeSourceInfoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
QTextStream stream(&cmakeSourceInfoFile);
|
|
|
|
|
const QLatin1String searchSource("SET(CMAKE_RELATIVE_PATH_TOP_SOURCE \"");
|
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
const QString lineTopSource = stream.readLine().trimmed();
|
2016-03-07 09:35:28 +01:00
|
|
|
if (lineTopSource.startsWith(searchSource, Qt::CaseInsensitive)) {
|
2016-10-13 12:02:52 +02:00
|
|
|
QString src = lineTopSource.mid(searchSource.size());
|
|
|
|
|
src.chop(2);
|
|
|
|
|
m_buildTarget.sourceDirectory = FileName::fromString(src);
|
2015-10-25 14:23:00 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_buildTarget.sourceDirectory.isEmpty()) {
|
2016-10-13 12:02:52 +02:00
|
|
|
QDir dir(m_buildDirectory.toString());
|
|
|
|
|
const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory.toString());
|
|
|
|
|
m_buildTarget.sourceDirectory = m_sourceDirectory;
|
|
|
|
|
m_buildTarget.sourceDirectory.appendPath(relative).toString();
|
2015-10-25 14:23:00 +01:00
|
|
|
}
|
2015-03-10 10:22:38 +01:00
|
|
|
}
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeCbpParser::projectName() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseOption()
|
|
|
|
|
{
|
2016-10-17 13:12:02 +02:00
|
|
|
if (attributes().hasAttribute("title"))
|
|
|
|
|
m_projectName = attributes().value("title").toString();
|
2015-03-10 10:22:38 +01:00
|
|
|
|
2016-10-17 13:12:02 +02:00
|
|
|
if (attributes().hasAttribute("compiler"))
|
|
|
|
|
m_compiler = attributes().value("compiler").toString();
|
2015-03-10 10:22:38 +01:00
|
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseMakeCommands()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Build")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseBuildTargetBuild();
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Clean")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseBuildTargetClean();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuildTargetBuild()
|
|
|
|
|
{
|
2016-10-17 13:12:02 +02:00
|
|
|
if (attributes().hasAttribute("command"))
|
2016-10-13 12:02:52 +02:00
|
|
|
m_buildTarget.makeCommand = m_pathMapper(FileName::fromUserInput(attributes().value("command").toString()));
|
2015-03-10 10:22:38 +01:00
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuildTargetClean()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseCompiler()
|
|
|
|
|
{
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
else if (name() == "Add")
|
2015-03-10 10:22:38 +01:00
|
|
|
parseAdd();
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseAdd()
|
|
|
|
|
{
|
|
|
|
|
// CMake only supports <Add option=\> and <Add directory=\>
|
|
|
|
|
const QXmlStreamAttributes addAttributes = attributes();
|
|
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
FileName includeDirectory
|
|
|
|
|
= m_pathMapper(FileName::fromString(addAttributes.value("directory").toString()));
|
2015-03-10 15:47:09 +01:00
|
|
|
|
2015-03-10 10:22:38 +01:00
|
|
|
// allow adding multiple times because order happens
|
|
|
|
|
if (!includeDirectory.isEmpty())
|
|
|
|
|
m_buildTarget.includeFiles.append(includeDirectory);
|
|
|
|
|
|
2016-10-17 13:12:02 +02:00
|
|
|
QString compilerOption = addAttributes.value("option").toString();
|
2015-03-10 10:22:38 +01:00
|
|
|
// defining multiple times a macro to the same value makes no sense
|
|
|
|
|
if (!compilerOption.isEmpty() && !m_buildTarget.compilerOptions.contains(compilerOption)) {
|
|
|
|
|
m_buildTarget.compilerOptions.append(compilerOption);
|
2016-10-17 13:12:02 +02:00
|
|
|
int macroNameIndex = compilerOption.indexOf("-D") + 2;
|
2015-03-10 10:22:38 +01:00
|
|
|
if (macroNameIndex != 1) {
|
2016-10-17 13:12:02 +02:00
|
|
|
int assignIndex = compilerOption.indexOf('=', macroNameIndex);
|
2015-03-10 10:22:38 +01:00
|
|
|
if (assignIndex != -1)
|
|
|
|
|
compilerOption[assignIndex] = ' ';
|
|
|
|
|
m_buildTarget.defines.append("#define ");
|
|
|
|
|
m_buildTarget.defines.append(compilerOption.mid(macroNameIndex).toUtf8());
|
|
|
|
|
m_buildTarget.defines.append('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
return;
|
|
|
|
|
else if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseUnit()
|
|
|
|
|
{
|
|
|
|
|
FileName fileName =
|
2016-10-13 12:02:52 +02:00
|
|
|
m_pathMapper(FileName::fromUserInput(attributes().value("filename").toString()));
|
2015-03-10 15:47:09 +01:00
|
|
|
|
2016-02-12 12:30:55 +01:00
|
|
|
m_parsingCMakeUnit = false;
|
2016-08-17 12:45:53 +02:00
|
|
|
m_unitTargets.clear();
|
2015-03-10 10:22:38 +01:00
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
if (isEndElement()) {
|
2016-10-17 13:12:02 +02:00
|
|
|
if (!fileName.endsWith(".rule") && !m_processedUnits.contains(fileName)) {
|
2015-03-10 10:22:38 +01:00
|
|
|
// Now check whether we found a virtual element beneath
|
2016-02-12 12:30:55 +01:00
|
|
|
if (m_parsingCMakeUnit) {
|
2016-10-31 13:47:42 +01:00
|
|
|
m_cmakeFileList.append( new FileNode(fileName, FileType::Project, false));
|
2015-03-10 10:22:38 +01:00
|
|
|
} else {
|
|
|
|
|
bool generated = false;
|
|
|
|
|
QString onlyFileName = fileName.fileName();
|
2016-10-17 13:12:02 +02:00
|
|
|
if ( (onlyFileName.startsWith("moc_") && onlyFileName.endsWith(".cxx"))
|
|
|
|
|
|| (onlyFileName.startsWith("ui_") && onlyFileName.endsWith(".h"))
|
|
|
|
|
|| (onlyFileName.startsWith("qrc_") && onlyFileName.endsWith(".cxx")))
|
2015-03-10 10:22:38 +01:00
|
|
|
generated = true;
|
|
|
|
|
|
2016-10-17 13:12:02 +02:00
|
|
|
if (fileName.endsWith(".qrc"))
|
2016-10-31 13:47:42 +01:00
|
|
|
m_fileList.append( new FileNode(fileName, FileType::Resource, generated));
|
2015-03-10 10:22:38 +01:00
|
|
|
else
|
2016-10-31 13:47:42 +01:00
|
|
|
m_fileList.append( new FileNode(fileName, FileType::Source, generated));
|
2015-03-10 10:22:38 +01:00
|
|
|
}
|
2016-08-17 12:45:53 +02:00
|
|
|
m_unitTargetMap.insert(fileName, m_unitTargets);
|
2015-03-10 10:22:38 +01:00
|
|
|
m_processedUnits.insert(fileName);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2016-10-17 13:12:02 +02:00
|
|
|
} else if (name() == "Option") {
|
2015-03-10 10:22:38 +01:00
|
|
|
parseUnitOption();
|
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseUnitOption()
|
|
|
|
|
{
|
2015-04-21 12:42:17 -07:00
|
|
|
const QXmlStreamAttributes optionAttributes = attributes();
|
2016-10-17 13:12:02 +02:00
|
|
|
m_parsingCMakeUnit = optionAttributes.hasAttribute("virtualFolder");
|
|
|
|
|
const QString target = optionAttributes.value("target").toString();
|
2016-08-17 12:45:53 +02:00
|
|
|
if (!target.isEmpty())
|
|
|
|
|
m_unitTargets.append(target);
|
2015-03-10 10:22:38 +01:00
|
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseUnknownElement()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(isStartElement());
|
|
|
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
|
parseUnknownElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 11:36:00 +02:00
|
|
|
QList<FileNode *> CMakeCbpParser::fileList()
|
2015-03-10 10:22:38 +01:00
|
|
|
{
|
|
|
|
|
return m_fileList;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 11:36:00 +02:00
|
|
|
QList<FileNode *> CMakeCbpParser::cmakeFileList()
|
2015-03-10 10:22:38 +01:00
|
|
|
{
|
|
|
|
|
return m_cmakeFileList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeCbpParser::hasCMakeFiles()
|
|
|
|
|
{
|
|
|
|
|
return !m_cmakeFileList.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<CMakeBuildTarget> CMakeCbpParser::buildTargets()
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeCbpParser::compilerName() const
|
|
|
|
|
{
|
|
|
|
|
return m_compiler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|