diff options
author | Jake Petroules <jake.petroules@qt.io> | 2017-05-12 18:50:50 -0700 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-06-13 15:47:18 +0000 |
commit | 8b5e5af31e7c0860f8cf4f8fa50e7b322cadca62 (patch) | |
tree | 36a7e2fc38c7571cdf7e4c6b6449754e39cb993c /src/plugins/generator/visualstudio | |
parent | d5dc7a2571027168d1a74cbb2578848dc843e20e (diff) |
Transform the scanner plugin manager into a true generic plugin manager
...and fit the generator plugins into this new plugin structure.
Plugins are now handled entirely by the build system in a generic manner
and no part of qbscore (code or build files) has a direct reference to
any plugin regardless of whether qbs is being built as shared or static
libraries.
Change-Id: I4a20546ce275df71083ee22c2cb67f781c4de764
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/plugins/generator/visualstudio')
71 files changed, 5988 insertions, 0 deletions
diff --git a/src/plugins/generator/visualstudio/io/msbuildprojectwriter.cpp b/src/plugins/generator/visualstudio/io/msbuildprojectwriter.cpp new file mode 100644 index 000000000..f912f3a19 --- /dev/null +++ b/src/plugins/generator/visualstudio/io/msbuildprojectwriter.cpp @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildprojectwriter.h" + +#include "../msbuild/imsbuildnodevisitor.h" +#include "../msbuild/msbuildimport.h" +#include "../msbuild/msbuildimportgroup.h" +#include "../msbuild/msbuilditem.h" +#include "../msbuild/msbuilditemdefinitiongroup.h" +#include "../msbuild/msbuilditemgroup.h" +#include "../msbuild/msbuilditemmetadata.h" +#include "../msbuild/msbuildproject.h" +#include "../msbuild/msbuildproperty.h" +#include "../msbuild/msbuildpropertygroup.h" + +#include <QtCore/qxmlstream.h> + +namespace qbs { + +static const QString kMSBuildSchemaURI = + QStringLiteral("http://schemas.microsoft.com/developer/msbuild/2003"); + +class MSBuildProjectWriterPrivate : public IMSBuildNodeVisitor +{ +public: + QScopedPointer<QXmlStreamWriter> writer; + + void visitStart(const MSBuildImport *import) override; + void visitEnd(const MSBuildImport *import) override; + + void visitStart(const MSBuildImportGroup *importGroup) override; + void visitEnd(const MSBuildImportGroup *importGroup) override; + + void visitStart(const MSBuildItem *item) override; + void visitEnd(const MSBuildItem *item) override; + + void visitStart(const MSBuildItemDefinitionGroup *itemDefinitionGroup) override; + void visitEnd(const MSBuildItemDefinitionGroup *itemDefinitionGroup) override; + + void visitStart(const MSBuildItemGroup *itemGroup) override; + void visitEnd(const MSBuildItemGroup *itemGroup) override; + + void visitStart(const MSBuildItemMetadata *itemMetadata) override; + void visitEnd(const MSBuildItemMetadata *itemMetadata) override; + + void visitStart(const MSBuildProject *project) override; + void visitEnd(const MSBuildProject *project) override; + + void visitStart(const MSBuildProperty *property) override; + void visitEnd(const MSBuildProperty *property) override; + + void visitStart(const MSBuildPropertyGroup *propertyGroup) override; + void visitEnd(const MSBuildPropertyGroup *propertyGroup) override; +}; + +MSBuildProjectWriter::MSBuildProjectWriter(QIODevice *device) + : d(new MSBuildProjectWriterPrivate) +{ + d->writer.reset(new QXmlStreamWriter(device)); + d->writer->setAutoFormatting(true); +} + +MSBuildProjectWriter::~MSBuildProjectWriter() +{ + delete d; +} + +bool MSBuildProjectWriter::write(const MSBuildProject *project) +{ + d->writer->writeStartDocument(); + project->accept(d); + d->writer->writeEndDocument(); + return !d->writer->hasError(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildImport *import) +{ + writer->writeStartElement(QStringLiteral("Import")); + writer->writeAttribute(QStringLiteral("Project"), import->project()); + if (!import->condition().isEmpty()) + writer->writeAttribute(QStringLiteral("Condition"), import->condition()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildImport *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildImportGroup *importGroup) +{ + writer->writeStartElement(QStringLiteral("ImportGroup")); + if (!importGroup->condition().isEmpty()) + writer->writeAttribute(QStringLiteral("Condition"), importGroup->condition()); + if (!importGroup->label().isEmpty()) + writer->writeAttribute(QStringLiteral("Label"), importGroup->label()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildImportGroup *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildItem *item) +{ + writer->writeStartElement(item->name()); + if (!item->include().isEmpty()) + writer->writeAttribute(QStringLiteral("Include"), item->include()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildItem *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildItemDefinitionGroup *itemDefinitionGroup) +{ + writer->writeStartElement(QStringLiteral("ItemDefinitionGroup")); + if (!itemDefinitionGroup->condition().isEmpty()) + writer->writeAttribute(QStringLiteral("Condition"), itemDefinitionGroup->condition()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildItemDefinitionGroup *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildItemGroup *itemGroup) +{ + writer->writeStartElement(QStringLiteral("ItemGroup")); + if (!itemGroup->condition().isEmpty()) + writer->writeAttribute(QStringLiteral("Condition"), itemGroup->condition()); + if (!itemGroup->label().isEmpty()) + writer->writeAttribute(QStringLiteral("Label"), itemGroup->label()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildItemGroup *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildItemMetadata *itemMetadata) +{ + QString stringValue; + if (itemMetadata->value().type() == QVariant::Bool) { + stringValue = itemMetadata->value().toBool() + ? QStringLiteral("True") + : QStringLiteral("False"); + } else { + stringValue = itemMetadata->value().toString(); + } + writer->writeTextElement(itemMetadata->name(), stringValue); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildItemMetadata *) +{ +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildProject *project) +{ + writer->writeStartElement(QStringLiteral("Project")); + if (!project->defaultTargets().isEmpty()) + writer->writeAttribute(QStringLiteral("DefaultTargets"), project->defaultTargets()); + if (!project->toolsVersion().isEmpty()) + writer->writeAttribute(QStringLiteral("ToolsVersion"), project->toolsVersion()); + writer->writeAttribute(QStringLiteral("xmlns"), kMSBuildSchemaURI); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildProject *) +{ + writer->writeEndElement(); +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildProperty *property) +{ + QString stringValue; + if (property->value().type() == QVariant::Bool) + stringValue = property->value().toBool() ? QStringLiteral("True") : QStringLiteral("False"); + else + stringValue = property->value().toString(); + writer->writeTextElement(property->name(), stringValue); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildProperty *) +{ +} + +void MSBuildProjectWriterPrivate::visitStart(const MSBuildPropertyGroup *propertyGroup) +{ + writer->writeStartElement(QStringLiteral("PropertyGroup")); + if (!propertyGroup->condition().isEmpty()) + writer->writeAttribute(QStringLiteral("Condition"), propertyGroup->condition()); + if (!propertyGroup->label().isEmpty()) + writer->writeAttribute(QStringLiteral("Label"), propertyGroup->label()); +} + +void MSBuildProjectWriterPrivate::visitEnd(const MSBuildPropertyGroup *) +{ + writer->writeEndElement(); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/io/msbuildprojectwriter.h b/src/plugins/generator/visualstudio/io/msbuildprojectwriter.h new file mode 100644 index 000000000..c70889971 --- /dev/null +++ b/src/plugins/generator/visualstudio/io/msbuildprojectwriter.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDPROJECTWRITER_H +#define MSBUILDPROJECTWRITER_H + +#include <QtCore/qiodevice.h> + +namespace qbs { + +class MSBuildProject; +class MSBuildProjectWriterPrivate; + +class MSBuildProjectWriter +{ + Q_DISABLE_COPY(MSBuildProjectWriter) +public: + explicit MSBuildProjectWriter(QIODevice *device); + ~MSBuildProjectWriter(); + + bool write(const MSBuildProject *project); + +private: + MSBuildProjectWriterPrivate *d; +}; + +} // namespace qbs + +#endif // MSBUILDPROJECTWRITER_H diff --git a/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.cpp b/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.cpp new file mode 100644 index 000000000..99180e2e2 --- /dev/null +++ b/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudiosolutionwriter.h" + +#include "../solution/visualstudiosolutionfileproject.h" +#include "../solution/visualstudiosolutionfolderproject.h" +#include "../solution/visualstudiosolutionglobalsection.h" +#include "../solution/visualstudiosolution.h" + +#include <tools/hostosinfo.h> +#include <tools/pathutils.h> +#include <tools/visualstudioversioninfo.h> + +#include <QtCore/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qfileinfo.h> +#include <QtCore/qtextstream.h> +#include <QtCore/quuid.h> + +#include <vector> + +namespace qbs { + +class VisualStudioSolutionWriterPrivate +{ +public: + QIODevice *device; + QString baseDir; +}; + +VisualStudioSolutionWriter::VisualStudioSolutionWriter(QIODevice *device) + : d(new VisualStudioSolutionWriterPrivate) +{ + d->device = device; +} + +VisualStudioSolutionWriter::~VisualStudioSolutionWriter() +{ +} + +QString VisualStudioSolutionWriter::projectBaseDirectory() const +{ + return d->baseDir; +} + +void VisualStudioSolutionWriter::setProjectBaseDirectory(const QString &dir) +{ + d->baseDir = dir; +} + +bool VisualStudioSolutionWriter::write(const VisualStudioSolution *solution) +{ + QTextStream out(d->device); + out << QString(QLatin1String("Microsoft Visual Studio Solution File, " + "Format Version %1\n" + "# Visual Studio %2\n")) + .arg(solution->versionInfo().solutionVersion()) + .arg(solution->versionInfo().version().majorVersion()); + + for (const auto &project : solution->fileProjects()) { + auto projectFilePath = project->filePath(); + + // Try to make the project file path relative to the + // solution file path if we're writing to a file device + if (!d->baseDir.isEmpty()) { + const QDir solutionDir(d->baseDir); + projectFilePath = Internal::PathUtils::toNativeSeparators( + solutionDir.relativeFilePath(projectFilePath), + Internal::HostOsInfo::HostOsWindows); + } + + out << QStringLiteral("Project(\"%1\") = \"%2\", \"%3\", \"%4\"\n") + .arg(project->projectTypeGuid().toString()) + .arg(QFileInfo(projectFilePath).baseName()) + .arg(projectFilePath) + .arg(project->guid().toString()); + + const auto dependencies = solution->dependencies(project); + if (!dependencies.isEmpty()) { + out << "\tProjectSection(ProjectDependencies) = postProject\n"; + + for (const auto &dependency : dependencies) + out << QStringLiteral("\t\t%1 = %1\n").arg(dependency->guid().toString()); + + out << "\tEndProjectSection\n"; + } + + out << "EndProject\n"; + } + + for (const auto &project : solution->folderProjects()) { + out << QStringLiteral("Project(\"%1\") = \"%2\", \"%3\", \"%4\"\n") + .arg(project->projectTypeGuid().toString()) + .arg(project->name()) + .arg(project->name()) + .arg(project->guid().toString()); + out << QStringLiteral("EndProject\n"); + } + + out << "Global\n"; + + for (const auto &globalSection : solution->globalSections()) { + out << QStringLiteral("\tGlobalSection(%1) = %2\n") + .arg(globalSection->name()) + .arg(globalSection->isPost() + ? QStringLiteral("postSolution") + : QStringLiteral("preSolution")); + for (const auto &property : globalSection->properties()) + out << QStringLiteral("\t\t%1 = %2\n").arg(property.first).arg(property.second); + out << "\tEndGlobalSection\n"; + } + + out << "EndGlobal\n"; + + return out.status() == QTextStream::Ok; +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.h b/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.h new file mode 100644 index 000000000..d5b0107f0 --- /dev/null +++ b/src/plugins/generator/visualstudio/io/visualstudiosolutionwriter.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOSOLUTIONWRITER_H +#define VISUALSTUDIOSOLUTIONWRITER_H + +#include <QtCore/qiodevice.h> +#include <QtCore/qscopedpointer.h> + +namespace qbs { + +namespace Internal { class VisualStudioVersionInfo; } + +class VisualStudioSolution; +class VisualStudioSolutionWriterPrivate; + +class VisualStudioSolutionWriter +{ + Q_DISABLE_COPY(VisualStudioSolutionWriter) +public: + explicit VisualStudioSolutionWriter(QIODevice *device); + ~VisualStudioSolutionWriter(); + + QString projectBaseDirectory() const; + void setProjectBaseDirectory(const QString &dir); + + bool write(const VisualStudioSolution *solution); + +private: + void addDefaultGlobalSections(); + + QScopedPointer<VisualStudioSolutionWriterPrivate> d; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOSOLUTIONWRITER_H diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.cpp b/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.cpp new file mode 100644 index 000000000..c51f0e517 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "imsbuildgroup.h" +#include "msbuildproject.h" + +namespace qbs { + +class IMSBuildGroupPrivate +{ +public: + QString condition; +}; + +IMSBuildGroup::IMSBuildGroup(MSBuildProject *parent) + : QObject(parent) + , d(new IMSBuildGroupPrivate) +{ +} + +IMSBuildGroup::~IMSBuildGroup() +{ +} + +QString IMSBuildGroup::condition() const +{ + return d->condition; +} + +void IMSBuildGroup::setCondition(const QString &condition) +{ + d->condition = condition; +} + +IMSBuildItemGroup::IMSBuildItemGroup(MSBuildProject *parent) + : IMSBuildGroup(parent) +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.h b/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.h new file mode 100644 index 000000000..4d2436e52 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildgroup.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IMSBUILDGROUP_H +#define IMSBUILDGROUP_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> + +namespace qbs { + +class MSBuildProject; +class IMSBuildGroupPrivate; + +class IMSBuildGroup : public QObject +{ + Q_OBJECT +public: + explicit IMSBuildGroup(MSBuildProject *parent = 0); + virtual ~IMSBuildGroup(); + + QString condition() const; + void setCondition(const QString &condition); + +private: + QScopedPointer<IMSBuildGroupPrivate> d; +}; + +class IMSBuildItemGroup : public IMSBuildGroup +{ + Q_OBJECT +public: + explicit IMSBuildItemGroup(MSBuildProject *parent = 0); +}; + +} // namespace qbs + +#endif // IMSBUILDGROUP_H diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildnode.cpp b/src/plugins/generator/visualstudio/msbuild/imsbuildnode.cpp new file mode 100644 index 000000000..4c70405c2 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildnode.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "imsbuildnode.h" + +namespace qbs { + +IMSBuildNode::~IMSBuildNode() +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildnode.h b/src/plugins/generator/visualstudio/msbuild/imsbuildnode.h new file mode 100644 index 000000000..67fb10081 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildnode.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IMSBUILDNODE_H +#define IMSBUILDNODE_H + +namespace qbs { + +class IMSBuildNodeVisitor; + +class IMSBuildNode +{ +public: + virtual ~IMSBuildNode(); + virtual void accept(IMSBuildNodeVisitor *visitor) const = 0; +}; + +} // namespace qbs + +#endif // IMSBUILDNODE_H diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildnodevisitor.h b/src/plugins/generator/visualstudio/msbuild/imsbuildnodevisitor.h new file mode 100644 index 000000000..fe75c23f9 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildnodevisitor.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IMSBUILDNODEVISITOR_H +#define IMSBUILDNODEVISITOR_H + +namespace qbs { + +class MSBuildImport; +class MSBuildImportGroup; +class MSBuildItem; +class MSBuildItemDefinitionGroup; +class MSBuildItemGroup; +class MSBuildItemMetadata; +class MSBuildProject; +class MSBuildProperty; +class MSBuildPropertyGroup; + +class IMSBuildNodeVisitor +{ +public: + virtual ~IMSBuildNodeVisitor() {} + + virtual void visitStart(const MSBuildImport *import) = 0; + virtual void visitEnd(const MSBuildImport *import) = 0; + + virtual void visitStart(const MSBuildImportGroup *importGroup) = 0; + virtual void visitEnd(const MSBuildImportGroup *importGroup) = 0; + + virtual void visitStart(const MSBuildItem *item) = 0; + virtual void visitEnd(const MSBuildItem *item) = 0; + + virtual void visitStart(const MSBuildItemDefinitionGroup *itemDefinitionGroup) = 0; + virtual void visitEnd(const MSBuildItemDefinitionGroup *itemDefinitionGroup) = 0; + + virtual void visitStart(const MSBuildItemGroup *itemGroup) = 0; + virtual void visitEnd(const MSBuildItemGroup *itemGroup) = 0; + + virtual void visitStart(const MSBuildItemMetadata *itemMetadata) = 0; + virtual void visitEnd(const MSBuildItemMetadata *itemMetadata) = 0; + + virtual void visitStart(const MSBuildProject *project) = 0; + virtual void visitEnd(const MSBuildProject *project) = 0; + + virtual void visitStart(const MSBuildProperty *property) = 0; + virtual void visitEnd(const MSBuildProperty *property) = 0; + + virtual void visitStart(const MSBuildPropertyGroup *propertyGroup) = 0; + virtual void visitEnd(const MSBuildPropertyGroup *propertyGroup) = 0; +}; + +} // namespace qbs + +#endif // IMSBUILDNODEVISITOR_H diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.cpp b/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.cpp new file mode 100644 index 000000000..6e54f1e43 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "imsbuildproperty.h" + +namespace qbs { + +class IMSBuildPropertyPrivate +{ +public: + QString condition; + QString name; + QVariant value; +}; + +IMSBuildProperty::IMSBuildProperty(QObject *parent) + : QObject(parent) + , d(new IMSBuildPropertyPrivate) +{ +} + +IMSBuildProperty::~IMSBuildProperty() +{ +} + +QString IMSBuildProperty::condition() const +{ + return d->condition; +} + +void IMSBuildProperty::setCondition(const QString &condition) +{ + d->condition = condition; +} + +QString IMSBuildProperty::name() const +{ + return d->name; +} + +void IMSBuildProperty::setName(const QString &name) +{ + d->name = name; +} + +QVariant IMSBuildProperty::value() const +{ + return d->value; +} + +void IMSBuildProperty::setValue(const QVariant &value) +{ + d->value = value; +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.h b/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.h new file mode 100644 index 000000000..a1a7676e6 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/imsbuildproperty.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IMSBUILDPROPERTY_H +#define IMSBUILDPROPERTY_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> +#include <QtCore/qvariant.h> + +namespace qbs { + +class IMSBuildPropertyPrivate; + +class IMSBuildProperty : public QObject +{ + Q_OBJECT +protected: + explicit IMSBuildProperty(QObject *parent = 0); + +public: + virtual ~IMSBuildProperty(); + + QString condition() const; + void setCondition(const QString &condition); + + QString name() const; + void setName(const QString &name); + + QVariant value() const; + void setValue(const QVariant &value); + +private: + QScopedPointer<IMSBuildPropertyPrivate> d; +}; + +} // namespace qbs + +#endif // IMSBUILDPROPERTY_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.cpp new file mode 100644 index 000000000..d8a587454 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildclcompile.h" + +namespace qbs { + +static const QString MSBuildClCompileItemName = QStringLiteral("ClCompile"); + +MSBuildClCompile::MSBuildClCompile(IMSBuildItemGroup *parent) + : MSBuildFileItem(MSBuildClCompileItemName, parent) +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.h new file mode 100644 index 000000000..745c3ed7f --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildclcompile.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDCLCOMPILE_H +#define MSBUILDCLCOMPILE_H + +#include "msbuildfileitem.h" + +namespace qbs { + +class MSBuildClCompile : public MSBuildFileItem +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildClCompile) +public: + explicit MSBuildClCompile(IMSBuildItemGroup *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDCLCOMPILE_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.cpp new file mode 100644 index 000000000..d9c61bece --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildclinclude.h" + +namespace qbs { + +static const QString MSBuildClIncludeItemName = QStringLiteral("ClInclude"); + +MSBuildClInclude::MSBuildClInclude(IMSBuildItemGroup *parent) + : MSBuildFileItem(MSBuildClIncludeItemName, parent) +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.h new file mode 100644 index 000000000..cfe31022f --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildclinclude.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDCLINCLUDE_H +#define MSBUILDCLINCLUDE_H + +#include "msbuildfileitem.h" + +namespace qbs { + +class MSBuildClInclude : public MSBuildFileItem +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildClInclude) +public: + explicit MSBuildClInclude(IMSBuildItemGroup *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDCLINCLUDE_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.cpp new file mode 100644 index 000000000..bce7488b4 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildfileitem.h" +#include "../msbuilditemmetadata.h" + +namespace qbs { + +class MSBuildFileItemPrivate +{ +public: + QScopedPointer<MSBuildItemMetadata> filter; +}; + +MSBuildFileItem::MSBuildFileItem(const QString &name, IMSBuildItemGroup *parent) + : MSBuildItem(name, parent) + , d(new MSBuildFileItemPrivate) +{ + d->filter.reset(new MSBuildItemMetadata(QStringLiteral("Filter"), QVariant())); +} + +MSBuildFileItem::~MSBuildFileItem() +{ +} + +QString MSBuildFileItem::filePath() const +{ + return include(); +} + +void MSBuildFileItem::setFilePath(const QString &filePath) +{ + setInclude(filePath); +} + +QString MSBuildFileItem::filterName() const +{ + return d->filter->value().toString(); +} + +void MSBuildFileItem::setFilterName(const QString &filterName) +{ + d->filter->setValue(filterName); + d->filter->setParent(!filterName.isEmpty() ? this : nullptr); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.h new file mode 100644 index 000000000..d6e4d485b --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildfileitem.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDFILEITEM_H +#define MSBUILDFILEITEM_H + +#include "../msbuilditem.h" + +namespace qbs { + +class MSBuildFileItemPrivate; + +class MSBuildFileItem : public MSBuildItem +{ +public: + virtual ~MSBuildFileItem(); + + QString filePath() const; + void setFilePath(const QString &filePath); + + QString filterName() const; + void setFilterName(const QString &filterName); + +protected: + explicit MSBuildFileItem(const QString &name, IMSBuildItemGroup *parent = 0); + +private: + QScopedPointer<MSBuildFileItemPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDFILEITEM_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.cpp new file mode 100644 index 000000000..3a5d98a98 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildfilter.h" +#include "../msbuilditemmetadata.h" +#include <tools/hostosinfo.h> +#include <QtCore/quuid.h> + +namespace qbs { + +static const QString MSBuildFilterItemName = QStringLiteral("Filter"); + +class MSBuildFilterPrivate +{ +public: + QUuid identifier; + QList<QString> extensions; + bool parseFiles = true; + bool sourceControlFiles = true; + MSBuildItemMetadata *identifierMetadata; + MSBuildItemMetadata *extensionsMetadata; +}; + +MSBuildFilter::MSBuildFilter(IMSBuildItemGroup *parent) + : MSBuildItem(MSBuildFilterItemName, parent) + , d(new MSBuildFilterPrivate) +{ + d->identifierMetadata = new MSBuildItemMetadata(QStringLiteral("UniqueIdentifier"), + QVariant(), this); + d->extensionsMetadata = new MSBuildItemMetadata(QStringLiteral("Extensions"), + QVariant(), this); + setIdentifier(QUuid::createUuid()); +} + +MSBuildFilter::MSBuildFilter(const QString &name, + const QList<QString> &extensions, + IMSBuildItemGroup *parent) + : MSBuildFilter(parent) +{ + setInclude(name); + setExtensions(extensions); +} + +MSBuildFilter::~MSBuildFilter() +{ +} + +QUuid MSBuildFilter::identifier() const +{ + return d->identifier; +} + +void MSBuildFilter::setIdentifier(const QUuid &identifier) +{ + d->identifier = identifier; + d->identifierMetadata->setValue(identifier.toString()); +} + +QList<QString> MSBuildFilter::extensions() const +{ + return d->extensions; +} + +void MSBuildFilter::setExtensions(const QList<QString> &extensions) +{ + d->extensions = extensions; + d->extensionsMetadata->setValue(QStringList(extensions).join( + Internal::HostOsInfo::pathListSeparator( + Internal::HostOsInfo::HostOsWindows))); +} + +bool MSBuildFilter::parseFiles() const +{ + return d->parseFiles; +} + +void MSBuildFilter::setParseFiles(bool parseFiles) +{ + d->parseFiles = parseFiles; +} + +bool MSBuildFilter::sourceControlFiles() const +{ + return d->sourceControlFiles; +} + +void MSBuildFilter::setSourceControlFiles(bool sourceControlFiles) +{ + d->sourceControlFiles = sourceControlFiles; +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.h new file mode 100644 index 000000000..344783a1e --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildfilter.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDFILTER_H +#define MSBUILDFILTER_H + +#include "../msbuilditem.h" + +namespace qbs { + +class IMSBuildItemGroup; +class MSBuildFilterPrivate; + +class MSBuildFilter : public MSBuildItem +{ + Q_OBJECT +public: + explicit MSBuildFilter(IMSBuildItemGroup *parent = 0); + MSBuildFilter(const QString &name, const QList<QString> &extensions, + IMSBuildItemGroup *parent = 0); + ~MSBuildFilter(); + + QUuid identifier() const; + void setIdentifier(const QUuid &identifier); + + QList<QString> extensions() const; + void setExtensions(const QList<QString> &extensions); + + bool parseFiles() const; + void setParseFiles(bool parseFiles); + + bool sourceControlFiles() const; + void setSourceControlFiles(bool sourceControlFiles); + +private: + QScopedPointer<MSBuildFilterPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDFILTER_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.cpp new file mode 100644 index 000000000..cae1a63a3 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildlink.h" + +#include "../imsbuildgroup.h" + +namespace qbs { + +static const QString MSBuildLinkItemName = QStringLiteral("Link"); + +MSBuildLink::MSBuildLink(IMSBuildItemGroup *parent) + : MSBuildItem(MSBuildLinkItemName, parent) +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.h new file mode 100644 index 000000000..caf125440 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildlink.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDLINK_H +#define MSBUILDLINK_H + +#include "../msbuilditem.h" + +namespace qbs { + +class IMSBuildItemGroup; + +class MSBuildLink : public MSBuildItem +{ + Q_OBJECT +public: + explicit MSBuildLink(IMSBuildItemGroup *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDLINK_H diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.cpp b/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.cpp new file mode 100644 index 000000000..a590c6e9f --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildnone.h" + +namespace qbs { + +MSBuildNone::MSBuildNone(IMSBuildItemGroup *parent) + : MSBuildFileItem(QStringLiteral("None"), parent) +{ +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.h b/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.h new file mode 100644 index 000000000..98dac7a76 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/items/msbuildnone.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDNONE_H +#define MSBUILDNONE_H + +#include "msbuildfileitem.h" + +namespace qbs { + +class MSBuildNone : public MSBuildFileItem +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildNone) +public: + explicit MSBuildNone(IMSBuildItemGroup *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDNONE_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildimport.cpp b/src/plugins/generator/visualstudio/msbuild/msbuildimport.cpp new file mode 100644 index 000000000..a0c693aff --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildimport.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildimport.h" + +#include "imsbuildnodevisitor.h" +#include "msbuildimportgroup.h" +#include "msbuildproject.h" + +namespace qbs { + +class MSBuildImportPrivate +{ +public: + QString project; + QString condition; +}; + +MSBuildImport::MSBuildImport(MSBuildProject *parent) + : QObject(parent) + , d(new MSBuildImportPrivate) +{ +} + +MSBuildImport::MSBuildImport(MSBuildImportGroup *parent) + : QObject(parent) + , d(new MSBuildImportPrivate) +{ +} + +MSBuildImport::~MSBuildImport() +{ +} + +QString MSBuildImport::project() const +{ + return d->project; +} + +void MSBuildImport::setProject(const QString &project) +{ + d->project = project; +} + +QString MSBuildImport::condition() const +{ + return d->condition; +} + +void MSBuildImport::setCondition(const QString &condition) +{ + d->condition = condition; +} + +void MSBuildImport::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildimport.h b/src/plugins/generator/visualstudio/msbuild/msbuildimport.h new file mode 100644 index 000000000..352616e1b --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildimport.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef MSBUILDIMPORT_H +#define MSBUILDIMPORT_H + +#include <QtCore/qobject.h> +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildImportGroup; +class MSBuildImportPrivate; +class MSBuildProject; + +/*! + * \brief The MSBuildImport class represents an MSBuild Import element. + * + * https://msdn.microsoft.com/en-us/library/92x05xfs.aspx + */ +class MSBuildImport : public QObject, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildImport) +public: + explicit MSBuildImport(MSBuildProject *parent); + explicit MSBuildImport(MSBuildImportGroup *parent); + virtual ~MSBuildImport(); + + QString project() const; + void setProject(const QString &project); + + QString condition() const; + void setCondition(const QString &condition); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildImportPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDIMPORT_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.cpp b/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.cpp new file mode 100644 index 000000000..56c48049e --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildimportgroup.h" + +#include "imsbuildnodevisitor.h" +#include "msbuildimport.h" + +namespace qbs { + +class MSBuildImportGroupPrivate +{ +public: + QString label; +}; + +MSBuildImportGroup::MSBuildImportGroup(MSBuildProject *parent) + : IMSBuildGroup(parent) + , d(new MSBuildImportGroupPrivate) +{ +} + +MSBuildImportGroup::~MSBuildImportGroup() +{ +} + +QString MSBuildImportGroup::label() const +{ + return d->label; +} + +void MSBuildImportGroup::setLabel(const QString &label) +{ + d->label = label; +} + +void MSBuildImportGroup::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (const MSBuildImport *import = qobject_cast<const MSBuildImport *>(child)) + import->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.h b/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.h new file mode 100644 index 000000000..c2f0b8fc7 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildimportgroup.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDIMPORTGROUP_H +#define MSBUILDIMPORTGROUP_H + +#include "imsbuildgroup.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildProject; +class MSBuildImportGroupPrivate; + +/*! + * \brief The MSBuildImportGroup class represents an MSBuild ImportGroup element. + * + * https://msdn.microsoft.com/en-us/library/ff606262.aspx + */ +class MSBuildImportGroup : public IMSBuildGroup, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildImportGroup) +public: + explicit MSBuildImportGroup(MSBuildProject *parent = 0); + virtual ~MSBuildImportGroup(); + + QString label() const; + void setLabel(const QString &label); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildImportGroupPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDIMPORTGROUP_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditem.cpp b/src/plugins/generator/visualstudio/msbuild/msbuilditem.cpp new file mode 100644 index 000000000..9a2ffb734 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditem.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuilditem.h" + +#include "imsbuildnodevisitor.h" +#include "msbuilditemdefinitiongroup.h" +#include "msbuilditemgroup.h" +#include "msbuilditemmetadata.h" + +namespace qbs { + +class MSBuildItemPrivate +{ +public: + QString name = QStringLiteral("Item"); + QString include; +}; + +MSBuildItem::MSBuildItem(const QString &name, IMSBuildItemGroup *parent) + : QObject(parent) + , d(new MSBuildItemPrivate) +{ + setName(name); +} + +MSBuildItem::~MSBuildItem() +{ +} + +QString MSBuildItem::name() const +{ + return d->name; +} + +void MSBuildItem::setName(const QString &name) +{ + d->name = name; +} + +QString MSBuildItem::include() const +{ + return d->include; +} + +void MSBuildItem::setInclude(const QString &include) +{ + d->include = include; +} + +void MSBuildItem::appendProperty(const QString &name, const QVariant &value) +{ + new MSBuildItemMetadata(name, value, this); +} + +void MSBuildItem::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (MSBuildItemMetadata *itemMetadata = qobject_cast<MSBuildItemMetadata *>(child)) + itemMetadata->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditem.h b/src/plugins/generator/visualstudio/msbuild/msbuilditem.h new file mode 100644 index 000000000..ca411c715 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditem.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDITEM_H +#define MSBUILDITEM_H + +#include <QtCore/qobject.h> +#include "imsbuildnode.h" + +namespace qbs { + +class IMSBuildItemGroup; +class MSBuildItemDefinitionGroup; +class MSBuildItemGroup; +class MSBuildItemPrivate; + +/*! + * \brief The MSBuildItem class represents an MSBuild Item element. + * + * https://msdn.microsoft.com/en-us/library/ms164283.aspx + */ +class MSBuildItem : public QObject, public IMSBuildNode +{ + Q_OBJECT +public: + explicit MSBuildItem(const QString &name, IMSBuildItemGroup *parent = 0); + virtual ~MSBuildItem(); + + QString name() const; + void setName(const QString &name); + + QString include() const; + void setInclude(const QString &include); + + void appendProperty(const QString &name, const QVariant &value); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildItemPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDITEM_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.cpp b/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.cpp new file mode 100644 index 000000000..5228e850e --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuilditemdefinitiongroup.h" + +#include "imsbuildnodevisitor.h" +#include "msbuilditem.h" + +namespace qbs { + +MSBuildItemDefinitionGroup::MSBuildItemDefinitionGroup(MSBuildProject *parent) + : IMSBuildItemGroup(parent) +{ +} + +MSBuildItemDefinitionGroup::~MSBuildItemDefinitionGroup() +{ +} + +void MSBuildItemDefinitionGroup::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (const auto item = qobject_cast<MSBuildItem *>(child)) + item->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.h b/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.h new file mode 100644 index 000000000..a96f0fff8 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemdefinitiongroup.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDITEMDEFINITIONGROUP_H +#define MSBUILDITEMDEFINITIONGROUP_H + +#include "imsbuildgroup.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildProject; +class MSBuildItemDefinitionGroupPrivate; + +/*! + * \brief The MSBuildItemDefinitionGroup class represents an MSBuild ItemDefinitionGroup element. + * + * https://msdn.microsoft.com/en-us/library/bb629392.aspx + */ +class MSBuildItemDefinitionGroup : public IMSBuildItemGroup, public IMSBuildNode +{ + Q_OBJECT +public: + explicit MSBuildItemDefinitionGroup(MSBuildProject *parent = 0); + ~MSBuildItemDefinitionGroup(); + + void accept(IMSBuildNodeVisitor *visitor) const; +}; + +} // namespace qbs + +#endif // MSBUILDITEMDEFINITIONGROUP_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.cpp b/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.cpp new file mode 100644 index 000000000..7a9bd122b --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuilditemgroup.h" + +#include "imsbuildnodevisitor.h" +#include "msbuilditem.h" + +namespace qbs { + +class MSBuildItemGroupPrivate +{ +public: + QString label; +}; + +MSBuildItemGroup::MSBuildItemGroup(MSBuildProject *parent) + : IMSBuildItemGroup(parent) + , d(new MSBuildItemGroupPrivate) +{ +} + +MSBuildItemGroup::~MSBuildItemGroup() +{ +} + +QString MSBuildItemGroup::label() const +{ + return d->label; +} + +void MSBuildItemGroup::setLabel(const QString &label) +{ + d->label = label; +} + +void MSBuildItemGroup::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (const MSBuildItem *item = qobject_cast<MSBuildItem *>(child)) + item->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.h b/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.h new file mode 100644 index 000000000..02ac6b082 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemgroup.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDITEMGROUP_H +#define MSBUILDITEMGROUP_H + +#include "imsbuildgroup.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildProject; +class MSBuildItemGroupPrivate; + +/*! + * \brief The MSBuildItemGroup class represents an MSBuild ItemGroup element. + * + * https://msdn.microsoft.com/en-us/library/646dk05y.aspx + */ +class MSBuildItemGroup : public IMSBuildItemGroup, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildItemGroup) +public: + explicit MSBuildItemGroup(MSBuildProject *parent = 0); + ~MSBuildItemGroup(); + + QString label() const; + void setLabel(const QString &label); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildItemGroupPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDITEMGROUP_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.cpp b/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.cpp new file mode 100644 index 000000000..daaa4c6b3 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuilditemmetadata.h" + +#include "imsbuildnodevisitor.h" +#include "msbuilditem.h" + +namespace qbs { + +MSBuildItemMetadata::MSBuildItemMetadata(MSBuildItem *parent) + : IMSBuildProperty(parent) +{ +} + +MSBuildItemMetadata::MSBuildItemMetadata(const QString &name, const QVariant &value, + MSBuildItem *parent) + : MSBuildItemMetadata(parent) +{ + setName(name); + setValue(value); +} + +void MSBuildItemMetadata::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.h b/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.h new file mode 100644 index 000000000..7a42f1736 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuilditemmetadata.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDITEMMETADATA_H +#define MSBUILDITEMMETADATA_H + +#include "imsbuildproperty.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildItem; + +/*! + * \brief The MSBuildItemMetadata class represents an MSBuild ItemMetadata element. + * + * https://msdn.microsoft.com/en-us/library/ms164284.aspx + */ +class MSBuildItemMetadata : public IMSBuildProperty, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildItemMetadata) +public: + explicit MSBuildItemMetadata(MSBuildItem *parent = 0); + MSBuildItemMetadata(const QString &name, const QVariant &value = QVariant(), + MSBuildItem *parent = 0); + + void accept(IMSBuildNodeVisitor *visitor) const; +}; + +} // namespace qbs + +#endif // MSBUILDITEMMETADATA_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildproject.cpp b/src/plugins/generator/visualstudio/msbuild/msbuildproject.cpp new file mode 100644 index 000000000..c872622b9 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildproject.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildproject.h" + +#include "imsbuildnodevisitor.h" +#include "msbuildimport.h" +#include "msbuildimportgroup.h" +#include "msbuilditemdefinitiongroup.h" +#include "msbuilditemgroup.h" +#include "msbuildpropertygroup.h" + +namespace qbs { + +class MSBuildProjectPrivate +{ +public: + QString defaultTargets; + QString toolsVersion; +}; + +MSBuildProject::MSBuildProject(QObject *parent) + : QObject(parent) + , d(new MSBuildProjectPrivate) +{ +} + +MSBuildProject::~MSBuildProject() +{ +} + +QString MSBuildProject::defaultTargets() const +{ + return d->defaultTargets; +} + +void MSBuildProject::setDefaultTargets(const QString &defaultTargets) +{ + d->defaultTargets = defaultTargets; +} + +QString MSBuildProject::toolsVersion() const +{ + return d->toolsVersion; +} + +void MSBuildProject::setToolsVersion(const QString &toolsVersion) +{ + d->toolsVersion = toolsVersion; +} + +void MSBuildProject::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (const auto node = qobject_cast<MSBuildImport *>(child)) + node->accept(visitor); + else if (const auto node = qobject_cast<MSBuildImportGroup *>(child)) + node->accept(visitor); + else if (const auto node = qobject_cast<MSBuildItemDefinitionGroup *>(child)) + node->accept(visitor); + else if (const auto node = qobject_cast<MSBuildItemGroup *>(child)) + node->accept(visitor); + else if (const auto node = qobject_cast<MSBuildPropertyGroup *>(child)) + node->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildproject.h b/src/plugins/generator/visualstudio/msbuild/msbuildproject.h new file mode 100644 index 000000000..fc1a0f1f4 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildproject.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDPROJECT_H +#define MSBUILDPROJECT_H + +#include <QtCore/qobject.h> +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildProjectPrivate; + +/*! + * \brief The MSBuildProject class represents an MSBuild Project element. + * + * https://msdn.microsoft.com/en-us/library/bcxfsh87.aspx + */ +class MSBuildProject : public QObject, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildProject) +public: + explicit MSBuildProject(QObject *parent = 0); + ~MSBuildProject(); + + QString defaultTargets() const; + void setDefaultTargets(const QString &defaultTargets); + + QString toolsVersion() const; + void setToolsVersion(const QString &toolsVersion); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildProjectPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildproperty.cpp b/src/plugins/generator/visualstudio/msbuild/msbuildproperty.cpp new file mode 100644 index 000000000..410e2a694 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildproperty.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildproperty.h" + +#include "imsbuildnodevisitor.h" +#include "msbuildpropertygroup.h" + +namespace qbs { + +MSBuildProperty::MSBuildProperty(MSBuildPropertyGroup *parent) + : IMSBuildProperty(parent) +{ +} + +MSBuildProperty::MSBuildProperty(const QString &name, const QVariant &value, + MSBuildPropertyGroup *parent) + : MSBuildProperty(parent) +{ + setName(name); + setValue(value); +} + +void MSBuildProperty::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildproperty.h b/src/plugins/generator/visualstudio/msbuild/msbuildproperty.h new file mode 100644 index 000000000..310fcc044 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildproperty.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDPROPERTY_H +#define MSBUILDPROPERTY_H + +#include "imsbuildproperty.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildPropertyGroup; + +/*! + * \brief The MSBuildProperty class represents an MSBuild Property element. + * + * https://msdn.microsoft.com/en-us/library/ms164288.aspx + */ +class MSBuildProperty : public IMSBuildProperty, public IMSBuildNode +{ + Q_OBJECT +public: + explicit MSBuildProperty(MSBuildPropertyGroup *parent = 0); + MSBuildProperty(const QString &name, const QVariant &value = QVariant(), + MSBuildPropertyGroup *parent = 0); + + void accept(IMSBuildNodeVisitor *visitor) const; +}; + +} // namespace qbs + +#endif // MSBUILDPROPERTY_H diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.cpp b/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.cpp new file mode 100644 index 000000000..4f9c72939 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildpropertygroup.h" + +#include "imsbuildnodevisitor.h" +#include "msbuildproperty.h" + +namespace qbs { + +class MSBuildPropertyGroupPrivate +{ +public: + QString condition; + QString label; +}; + +MSBuildPropertyGroup::MSBuildPropertyGroup(MSBuildProject *parent) + : IMSBuildGroup(parent) + , d(new MSBuildPropertyGroupPrivate) +{ +} + +MSBuildPropertyGroup::~MSBuildPropertyGroup() +{ +} + +QString MSBuildPropertyGroup::label() const +{ + return d->label; +} + +void MSBuildPropertyGroup::setLabel(const QString &label) +{ + d->label = label; +} + +void MSBuildPropertyGroup::appendProperty(const QString &name, const QVariant &value) +{ + new MSBuildProperty(name, value, this); +} + +void MSBuildPropertyGroup::accept(IMSBuildNodeVisitor *visitor) const +{ + visitor->visitStart(this); + + for (const auto &child : children()) { + if (const MSBuildProperty *property = qobject_cast<MSBuildProperty *>(child)) + property->accept(visitor); + } + + visitor->visitEnd(this); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.h b/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.h new file mode 100644 index 000000000..33fa07b3e --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuild/msbuildpropertygroup.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDPROPERTYGROUP_H +#define MSBUILDPROPERTYGROUP_H + +#include "imsbuildgroup.h" +#include "imsbuildnode.h" + +namespace qbs { + +class MSBuildProject; +class MSBuildPropertyGroupPrivate; + +/*! + * \brief The MSBuildPropertyGroup class represents an MSBuild PropertyGroup element. + * + * https://msdn.microsoft.com/en-us/library/t4w159bs.aspx + */ +class MSBuildPropertyGroup : public IMSBuildGroup, public IMSBuildNode +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildPropertyGroup) +public: + explicit MSBuildPropertyGroup(MSBuildProject *parent = 0); + ~MSBuildPropertyGroup(); + + QString label() const; + void setLabel(const QString &label); + + void appendProperty(const QString &name, const QVariant &value); + + void accept(IMSBuildNodeVisitor *visitor) const; + +private: + QScopedPointer<MSBuildPropertyGroupPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDPROPERTYGROUP_H diff --git a/src/plugins/generator/visualstudio/msbuildfiltersproject.cpp b/src/plugins/generator/visualstudio/msbuildfiltersproject.cpp new file mode 100644 index 000000000..45a09236a --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildfiltersproject.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildfiltersproject.h" + +#include "msbuild/msbuilditemgroup.h" + +#include "msbuild/items/msbuildclcompile.h" +#include "msbuild/items/msbuildclinclude.h" +#include "msbuild/items/msbuildfilter.h" +#include "msbuild/items/msbuildnone.h" + +#include <tools/set.h> + +#include <QtCore/qfileinfo.h> + +#include <vector> + +namespace qbs { + +namespace { + +static QStringList sourceFileExtensions() +{ + return QStringList() + << QStringLiteral("c") + << QStringLiteral("C") + << QStringLiteral("cpp") + << QStringLiteral("cxx") + << QStringLiteral("c++") + << QStringLiteral("cc") + << QStringLiteral("cs") + << QStringLiteral("def") + << QStringLiteral("java") + << QStringLiteral("m") + << QStringLiteral("mm"); +} + +static QStringList headerFileExtensions() +{ + return QStringList() + << QStringLiteral("h") + << QStringLiteral("H") + << QStringLiteral("hpp") + << QStringLiteral("hxx") + << QStringLiteral("h++"); +} + +static std::vector<MSBuildFilter *> defaultItemGroupFilters(IMSBuildItemGroup *parent = 0) +{ + const auto sourceFilter = new MSBuildFilter(QStringLiteral("Source Files"), sourceFileExtensions(), parent); + const auto headerFilter = new MSBuildFilter(QStringLiteral("Header Files"), headerFileExtensions(), parent); + + const auto formFilter = new MSBuildFilter(QStringLiteral("Form Files"), + QStringList() << QStringLiteral("ui"), parent); + const auto resourceFilter = new MSBuildFilter(QStringLiteral("Resource Files"), + QStringList() + << QStringLiteral("qrc") + << QStringLiteral("rc") + << QStringLiteral("*"), parent); + resourceFilter->setParseFiles(false); + const auto generatedFilter = new MSBuildFilter(QStringLiteral("Generated Files"), + QStringList() << QStringLiteral("moc"), parent); + generatedFilter->setSourceControlFiles(false); + const auto translationFilter = new MSBuildFilter(QStringLiteral("Translation Files"), + QStringList() << QStringLiteral("ts"), parent); + translationFilter->setParseFiles(false); + + return std::vector<MSBuildFilter *> { + sourceFilter, headerFilter, formFilter, resourceFilter, generatedFilter, translationFilter + }; +} + +static bool matchesFilter(const MSBuildFilter *filter, const QString &filePath) +{ + return filter->extensions().contains(QFileInfo(filePath).completeSuffix()); +} + +} + +MSBuildFiltersProject::MSBuildFiltersProject(const GeneratableProductData &product, + QObject *parent) + : MSBuildProject(parent) +{ + // Normally this would be versionInfo.toolsVersion() but for some reason it seems + // filters projects are always v4.0 + setToolsVersion(QStringLiteral("4.0")); + + auto itemGroup = new MSBuildItemGroup(this); + const auto filterOptions = defaultItemGroupFilters(); + for (const auto options : filterOptions) { + auto filter = new MSBuildFilter(options->include(), options->extensions(), itemGroup); + filter->appendProperty(QStringLiteral("ParseFiles"), options->parseFiles()); + filter->appendProperty(QStringLiteral("SourceControlFiles"), options->sourceControlFiles()); + } + + Internal::Set<QString> allFiles; + for (const auto &productData : product.data.values()) { + for (const auto &groupData : productData.groups()) + if (groupData.isEnabled()) + allFiles.unite(Internal::Set<QString>::fromList(groupData.allFilePaths())); + } + + MSBuildItemGroup *headerFilesGroup = nullptr; + MSBuildItemGroup *sourceFilesGroup = nullptr; + MSBuildItemGroup *filesGroup = nullptr; + + for (const auto &filePath : allFiles) { + MSBuildFileItem *fileItem = nullptr; + + for (const MSBuildFilter *options : filterOptions) { + if (matchesFilter(options, filePath)) { + if (options->include() == QStringLiteral("Header Files")) { + if (!headerFilesGroup) + headerFilesGroup = new MSBuildItemGroup(this); + fileItem = new MSBuildClInclude(headerFilesGroup); + } else if (options->include() == QStringLiteral("Source Files")) { + if (!sourceFilesGroup) + sourceFilesGroup = new MSBuildItemGroup(this); + fileItem = new MSBuildClCompile(sourceFilesGroup); + } + + if (fileItem) { + fileItem->setFilterName(options->include()); + break; + } + } + } + + if (!fileItem) { + if (!filesGroup) + filesGroup = new MSBuildItemGroup(this); + fileItem = new MSBuildNone(filesGroup); + } + fileItem->setFilePath(filePath); + } + + qDeleteAll(filterOptions); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildfiltersproject.h b/src/plugins/generator/visualstudio/msbuildfiltersproject.h new file mode 100644 index 000000000..521a6e610 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildfiltersproject.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDFILTERSPROJECT_H +#define MSBUILDFILTERSPROJECT_H + +#include "msbuild/msbuildproject.h" + +#include <generators/generatordata.h> +#include <tools/visualstudioversioninfo.h> + +namespace qbs { + +class MSBuildFilter; + +class MSBuildFiltersProject : public MSBuildProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildFiltersProject) +public: + explicit MSBuildFiltersProject(const GeneratableProductData &product, + QObject *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDFILTERSPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.cpp b/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.cpp new file mode 100644 index 000000000..51c72ecd3 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildqbsgenerateproject.h" + +#include "msbuild/msbuildimport.h" +#include "msbuild/msbuildproperty.h" +#include "msbuild/msbuildpropertygroup.h" + +#include <tools/hostosinfo.h> +#include <tools/shellutils.h> +#include <QtCore/quuid.h> + +namespace qbs { + +MSBuildQbsGenerateProject::MSBuildQbsGenerateProject( + const GeneratableProject &project, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent) + : MSBuildTargetProject(project, versionInfo, parent) +{ + auto cppDefaultProps = new MSBuildImport(this); + cppDefaultProps->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.Default.props")); + + auto group = new MSBuildPropertyGroup(this); + group->setLabel(QStringLiteral("Configuration")); + group->appendProperty(QStringLiteral("PlatformToolset"), + versionInfo.platformToolsetVersion()); + group->appendProperty(QStringLiteral("ConfigurationType"), + QStringLiteral("Makefile")); + const auto params = Internal::shellQuote(project.commandLine(), + Internal::HostOsInfo::HostOsWindows); + group->appendProperty(QStringLiteral("NMakeBuildCommandLine"), + QStringLiteral("$(QbsGenerateCommandLine) ") + params); + + auto cppProps = new MSBuildImport(this); + cppProps->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.props")); + + auto import = new MSBuildImport(this); + import->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.targets")); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.h b/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.h new file mode 100644 index 000000000..433bd31a1 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildqbsgenerateproject.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDQBSGENERATEPROJECT_H +#define MSBUILDQBSGENERATEPROJECT_H + +#include "msbuildtargetproject.h" + +#include <generators/generatordata.h> +#include <tools/visualstudioversioninfo.h> + +namespace qbs { + +class MSBuildQbsGenerateProject : public MSBuildTargetProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildQbsGenerateProject) +public: + MSBuildQbsGenerateProject(const GeneratableProject &project, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent = 0); +}; + +} // namespace qbs + +#endif // MSBUILDQBSGENERATEPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildqbsproductproject.cpp b/src/plugins/generator/visualstudio/msbuildqbsproductproject.cpp new file mode 100644 index 000000000..fc9187ae2 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildqbsproductproject.cpp @@ -0,0 +1,425 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildqbsproductproject.h" + +#include "msbuild/msbuildimport.h" +#include "msbuild/msbuildimportgroup.h" +#include "msbuild/msbuilditemdefinitiongroup.h" +#include "msbuild/msbuilditemgroup.h" +#include "msbuild/msbuilditemmetadata.h" +#include "msbuild/msbuildproperty.h" +#include "msbuild/msbuildpropertygroup.h" + +#include "msbuild/items/msbuildclcompile.h" +#include "msbuild/items/msbuildclinclude.h" +#include "msbuild/items/msbuildlink.h" +#include "msbuild/items/msbuildnone.h" + +#include "msbuildutils.h" +#include "visualstudiogenerator.h" + +#include <api/runenvironment.h> +#include <tools/pathutils.h> +#include <tools/shellutils.h> +#include <tools/version.h> + +#include <QtCore/qdir.h> +#include <QtCore/quuid.h> + +namespace qbs { + +MSBuildQbsProductProject::MSBuildQbsProductProject( + const GeneratableProject &project, + const GeneratableProductData &product, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent) + : MSBuildTargetProject(project, versionInfo, parent) +{ + Q_ASSERT(project.projects.size() == project.commandLines.size()); + Q_ASSERT(project.projects.size() == product.data.size()); + + const int count = std::max(project.projects.size(), product.data.size()); + + globalsPropertyGroup()->appendProperty(QStringLiteral("QbsProductName"), product.name()); + + MSBuildImport *cppDefaultProps = new MSBuildImport(this); + cppDefaultProps->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.Default.props")); + + for (int i = 0; i < count; ++i) { + addConfiguration( + project, + project.projects.values().at(i), + product.data.values().at(i), + project.commandLines.values().at(i)); + } + + MSBuildImport *cppProps = new MSBuildImport(this); + cppProps->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.props")); + + for (int i = 0; i < count; ++i) + addItemDefGroup(project.projects.values().at(i), product.data.values().at(i)); + + addFiles(project, product); +} + +static QString productTargetPath(const qbs::ProductData &productData) +{ + const QString fullPath = productData.targetExecutable(); + if (!fullPath.isEmpty()) + return QFileInfo(fullPath).absolutePath(); + return productData.properties().value(QStringLiteral("buildDirectory")).toString(); +} + +static bool listEnvironmentVariableContainsValue(const QString &environmentVariable, + const QString &value) +{ + return environmentVariable.contains(QLatin1Char(';') + value + QLatin1Char(';')) + || environmentVariable.startsWith(value + QLatin1Char(';')) + || environmentVariable.endsWith(QLatin1Char(';') + value); +} + +void MSBuildQbsProductProject::addConfiguration(const GeneratableProject &project, + const Project &buildTask, + const ProductData &productData, + const QStringList &buildConfigurationCommandLine) +{ + const auto targetDir = Internal::PathUtils::toNativeSeparators( + productTargetPath(productData), Internal::HostOsInfo::HostOsWindows); + + auto configurationDir = Internal::PathUtils::toNativeSeparators( + project.baseBuildDirectory().absolutePath() + + QLatin1Char('\\') + + MSBuildUtils::configurationName(buildTask), + Internal::HostOsInfo::HostOsWindows); + auto relativeTargetDir = targetDir; + if (targetDir.startsWith(configurationDir)) + relativeTargetDir = QStringLiteral("$(SolutionDir)$(Configuration)") + + relativeTargetDir.mid(configurationDir.size()); + + const auto properties = productData.moduleProperties(); + + const bool debugBuild = properties.getModuleProperty(QStringLiteral("qbs"), + QStringLiteral("debugInformation")) + .toBool(); + + const auto includePaths = QStringList() + << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("includePaths")) + << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("systemIncludePaths")); + const auto cppDefines = properties + .getModulePropertiesAsStringList(QStringLiteral("cpp"), QStringLiteral("defines")); + + const auto sep = Internal::HostOsInfo::pathListSeparator(Internal::HostOsInfo::HostOsWindows); + + auto propertyGroup1 = new MSBuildPropertyGroup(this); + propertyGroup1->setCondition(MSBuildUtils::buildTaskCondition(buildTask)); + propertyGroup1->setLabel(QStringLiteral("Configuration")); + propertyGroup1->appendProperty(QStringLiteral("UseDebugLibraries"), + debugBuild ? QStringLiteral("true") : QStringLiteral("false")); + + // General - General + // We need a trailing backslash for $(OutDir); See also the VS documentation: + // https://docs.microsoft.com/en-us/cpp/ide/common-macros-for-build-commands-and-properties + propertyGroup1->appendProperty(QStringLiteral("OutDir"), relativeTargetDir + QLatin1Char('\\')); + propertyGroup1->appendProperty(QStringLiteral("TargetName"), productData.targetName()); + propertyGroup1->appendProperty(QStringLiteral("PlatformToolset"), + versionInfo().platformToolsetVersion()); + propertyGroup1->appendProperty(QStringLiteral("ConfigurationType"), QStringLiteral("Makefile")); + + // VS possible values: Unicode|MultiByte|NotSet + propertyGroup1->appendProperty(QStringLiteral("CharacterSet"), + properties.getModuleProperty(QStringLiteral("cpp"), + QStringLiteral("windowsApiCharacterSet")) == QStringLiteral("unicode") + ? QStringLiteral("MultiByte") : QStringLiteral("NotSet")); + + // Debugging + propertyGroup1->appendProperty(QStringLiteral("DebuggerFlavor"), + QStringLiteral("WindowsLocalDebugger")); + propertyGroup1->appendProperty(QStringLiteral("LocalDebuggerCommand"), + QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)")); + propertyGroup1->appendProperty(QStringLiteral("LocalDebuggerWorkingDirectory"), + QStringLiteral("$(OutDir)")); + + auto env = buildTask.getRunEnvironment(productData, project.installOptions, + QProcessEnvironment(), nullptr).runEnvironment(); + if (!env.isEmpty()) { + const auto systemEnv = QProcessEnvironment::systemEnvironment(); + for (const auto &key : systemEnv.keys()) { + if (!env.contains(key)) + continue; + + // Don't duplicate keys from the system environment + if (env.value(key) == systemEnv.value(key)) { + env.remove(key); + continue; + } + + // Cleverly concatenate list variables to avoid duplicating system environment + const QString systemValue = systemEnv.value(key); + QString overriddenValue = env.value(key); + if (listEnvironmentVariableContainsValue(overriddenValue, systemValue)) { + env.insert(key, overriddenValue.replace(systemValue, + QLatin1Char('%') + key + QLatin1Char('%'))); + } + + QString installRoot = project.installOptions.installRoot(); + if (!installRoot.isEmpty()) { + if (listEnvironmentVariableContainsValue(overriddenValue, installRoot)) { + env.insert(key, overriddenValue.replace(installRoot, + QStringLiteral("$(QbsInstallRoot)"))); + } + } else { + installRoot = Internal::PathUtils::toNativeSeparators( + QDir(buildTask.projectData().buildDirectory()).absoluteFilePath( + project.installOptions.defaultInstallRoot()), + Internal::HostOsInfo::HostOsWindows); + if (listEnvironmentVariableContainsValue(overriddenValue, installRoot)) { + env.insert(key, overriddenValue.replace(installRoot, + QStringLiteral("$(SolutionDir)$(Configuration)\\install-root"))); + } + } + } + + propertyGroup1->appendProperty(QStringLiteral("LocalDebuggerEnvironment"), + env.toStringList().join(QStringLiteral("\n"))); + } + + // NMake - General + // Skip configuration name, that's handled in qbs-shared.props + const auto params = Internal::shellQuote(buildConfigurationCommandLine.mid(1), + Internal::HostOsInfo::HostOsWindows); + propertyGroup1->appendProperty(QStringLiteral("NMakeBuildCommandLine"), + QStringLiteral("$(QbsBuildCommandLine) ") + params); + propertyGroup1->appendProperty(QStringLiteral("NMakeReBuildCommandLine"), + QStringLiteral("$(QbsReBuildCommandLine) ") + params); + propertyGroup1->appendProperty(QStringLiteral("NMakeCleanCommandLine"), + QStringLiteral("$(QbsCleanCommandLine) ") + params); + propertyGroup1->appendProperty(QStringLiteral("NMakeOutput"), + QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)")); + + // NMake - IntelliSense + propertyGroup1->appendProperty(QStringLiteral("NMakePreprocessorDefinitions"), + cppDefines.join(sep)); + propertyGroup1->appendProperty(QStringLiteral("NMakeIncludeSearchPath"), + includePaths.join(sep)); +} + +static QString subsystemVersion(const QString &version) +{ + const auto v = Internal::Version::fromString(version); + return QStringLiteral("%1.%2").arg( + QString::number(v.majorVersion()), + QString::number(v.minorVersion()).rightJustified(2, QLatin1Char('0'))); +} + +void MSBuildQbsProductProject::addItemDefGroup(const Project &project, + const ProductData &productData) +{ + const auto properties = productData.moduleProperties(); + + const bool consoleApp = productData.properties().value(QStringLiteral("consoleApplication")) + .toBool(); + const bool debugBuild = properties.getModuleProperty(QStringLiteral("qbs"), + QStringLiteral("debugInformation")) + .toBool(); + const auto optimizationLevel = properties.getModuleProperty(QStringLiteral("qbs"), + QStringLiteral("optimization")) + .toString(); + const auto warningLevel = properties.getModuleProperty(QStringLiteral("qbs"), + QStringLiteral("warningLevel")) + .toString(); + + const auto includePaths = QStringList() + << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("includePaths")) + << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("systemIncludePaths")); + const auto cppDefines = properties.getModulePropertiesAsStringList( + QStringLiteral("cpp"), QStringLiteral("defines")); + + const auto sep = Internal::HostOsInfo::pathListSeparator(Internal::HostOsInfo::HostOsWindows); + + auto itemDefGroup = new MSBuildItemDefinitionGroup(this); + itemDefGroup->setCondition(MSBuildUtils::buildTaskCondition(project)); + + auto compile = new MSBuildClCompile(itemDefGroup); + + // C++ - General + compile->appendProperty(QStringLiteral("AdditionalIncludeDirectories"), + includePaths.join(sep) + + sep + + QStringLiteral("%(AdditionalIncludeDirectories)")); + if (warningLevel == QStringLiteral("none")) + compile->appendProperty(QStringLiteral("WarningLevel"), + QStringLiteral("TurnOffAllWarnings")); + else if (warningLevel == QStringLiteral("all")) + compile->appendProperty(QStringLiteral("WarningLevel"), + QStringLiteral("EnableAllWarnings")); + else + compile->appendProperty(QStringLiteral("WarningLevel"), + QStringLiteral("Level3")); // this is VS default. + + // C++ - Optimization + compile->appendProperty(QStringLiteral("Optimization"), + optimizationLevel == QStringLiteral("none") + ? QStringLiteral("Disabled") + : QStringLiteral("MaxSpeed")); + + // C++ - Preprocessor + compile->appendProperty(QStringLiteral("PreprocessorDefinitions"), + cppDefines.join(sep) + + sep + + QStringLiteral("%(PreprocessorDefinitions)")); + + // C++ - Code Generation + compile->appendProperty(QStringLiteral("RuntimeLibrary"), debugBuild + ? QStringLiteral("MultiThreadedDebugDLL") + : QStringLiteral("MultiThreadedDLL")); + + auto link = new MSBuildLink(itemDefGroup); + + // Linker - General + link->appendProperty(QStringLiteral("AdditionalLibraryDirectories"), + properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("libraryPaths")).join(sep)); + + // Linker - Input + link->appendProperty(QStringLiteral("AdditionalDependencies"), + properties.getModulePropertiesAsStringList(QStringLiteral("cpp"), + QStringLiteral("staticLibraries")).join(sep) + + sep + QStringLiteral("%(AdditionalDependencies)")); + + // Linker - Debugging + link->appendProperty(QStringLiteral("GenerateDebugInformation"), + debugBuild ? QStringLiteral("true") : QStringLiteral("false")); + + // Linker - System + link->appendProperty(QStringLiteral("SubSystem"), + consoleApp ? QStringLiteral("Console") : QStringLiteral("Windows")); + const auto subsysVersion = properties.getModuleProperty( + QStringLiteral("cpp"), QStringLiteral("minimumWindowsVersion")).toString(); + if (!subsysVersion.isEmpty()) + link->appendProperty(QStringLiteral("MinimumRequiredVersion"), + subsystemVersion(subsysVersion)); + + // Linker - Optimization + link->appendProperty(QStringLiteral("OptimizeReferences"), + debugBuild ? QStringLiteral("false") : QStringLiteral("true")); +} + +static MSBuildFileItem *fileItemForFileTags(const QList<QString> &fileTags, + IMSBuildItemGroup *parent = 0) +{ + const auto fileTagsSet = Internal::Set<QString>::fromList(fileTags); + if (fileTagsSet.intersects( + Internal::Set<QString> { QStringLiteral("hpp") })) + return new MSBuildClInclude(parent); + if (fileTagsSet.intersects( + Internal::Set<QString> { QStringLiteral("c"), QStringLiteral("cpp") })) + return new MSBuildClCompile(parent); + return new MSBuildNone(parent); +} + +void MSBuildQbsProductProject::addFiles(const GeneratableProject &project, + const GeneratableProductData &product) +{ + auto itemGroup = new MSBuildItemGroup(this); + + addQbsFile(project, product, itemGroup); + + std::map<QString, MSBuildFileItem *> sourceFileNodes; + std::map<QString, QStringList> sourceFileEnabledConfigurations; + + // Create a ClCompile item for each source file, keeping track of which configurations that + // file's containing group is enabled in + QMapIterator<QString, qbs::ProductData> productDataIt(product.data); + while (productDataIt.hasNext()) { + productDataIt.next(); + for (const auto &group : productDataIt.value().groups()) { + for (const auto &sourceArtifact : group.allSourceArtifacts()) { + const auto filePath = sourceArtifact.filePath(); + if (sourceFileNodes.find(filePath) == sourceFileNodes.end()) { + sourceFileNodes.insert({ + filePath, + fileItemForFileTags(sourceArtifact.fileTags(), itemGroup) + }); + } + auto fileItem = sourceFileNodes[filePath]; + QString path = project.baseBuildDirectory().relativeFilePath(filePath); + // The path still might not be relative (for example if the file item is + // located on a different drive) + if (QFileInfo(path).isRelative()) + path = QStringLiteral("$(ProjectDir)") + path; + fileItem->setFilePath(path); + if (group.isEnabled()) + sourceFileEnabledConfigurations[filePath] << productDataIt.key(); + } + } + } + + // Add ExcludedFromBuild item metadata to each file for each configuration + // where that file's containing group is disabled + for (const auto &sourceFileNode : sourceFileNodes) { + QMapIterator<QString, qbs::Project> projIt(project.projects); + while (projIt.hasNext()) { + projIt.next(); + if (!sourceFileEnabledConfigurations[sourceFileNode.first].contains(projIt.key())) { + auto metadata = new MSBuildItemMetadata( + QStringLiteral("ExcludedFromBuild"), + QStringLiteral("true"), + sourceFileNode.second); + metadata->setCondition(QStringLiteral("'$(Configuration)|$(Platform)'=='") + + MSBuildUtils::fullName(projIt.value()) + + QStringLiteral("'")); + } + } + } + + auto import = new MSBuildImport(this); + import->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.targets")); +} + +void MSBuildQbsProductProject::addQbsFile(const GeneratableProject &project, + const GeneratableProductData &product, + MSBuildItemGroup *itemGroup) +{ + auto fileItem = new MSBuildNone(itemGroup); + QString path = project.baseBuildDirectory().relativeFilePath(product.location().filePath()); + // The path still might not be relative (for example if the file item is + // located on a different drive) + if (QFileInfo(path).isRelative()) + path = QStringLiteral("$(ProjectDir)") + path; + fileItem->setFilePath(path); +} + + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildqbsproductproject.h b/src/plugins/generator/visualstudio/msbuildqbsproductproject.h new file mode 100644 index 000000000..7fb9e2a39 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildqbsproductproject.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDQBSPRODUCTPROJECT_H +#define MSBUILDQBSPRODUCTPROJECT_H + +#include "msbuildtargetproject.h" + +#include <generators/generatordata.h> +#include <tools/set.h> +#include <tools/visualstudioversioninfo.h> + +namespace qbs { + +class MSBuildImportGroup; +class MSBuildItemGroup; +class MSBuildProperty; + +class VisualStudioGenerator; + +class MSBuildQbsProductProject : public MSBuildTargetProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildQbsProductProject) +public: + MSBuildQbsProductProject(const GeneratableProject &project, + const GeneratableProductData &product, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent = 0); + +private: + typedef QHash<QString, Internal::Set<Project>> ProjectConfigurations; + + void addConfiguration(const GeneratableProject &project, const Project &buildTask, + const ProductData &productData, + const QStringList &buildConfigurationCommandLine); + void addItemDefGroup(const Project &project, + const ProductData &productData); + void addFiles(const GeneratableProject &project, const GeneratableProductData &product); + void addQbsFile(const GeneratableProject &project, const GeneratableProductData &product, + MSBuildItemGroup *itemGroup); +}; + +} // namespace qbs + +#endif // MSBUILDQBSPRODUCTPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.cpp b/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.cpp new file mode 100644 index 000000000..d8389817f --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildsharedsolutionpropertiesproject.h" + +#include "msbuild/msbuildpropertygroup.h" + +#include <tools/pathutils.h> +#include <tools/shellutils.h> + +#include <QtCore/qfileinfo.h> + +namespace qbs { + +static QString qbsCommandLine(const GeneratableProject &project, + const QString &subCommand, + const QString &qbsSettingsDir, + const Internal::VisualStudioVersionInfo &versionInfo) +{ + auto addEnvironmentVariableArgument = [&](Internal::CommandLine &cl, const QString &var) { + cl.appendRawArgument(QStringLiteral("\"$(%1)\"").arg(var)); + }; + + auto realSubCommand = subCommand; + if (subCommand == QStringLiteral("rebuild")) + realSubCommand = QStringLiteral("build"); + + // "path/to/qbs.exe" {build|clean} + // --settings-dir "path/to/settings/directory/" + // -f "path/to/project.qbs" -d "/build/directory/" + // -p product_name [[configuration key:value]...] + Internal::CommandLine commandLine; + commandLine.setProgram(QStringLiteral("\"$(QbsExecutablePath)\""), true); + commandLine.appendArgument(realSubCommand); + + if (!qbsSettingsDir.isEmpty()) { + commandLine.appendArgument(QStringLiteral("--settings-dir")); + addEnvironmentVariableArgument(commandLine, QStringLiteral("QbsSettingsDir")); + } + + commandLine.appendArgument(QStringLiteral("-f")); + addEnvironmentVariableArgument(commandLine, QStringLiteral("QbsProjectFile")); + commandLine.appendArgument(QStringLiteral("-d")); + addEnvironmentVariableArgument(commandLine, QStringLiteral("QbsBuildDir")); + + if (subCommand == QStringLiteral("generate")) { + commandLine.appendArgument(QStringLiteral("-g")); + commandLine.appendArgument( + QString(QStringLiteral("visualstudio%1")).arg(versionInfo.marketingVersion())); + } else { + commandLine.appendArgument(QStringLiteral("-p")); + addEnvironmentVariableArgument(commandLine, QStringLiteral("QbsProductName")); + + commandLine.appendArgument(QStringLiteral("--wait-lock")); + } + + if (realSubCommand == QStringLiteral("build") + && !project.installOptions.installRoot().isEmpty()) { + commandLine.appendArgument(QStringLiteral("--install-root")); + addEnvironmentVariableArgument(commandLine, QStringLiteral("QbsInstallRoot")); + } + + if (realSubCommand == QStringLiteral("build") && subCommand == QStringLiteral("rebuild")) { + commandLine.appendArgument(QStringLiteral("--check-timestamps")); + commandLine.appendArgument(QStringLiteral("--force-probe-execution")); + } + + addEnvironmentVariableArgument(commandLine, QStringLiteral("Configuration")); + + return commandLine.toCommandLine(Internal::HostOsInfo::HostOsWindows); +} + +MSBuildSharedSolutionPropertiesProject::MSBuildSharedSolutionPropertiesProject( + const Internal::VisualStudioVersionInfo &versionInfo, + const GeneratableProject &project, + const QFileInfo &qbsExecutable, + const QString &qbsSettingsDir) +{ + setDefaultTargets(QStringLiteral("Build")); + setToolsVersion(versionInfo.toolsVersion()); + + MSBuildPropertyGroup *group = new MSBuildPropertyGroup(this); + group->setLabel(QStringLiteral("UserMacros")); + + // Order's important here... a variable must be listed before one that uses it + group->appendProperty(QStringLiteral("QbsExecutablePath"), + QStringLiteral("$(QbsExecutableDir)") + qbsExecutable.fileName()); + if (!project.installOptions.installRoot().isEmpty()) { + group->appendProperty(QStringLiteral("QbsInstallRoot"), + Internal::PathUtils::toNativeSeparators( + project.installOptions.installRoot(), + Internal::HostOsInfo::HostOsWindows)); + } + + group->appendProperty(QStringLiteral("QbsProjectFile"), + QStringLiteral("$(QbsProjectDir)") + + project.filePath().fileName()); + + // Trailing '.' is not a typo. It prevents the trailing slash from combining with the closing + // quote to form an escape sequence. Unfortunately, Visual Studio expands variables *before* + // passing them to the underlying command shell, so there's not much we can do with regard to + // doing it "properly". Setting environment variables through MSBuild and using them in place + // of actual arguments does not work either, as Visual Studio apparently expands the environment + // variables as well, before passing them to the underlying shell. + group->appendProperty(QStringLiteral("QbsBuildDir"), + QStringLiteral("$(SolutionDir).")); + + group->appendProperty(QStringLiteral("QbsBuildCommandLine"), + qbsCommandLine(project, QStringLiteral("build"), + qbsSettingsDir, versionInfo)); + group->appendProperty(QStringLiteral("QbsReBuildCommandLine"), + qbsCommandLine(project, QStringLiteral("rebuild"), + qbsSettingsDir, versionInfo)); + group->appendProperty(QStringLiteral("QbsCleanCommandLine"), + qbsCommandLine(project, QStringLiteral("clean"), + qbsSettingsDir, versionInfo)); + group->appendProperty(QStringLiteral("QbsGenerateCommandLine"), + qbsCommandLine(project, QStringLiteral("generate"), + qbsSettingsDir, versionInfo)); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.h b/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.h new file mode 100644 index 000000000..f3848ce24 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildsharedsolutionpropertiesproject.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDSHAREDSOLUTIONPROPERTIESPROJECT_H +#define MSBUILDSHAREDSOLUTIONPROPERTIESPROJECT_H + +#include "msbuild/msbuildproject.h" + +#include <generators/generatordata.h> +#include <tools/visualstudioversioninfo.h> + +namespace qbs { + +class MSBuildSharedSolutionPropertiesProject : public MSBuildProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildSharedSolutionPropertiesProject) +public: + MSBuildSharedSolutionPropertiesProject(const Internal::VisualStudioVersionInfo &versionInfo, + const GeneratableProject &project, + const QFileInfo &qbsExecutable, const QString &qbsSettingsDir); +}; + +} // namespace qbs + +#endif // MSBUILDSHAREDSOLUTIONPROPERTIESPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.cpp b/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.cpp new file mode 100644 index 000000000..b0572e2e0 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildsolutionpropertiesproject.h" + +#include "msbuild/msbuildpropertygroup.h" + +#include <tools/pathutils.h> + +#include <QtCore/qfileinfo.h> + +namespace qbs { + +MSBuildSolutionPropertiesProject::MSBuildSolutionPropertiesProject( + const Internal::VisualStudioVersionInfo &versionInfo, + const GeneratableProject &project, + const QFileInfo &qbsExecutable, + const QString &qbsSettingsDir) +{ + setDefaultTargets(QStringLiteral("Build")); + setToolsVersion(versionInfo.toolsVersion()); + + auto group = new MSBuildPropertyGroup(this); + group->setLabel(QStringLiteral("UserMacros")); + + static const auto win = Internal::HostOsInfo::HostOsWindows; + + group->appendProperty(QStringLiteral("QbsExecutableDir"), + Internal::PathUtils::toNativeSeparators(qbsExecutable.path(), win) + + Internal::HostOsInfo::pathSeparator(win)); + group->appendProperty(QStringLiteral("QbsProjectDir"), + Internal::PathUtils::toNativeSeparators(project.filePath().path(), win) + + Internal::HostOsInfo::pathSeparator(win)); + + if (!qbsSettingsDir.isEmpty()) { + group->appendProperty(QStringLiteral("QbsSettingsDir"), + Internal::PathUtils::toNativeSeparators(qbsSettingsDir, win) + + Internal::HostOsInfo::pathSeparator(win) + QLatin1Char('.')); + } +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.h b/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.h new file mode 100644 index 000000000..1c49f7901 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildsolutionpropertiesproject.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDSOLUTIONPROPERTIESPROJECT_H +#define MSBUILDSOLUTIONPROPERTIESPROJECT_H + +#include "msbuild/msbuildproject.h" + +#include <generators/generatordata.h> +#include <tools/visualstudioversioninfo.h> + +#include <QtCore/qfileinfo.h> + +namespace qbs { + +class MSBuildSolutionPropertiesProject : public MSBuildProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildSolutionPropertiesProject) +public: + MSBuildSolutionPropertiesProject(const Internal::VisualStudioVersionInfo &versionInfo, + const GeneratableProject &project, + const QFileInfo &qbsExecutable, + const QString &qbsSettingsDir); +}; + +} // namespace qbs + +#endif // MSBUILDSOLUTIONPROPERTIESPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildtargetproject.cpp b/src/plugins/generator/visualstudio/msbuildtargetproject.cpp new file mode 100644 index 000000000..9a1d00476 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildtargetproject.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildtargetproject.h" +#include "msbuildutils.h" +#include "visualstudiogenerator.h" + +#include "msbuild/msbuildimport.h" +#include "msbuild/msbuildimportgroup.h" +#include "msbuild/msbuilditem.h" +#include "msbuild/msbuilditemgroup.h" +#include "msbuild/msbuildproperty.h" +#include "msbuild/msbuildpropertygroup.h" + +namespace qbs { + +class MSBuildTargetProjectPrivate +{ +public: + MSBuildTargetProjectPrivate(const Internal::VisualStudioVersionInfo &versionInfo) + : versionInfo(versionInfo) {} + MSBuildPropertyGroup *globalsPropertyGroup; + MSBuildProperty *projectGuidProperty; + const Internal::VisualStudioVersionInfo &versionInfo; +}; + +MSBuildTargetProject::MSBuildTargetProject(const GeneratableProject &project, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent) + : MSBuildProject(parent) + , d(new MSBuildTargetProjectPrivate(versionInfo)) +{ + setDefaultTargets(QStringLiteral("Build")); + setToolsVersion(versionInfo.toolsVersion()); + + auto projectConfigurationsGroup = new MSBuildItemGroup(this); + projectConfigurationsGroup->setLabel(QStringLiteral("ProjectConfigurations")); + + QMapIterator<QString, qbs::Project> it(project.projects); + while (it.hasNext()) { + it.next(); + auto item = new MSBuildItem(QStringLiteral("ProjectConfiguration"), + projectConfigurationsGroup); + item->setInclude(MSBuildUtils::fullName(it.value())); + item->appendProperty(QStringLiteral("Configuration"), it.key()); + item->appendProperty(QStringLiteral("Platform"), MSBuildUtils::platform(it.value())); + } + + d->globalsPropertyGroup = new MSBuildPropertyGroup(this); + d->globalsPropertyGroup->setLabel(QStringLiteral("Globals")); + d->projectGuidProperty = new MSBuildProperty(QStringLiteral("ProjectGuid"), + QUuid::createUuid().toString(), + d->globalsPropertyGroup); + + // Trigger creation of the property sheets ImportGroup + propertySheetsImportGroup(); +} + +MSBuildTargetProject::~MSBuildTargetProject() +{ +} + +const Internal::VisualStudioVersionInfo &MSBuildTargetProject::versionInfo() const +{ + return d->versionInfo; +} + +QUuid MSBuildTargetProject::guid() const +{ + return QUuid(d->projectGuidProperty->value().toString()); +} + +void MSBuildTargetProject::setGuid(const QUuid &guid) +{ + d->projectGuidProperty->setValue(guid.toString()); +} + +MSBuildPropertyGroup *MSBuildTargetProject::globalsPropertyGroup() +{ + return d->globalsPropertyGroup; +} + +MSBuildImportGroup *MSBuildTargetProject::propertySheetsImportGroup() +{ + MSBuildImportGroup *importGroup = nullptr; + for (const auto &child : children()) { + if (auto group = qobject_cast<MSBuildImportGroup *>(child)) { + if (group->label() == QStringLiteral("PropertySheets")) { + importGroup = group; + break; + } + } + } + + if (!importGroup) { + importGroup = new MSBuildImportGroup(this); + importGroup->setLabel(QStringLiteral("PropertySheets")); + } + + return importGroup; +} + +void MSBuildTargetProject::appendPropertySheet(const QString &path, bool optional) +{ + auto import = new MSBuildImport(propertySheetsImportGroup()); + import->setProject(path); + if (optional) + import->setCondition(QStringLiteral("Exists('%1')").arg(path)); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/msbuildtargetproject.h b/src/plugins/generator/visualstudio/msbuildtargetproject.h new file mode 100644 index 000000000..13d890d72 --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildtargetproject.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDTARGETPROJECT_H +#define MSBUILDTARGETPROJECT_H + +#include "msbuild/msbuildproject.h" + +#include <generators/generatordata.h> +#include <tools/visualstudioversioninfo.h> + +namespace qbs { + +class MSBuildImportGroup; +class MSBuildPropertyGroup; +class MSBuildTargetProjectPrivate; +class VisualStudioGenerator; + +class MSBuildTargetProject : public MSBuildProject +{ + Q_OBJECT + Q_DISABLE_COPY(MSBuildTargetProject) +protected: + MSBuildTargetProject(const GeneratableProject &project, + const Internal::VisualStudioVersionInfo &versionInfo, + VisualStudioGenerator *parent = 0); + +public: + ~MSBuildTargetProject(); + + const Internal::VisualStudioVersionInfo &versionInfo() const; + + QUuid guid() const; + void setGuid(const QUuid &guid); + + MSBuildPropertyGroup *globalsPropertyGroup(); + MSBuildImportGroup *propertySheetsImportGroup(); + void appendPropertySheet(const QString &path, bool optional = false); + +private: + QScopedPointer<MSBuildTargetProjectPrivate> d; +}; + +} // namespace qbs + +#endif // MSBUILDTARGETPROJECT_H diff --git a/src/plugins/generator/visualstudio/msbuildutils.h b/src/plugins/generator/visualstudio/msbuildutils.h new file mode 100644 index 000000000..3eceeba2e --- /dev/null +++ b/src/plugins/generator/visualstudio/msbuildutils.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MSBUILDUTILS_H +#define MSBUILDUTILS_H + +#include <qbs.h> + +namespace qbs { + +class MSBuildUtils +{ +public: + static QString _qbsArchitecture(const qbs::Project &project) + { + return project.projectConfiguration() + .value(QStringLiteral("qbs")).toMap() + .value(QStringLiteral("architecture")).toString(); + } + + static const QString visualStudioArchitectureName(const QString &qbsArch, bool useDisplayName) + { + if (qbsArch == QStringLiteral("x86") && useDisplayName) + return qbsArch; + + // map of qbs architecture names to MSBuild architecture names + static const QMap<QString, QString> map { + {QStringLiteral("x86"), QStringLiteral("Win32")}, + {QStringLiteral("x86_64"), QStringLiteral("x64")}, + {QStringLiteral("ia64"), QStringLiteral("Itanium")}, + {QStringLiteral("arm"), QStringLiteral("ARM")}, + {QStringLiteral("arm64"), QStringLiteral("ARM64")} + }; + return map[qbsArch]; + } + + static QString configurationName(const qbs::Project &project) + { + return project.projectConfiguration() + .value(QStringLiteral("qbs")).toMap() + .value(QStringLiteral("configurationName")).toString(); + } + + static QString displayPlatform(const qbs::Project &project) + { + const auto architecture = _qbsArchitecture(project); + auto displayPlatform = visualStudioArchitectureName(architecture, true); + if (displayPlatform.isEmpty()) + displayPlatform = architecture; + return displayPlatform; + } + + static QString platform(const qbs::Project &project) + { + const auto architecture = _qbsArchitecture(project); + auto platform = visualStudioArchitectureName(architecture, false); + if (platform.isEmpty()) { + qWarning() << "WARNING: Unsupported architecture \"" + << architecture << "\"; using \"Win32\" platform."; + platform = QStringLiteral("Win32"); + } + + return platform; + } + + static QString fullDisplayName(const qbs::Project &project) + { + return QStringLiteral("%1|%2") + .arg(configurationName(project)) + .arg(displayPlatform(project)); + } + + static QString fullName(const qbs::Project &project) + { + return QStringLiteral("%1|%2").arg(configurationName(project)).arg(platform(project)); + } + + static QString buildTaskCondition(const Project &buildTask) + { + return QStringLiteral("'$(Configuration)|$(Platform)'=='") + + MSBuildUtils::fullName(buildTask) + + QStringLiteral("'"); + } +}; + +} // namespace qbs + +#endif // MSBUILDUTILS_H diff --git a/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.cpp b/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.cpp new file mode 100644 index 000000000..f3a6a0cbd --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ivisualstudiosolutionproject.h" + +namespace qbs { + +class IVisualStudioSolutionProjectPrivate +{ +public: + QUuid guid = QUuid::createUuid(); + QString name; + QString filePath; +}; + +IVisualStudioSolutionProject::IVisualStudioSolutionProject(QObject *parent) + : QObject(parent) + , d(new IVisualStudioSolutionProjectPrivate) +{ +} + +IVisualStudioSolutionProject::~IVisualStudioSolutionProject() +{ +} + +QUuid IVisualStudioSolutionProject::guid() const +{ + return d->guid; +} + +void IVisualStudioSolutionProject::setGuid(const QUuid &guid) +{ + d->guid = guid; +} + +QString IVisualStudioSolutionProject::name() const +{ + return d->name; +} + +void IVisualStudioSolutionProject::setName(const QString &name) +{ + d->name = name; +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.h b/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.h new file mode 100644 index 000000000..17de66e73 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/ivisualstudiosolutionproject.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IVISUALSTUDIOSOLUTIONPROJECT_H +#define IVISUALSTUDIOSOLUTIONPROJECT_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> +#include <QtCore/qstring.h> +#include <QtCore/quuid.h> + +namespace qbs { + +class IVisualStudioSolutionProjectPrivate; + +class IVisualStudioSolutionProject : public QObject +{ + Q_OBJECT +protected: + explicit IVisualStudioSolutionProject(QObject *parent = 0); + +public: + virtual ~IVisualStudioSolutionProject(); + + virtual QUuid projectTypeGuid() const = 0; + + QUuid guid() const; + void setGuid(const QUuid &guid); + + virtual QString name() const; + void setName(const QString &name); + +private: + QScopedPointer<IVisualStudioSolutionProjectPrivate> d; +}; + +} // namespace qbs + +#endif // IVISUALSTUDIOSOLUTIONPROJECT_H diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolution.cpp b/src/plugins/generator/visualstudio/solution/visualstudiosolution.cpp new file mode 100644 index 000000000..a6d572425 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolution.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudiosolution.h" + +#include "visualstudiosolutionfileproject.h" +#include "visualstudiosolutionfolderproject.h" + +#include <tools/visualstudioversioninfo.h> + +#include <QtCore/qmap.h> + +namespace qbs { + +class VisualStudioSolutionPrivate +{ +public: + VisualStudioSolutionPrivate(const Internal::VisualStudioVersionInfo &versionInfo) + : versionInfo(versionInfo) { } + const Internal::VisualStudioVersionInfo versionInfo; + QList<IVisualStudioSolutionProject *> projects; + QMap<VisualStudioSolutionFileProject *, QList<VisualStudioSolutionFileProject *>> dependencies; + QList<VisualStudioSolutionGlobalSection *> globalSections; +}; + +VisualStudioSolution::VisualStudioSolution(const Internal::VisualStudioVersionInfo &versionInfo, + QObject *parent) + : QObject(parent) + , d(new VisualStudioSolutionPrivate(versionInfo)) +{ +} + +VisualStudioSolution::~VisualStudioSolution() +{ +} + +Internal::VisualStudioVersionInfo VisualStudioSolution::versionInfo() const +{ + return d->versionInfo; +} + +QList<IVisualStudioSolutionProject *> VisualStudioSolution::projects() const +{ + return d->projects; +} + +QList<VisualStudioSolutionFileProject *> VisualStudioSolution::fileProjects() const +{ + QList<VisualStudioSolutionFileProject *> list; + for (const auto &project : d->projects) + if (auto fileProject = qobject_cast<VisualStudioSolutionFileProject *>(project)) + list.append(fileProject); + return list; +} + +QList<VisualStudioSolutionFolderProject *> VisualStudioSolution::folderProjects() const +{ + QList<VisualStudioSolutionFolderProject *> list; + for (const auto &project : d->projects) + if (auto folderProject = qobject_cast<VisualStudioSolutionFolderProject *>(project)) + list.append(folderProject); + return list; +} + +void VisualStudioSolution::appendProject(IVisualStudioSolutionProject *project) +{ + d->projects.append(project); +} + +QList<VisualStudioSolutionFileProject *> VisualStudioSolution::dependencies( + VisualStudioSolutionFileProject *project) const +{ + return d->dependencies.value(project); +} + +void VisualStudioSolution::addDependency(VisualStudioSolutionFileProject *project, + VisualStudioSolutionFileProject *dependency) +{ + d->dependencies[project].append(dependency); +} + +QList<VisualStudioSolutionGlobalSection *> VisualStudioSolution::globalSections() const +{ + return d->globalSections; +} + +void VisualStudioSolution::appendGlobalSection(VisualStudioSolutionGlobalSection *globalSection) +{ + d->globalSections.append(globalSection); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolution.h b/src/plugins/generator/visualstudio/solution/visualstudiosolution.h new file mode 100644 index 000000000..16f06f9e9 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolution.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOSOLUTION_H +#define VISUALSTUDIOSOLUTION_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> + +namespace qbs { + +namespace Internal { class VisualStudioVersionInfo; } + +class MSBuildProject; + +class IVisualStudioSolutionProject; +class VisualStudioSolutionFileProject; +class VisualStudioSolutionFolderProject; +class VisualStudioSolutionGlobalSection; + +class VisualStudioSolutionPrivate; + +class VisualStudioSolution : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(VisualStudioSolution) +public: + explicit VisualStudioSolution(const Internal::VisualStudioVersionInfo &versionInfo, + QObject *parent = 0); + ~VisualStudioSolution(); + + Internal::VisualStudioVersionInfo versionInfo() const; + + QList<IVisualStudioSolutionProject *> projects() const; + QList<VisualStudioSolutionFileProject *> fileProjects() const; + QList<VisualStudioSolutionFolderProject *> folderProjects() const; + void appendProject(IVisualStudioSolutionProject *project); + void removeProject(const IVisualStudioSolutionProject *project); + void clearProjects(); + + QList<VisualStudioSolutionFileProject *> dependencies( + VisualStudioSolutionFileProject *project) const; + void addDependency(VisualStudioSolutionFileProject *project, + VisualStudioSolutionFileProject *dependency); + + QList<VisualStudioSolutionGlobalSection *> globalSections() const; + void appendGlobalSection(VisualStudioSolutionGlobalSection *globalSection); + +private: + void addDefaultGlobalSections(); + + QScopedPointer<VisualStudioSolutionPrivate> d; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOSOLUTION_H diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.cpp b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.cpp new file mode 100644 index 000000000..d66f47cf7 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudiosolutionfileproject.h" + +#include <QtCore/qfileinfo.h> + +namespace qbs { + +class VisualStudioSolutionFileProjectPrivate +{ +public: + QString filePath; +}; + +VisualStudioSolutionFileProject::VisualStudioSolutionFileProject(const QString &filePath, + QObject *parent) + : IVisualStudioSolutionProject(parent) + , d(new VisualStudioSolutionFileProjectPrivate) +{ + setFilePath(filePath); +} + +VisualStudioSolutionFileProject::~VisualStudioSolutionFileProject() +{ +} + +QString VisualStudioSolutionFileProject::name() const +{ + const auto projectName = IVisualStudioSolutionProject::name(); + if (projectName.isEmpty()) + return QFileInfo(filePath()).baseName(); + return projectName; +} + +QUuid VisualStudioSolutionFileProject::projectTypeGuid() const +{ + return QStringLiteral("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"); // C++ +} + +QString VisualStudioSolutionFileProject::filePath() const +{ + return d->filePath; +} + +void VisualStudioSolutionFileProject::setFilePath(const QString &filePath) +{ + d->filePath = filePath; +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.h b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.h new file mode 100644 index 000000000..fafafa494 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfileproject.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOSOLUTIONFILEPROJECT_H +#define VISUALSTUDIOSOLUTIONFILEPROJECT_H + +#include <QtCore/qobject.h> +#include "ivisualstudiosolutionproject.h" + +namespace qbs { + +class VisualStudioSolutionFileProjectPrivate; + +class VisualStudioSolutionFileProject : public IVisualStudioSolutionProject +{ + Q_OBJECT +public: + explicit VisualStudioSolutionFileProject(const QString &filePath, QObject *parent = 0); + ~VisualStudioSolutionFileProject(); + + QString name() const override; + + QString filePath() const; + void setFilePath(const QString &filePath); + + QUuid projectTypeGuid() const override; + +private: + QScopedPointer<VisualStudioSolutionFileProjectPrivate> d; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOSOLUTIONFILEPROJECT_H diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.cpp b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.cpp new file mode 100644 index 000000000..d59d1e1ed --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudiosolutionfolderproject.h" + +#include <QtCore/qfileinfo.h> + +namespace qbs { + +VisualStudioSolutionFolderProject::VisualStudioSolutionFolderProject(QObject *parent) + : IVisualStudioSolutionProject(parent) +{ +} + +QUuid VisualStudioSolutionFolderProject::projectTypeGuid() const +{ + return QStringLiteral("{2150E333-8FDC-42A3-9474-1A3956D46DE8}"); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.h b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.h new file mode 100644 index 000000000..a7fd180cc --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionfolderproject.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOSOLUTIONFOLDERPROJECT_H +#define VISUALSTUDIOSOLUTIONFOLDERPROJECT_H + +#include <QtCore/qobject.h> +#include "ivisualstudiosolutionproject.h" + +namespace qbs { + +class VisualStudioSolutionFolderProject : public IVisualStudioSolutionProject +{ + Q_OBJECT +public: + explicit VisualStudioSolutionFolderProject(QObject *parent); + + QUuid projectTypeGuid() const override; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOSOLUTIONFOLDERPROJECT_H diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.cpp b/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.cpp new file mode 100644 index 000000000..1e4f5fd01 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudiosolutionglobalsection.h" + +#include <utility> +#include <vector> + +namespace qbs { + +class VisualStudioSolutionGlobalSectionPrivate +{ +public: + QString name; + std::vector<std::pair<QString, QString>> properties; + bool post = false; +}; + +VisualStudioSolutionGlobalSection::VisualStudioSolutionGlobalSection(const QString &name, + QObject *parent) + : QObject(parent) + , d(new VisualStudioSolutionGlobalSectionPrivate) +{ + setName(name); +} + +VisualStudioSolutionGlobalSection::~VisualStudioSolutionGlobalSection() +{ +} + +QString VisualStudioSolutionGlobalSection::name() const +{ + return d->name; +} + +void VisualStudioSolutionGlobalSection::setName(const QString &name) +{ + d->name = name; +} + +bool VisualStudioSolutionGlobalSection::isPost() const +{ + return d->post; +} + +void VisualStudioSolutionGlobalSection::setPost(bool post) +{ + d->post = post; +} + +std::vector<std::pair<QString, QString> > VisualStudioSolutionGlobalSection::properties() const +{ + return d->properties; +} + +void VisualStudioSolutionGlobalSection::appendProperty(const QString &key, const QString &value) +{ + d->properties.push_back({ key, value }); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.h b/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.h new file mode 100644 index 000000000..dd821fce0 --- /dev/null +++ b/src/plugins/generator/visualstudio/solution/visualstudiosolutionglobalsection.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOSOLUTIONGLOBALSECTION_H +#define VISUALSTUDIOSOLUTIONGLOBALSECTION_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> + +namespace qbs { + +class VisualStudioSolutionGlobalSectionPrivate; + +class VisualStudioSolutionGlobalSection : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(VisualStudioSolutionGlobalSection) +public: + explicit VisualStudioSolutionGlobalSection(const QString &name, QObject *parent = 0); + ~VisualStudioSolutionGlobalSection(); + + QString name() const; + void setName(const QString &name); + + bool isPost() const; + void setPost(bool post); + + std::vector<std::pair<QString, QString> > properties() const; + void appendProperty(const QString &key, const QString &value); + +private: + QScopedPointer<VisualStudioSolutionGlobalSectionPrivate> d; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOSOLUTIONGLOBALSECTION_H diff --git a/src/plugins/generator/visualstudio/visualstudio.pro b/src/plugins/generator/visualstudio/visualstudio.pro new file mode 100644 index 000000000..7f464f1ce --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudio.pro @@ -0,0 +1,94 @@ +include(../../plugins.pri) + +TARGET = visualstudiogenerator + +QT = core + +HEADERS += \ + $$PWD/msbuildfiltersproject.h \ + $$PWD/msbuildqbsgenerateproject.h \ + $$PWD/msbuildqbsproductproject.h \ + $$PWD/msbuildsharedsolutionpropertiesproject.h \ + $$PWD/msbuildsolutionpropertiesproject.h \ + $$PWD/msbuildtargetproject.h \ + $$PWD/msbuildutils.h \ + $$PWD/visualstudiogenerator.h \ + $$PWD/visualstudioguidpool.h + +SOURCES += \ + $$PWD/msbuildfiltersproject.cpp \ + $$PWD/msbuildqbsgenerateproject.cpp \ + $$PWD/msbuildqbsproductproject.cpp \ + $$PWD/msbuildsharedsolutionpropertiesproject.cpp \ + $$PWD/msbuildsolutionpropertiesproject.cpp \ + $$PWD/msbuildtargetproject.cpp \ + $$PWD/visualstudiogenerator.cpp \ + $$PWD/visualstudiogeneratorplugin.cpp \ + $$PWD/visualstudioguidpool.cpp + +HEADERS += \ + $$PWD/solution/ivisualstudiosolutionproject.h \ + $$PWD/solution/visualstudiosolutionfileproject.h \ + $$PWD/solution/visualstudiosolutionfolderproject.h \ + $$PWD/solution/visualstudiosolution.h \ + $$PWD/solution/visualstudiosolutionglobalsection.h \ + +SOURCES += \ + $$PWD/solution/ivisualstudiosolutionproject.cpp \ + $$PWD/solution/visualstudiosolutionfileproject.cpp \ + $$PWD/solution/visualstudiosolutionfolderproject.cpp \ + $$PWD/solution/visualstudiosolution.cpp \ + $$PWD/solution/visualstudiosolutionglobalsection.cpp + +HEADERS += \ + $$PWD/msbuild/imsbuildgroup.h \ + $$PWD/msbuild/imsbuildnode.h \ + $$PWD/msbuild/imsbuildnodevisitor.h \ + $$PWD/msbuild/imsbuildproperty.h \ + $$PWD/msbuild/msbuildimport.h \ + $$PWD/msbuild/msbuildimportgroup.h \ + $$PWD/msbuild/msbuilditem.h \ + $$PWD/msbuild/msbuilditemdefinitiongroup.h \ + $$PWD/msbuild/msbuilditemgroup.h \ + $$PWD/msbuild/msbuilditemmetadata.h \ + $$PWD/msbuild/msbuildproject.h \ + $$PWD/msbuild/msbuildproperty.h \ + $$PWD/msbuild/msbuildpropertygroup.h + +SOURCES += \ + $$PWD/msbuild/imsbuildgroup.cpp \ + $$PWD/msbuild/imsbuildnode.cpp \ + $$PWD/msbuild/imsbuildproperty.cpp \ + $$PWD/msbuild/msbuildimport.cpp \ + $$PWD/msbuild/msbuildimportgroup.cpp \ + $$PWD/msbuild/msbuilditem.cpp \ + $$PWD/msbuild/msbuilditemdefinitiongroup.cpp \ + $$PWD/msbuild/msbuilditemgroup.cpp \ + $$PWD/msbuild/msbuilditemmetadata.cpp \ + $$PWD/msbuild/msbuildproject.cpp \ + $$PWD/msbuild/msbuildproperty.cpp \ + $$PWD/msbuild/msbuildpropertygroup.cpp + +HEADERS += \ + $$PWD/msbuild/items/msbuildclcompile.h \ + $$PWD/msbuild/items/msbuildclinclude.h \ + $$PWD/msbuild/items/msbuildfileitem.h \ + $$PWD/msbuild/items/msbuildfilter.h \ + $$PWD/msbuild/items/msbuildlink.h \ + $$PWD/msbuild/items/msbuildnone.h + +SOURCES += \ + $$PWD/msbuild/items/msbuildclcompile.cpp \ + $$PWD/msbuild/items/msbuildclinclude.cpp \ + $$PWD/msbuild/items/msbuildfileitem.cpp \ + $$PWD/msbuild/items/msbuildfilter.cpp \ + $$PWD/msbuild/items/msbuildlink.cpp \ + $$PWD/msbuild/items/msbuildnone.cpp + +HEADERS += \ + $$PWD/io/msbuildprojectwriter.h \ + $$PWD/io/visualstudiosolutionwriter.h + +SOURCES += \ + $$PWD/io/msbuildprojectwriter.cpp \ + $$PWD/io/visualstudiosolutionwriter.cpp diff --git a/src/plugins/generator/visualstudio/visualstudio.qbs b/src/plugins/generator/visualstudio/visualstudio.qbs new file mode 100644 index 000000000..cb22ea5d9 --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudio.qbs @@ -0,0 +1,106 @@ +import qbs +import "../../qbsplugin.qbs" as QbsPlugin + +QbsPlugin { + name: "visualstudiogenerator" + + files: ["visualstudiogeneratorplugin.cpp"] + + Group { + name: "Visual Studio generator" + files: [ + "msbuildfiltersproject.cpp", + "msbuildfiltersproject.h", + "msbuildqbsgenerateproject.cpp", + "msbuildqbsgenerateproject.h", + "msbuildqbsproductproject.cpp", + "msbuildqbsproductproject.h", + "msbuildsharedsolutionpropertiesproject.cpp", + "msbuildsharedsolutionpropertiesproject.h", + "msbuildsolutionpropertiesproject.cpp", + "msbuildsolutionpropertiesproject.h", + "msbuildtargetproject.cpp", + "msbuildtargetproject.h", + "msbuildutils.h", + "visualstudiogenerator.cpp", + "visualstudiogenerator.h", + "visualstudioguidpool.cpp", + "visualstudioguidpool.h", + ] + } + Group { + name: "Solution Object Model" + prefix: "solution/" + files: [ + "ivisualstudiosolutionproject.cpp", + "ivisualstudiosolutionproject.h", + "visualstudiosolutionfileproject.cpp", + "visualstudiosolutionfileproject.h", + "visualstudiosolutionfolderproject.cpp", + "visualstudiosolutionfolderproject.h", + "visualstudiosolution.cpp", + "visualstudiosolution.h", + "visualstudiosolutionglobalsection.cpp", + "visualstudiosolutionglobalsection.h", + ] + } + Group { + name: "MSBuild Object Model" + prefix: "msbuild/" + files: [ + "imsbuildgroup.cpp", + "imsbuildgroup.h", + "imsbuildnode.cpp", + "imsbuildnode.h", + "imsbuildnodevisitor.h", + "imsbuildproperty.cpp", + "imsbuildproperty.h", + "msbuildimport.cpp", + "msbuildimport.h", + "msbuildimportgroup.cpp", + "msbuildimportgroup.h", + "msbuilditem.cpp", + "msbuilditem.h", + "msbuilditemdefinitiongroup.cpp", + "msbuilditemdefinitiongroup.h", + "msbuilditemgroup.cpp", + "msbuilditemgroup.h", + "msbuilditemmetadata.cpp", + "msbuilditemmetadata.h", + "msbuildproject.cpp", + "msbuildproject.h", + "msbuildproperty.cpp", + "msbuildproperty.h", + "msbuildpropertygroup.cpp", + "msbuildpropertygroup.h", + ] + } + Group { + name: "MSBuild Object Model Items" + prefix: "msbuild/items/" + files: [ + "msbuildclcompile.cpp", + "msbuildclcompile.h", + "msbuildclinclude.cpp", + "msbuildclinclude.h", + "msbuildfileitem.cpp", + "msbuildfileitem.h", + "msbuildfilter.cpp", + "msbuildfilter.h", + "msbuildlink.cpp", + "msbuildlink.h", + "msbuildnone.cpp", + "msbuildnone.h", + ] + } + Group { + name: "Visual Studio Object Model I/O" + prefix: "io/" + files: [ + "msbuildprojectwriter.cpp", + "msbuildprojectwriter.h", + "visualstudiosolutionwriter.cpp", + "visualstudiosolutionwriter.h", + ] + } +} diff --git a/src/plugins/generator/visualstudio/visualstudiogenerator.cpp b/src/plugins/generator/visualstudio/visualstudiogenerator.cpp new file mode 100644 index 000000000..4b3667140 --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudiogenerator.cpp @@ -0,0 +1,365 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "msbuildfiltersproject.h" +#include "msbuildqbsgenerateproject.h" +#include "msbuildsharedsolutionpropertiesproject.h" +#include "msbuildsolutionpropertiesproject.h" +#include "msbuildqbsproductproject.h" +#include "msbuildutils.h" +#include "visualstudiogenerator.h" +#include "visualstudioguidpool.h" + +#include "msbuild/msbuildpropertygroup.h" +#include "msbuild/msbuildproject.h" + +#include "solution/visualstudiosolution.h" +#include "solution/visualstudiosolutionfileproject.h" +#include "solution/visualstudiosolutionglobalsection.h" +#include "solution/visualstudiosolutionfolderproject.h" + +#include "io/msbuildprojectwriter.h" +#include "io/visualstudiosolutionwriter.h" + +#include <generators/generatableprojectiterator.h> +#include <logging/translator.h> +#include <tools/filesaver.h> +#include <tools/qbsassert.h> +#include <tools/shellutils.h> +#include <tools/visualstudioversioninfo.h> + +#include <QtCore/qcoreapplication.h> +#include <QtCore/qdebug.h> +#include <QtCore/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qfileinfo.h> + +namespace qbs { + +using namespace Internal; + +class VisualStudioGeneratorPrivate +{ + friend class SolutionDependenciesVisitor; +public: + VisualStudioGeneratorPrivate(const Internal::VisualStudioVersionInfo &versionInfo) + : versionInfo(versionInfo) {} + + Internal::VisualStudioVersionInfo versionInfo; + + std::shared_ptr<VisualStudioGuidPool> guidPool; + std::shared_ptr<VisualStudioSolution> solution; + QString solutionFilePath; + QMap<QString, std::shared_ptr<MSBuildProject>> msbuildProjects; + QMap<QString, VisualStudioSolutionFileProject *> solutionProjects; + QMap<GeneratableProjectData::Id, VisualStudioSolutionFolderProject *> solutionFolders; + QList<std::pair<QString, bool>> propertySheetNames; + + void reset(); +}; + +void VisualStudioGeneratorPrivate::reset() +{ + guidPool.reset(); + solution.reset(); + solutionFilePath.clear(); + msbuildProjects.clear(); + solutionProjects.clear(); + solutionFolders.clear(); + propertySheetNames.clear(); +} + +class SolutionDependenciesVisitor : public IGeneratableProjectVisitor +{ +public: + SolutionDependenciesVisitor(VisualStudioGenerator *generator) + : generator(generator) { + } + + void visitProject(const GeneratableProject &project) override { + Q_UNUSED(project); + nestedProjects = new VisualStudioSolutionGlobalSection( + QStringLiteral("NestedProjects"), generator->d->solution.get()); + generator->d->solution->appendGlobalSection(nestedProjects); + } + + void visitProjectData(const GeneratableProject &project, + const GeneratableProjectData &parentProjectData, + const GeneratableProjectData &projectData) override { + Q_UNUSED(project); + // The root project will have a null GeneratableProjectData + // as its parent object (so skip giving it a parent folder) + if (!parentProjectData.name().isEmpty()) { + nestedProjects->appendProperty( + generator->d->solutionFolders.value(projectData.uniqueName())->guid() + .toString(), + generator->d->solutionFolders.value(parentProjectData.uniqueName())->guid() + .toString()); + } + } + + void visitProduct(const GeneratableProject &project, + const GeneratableProjectData &projectData, + const GeneratableProductData &productData) override { + Q_UNUSED(project); + Q_UNUSED(projectData); + for (const auto &dep : productData.dependencies()) { + generator->d->solution->addDependency( + generator->d->solutionProjects.value(productData.name()), + generator->d->solutionProjects.value(dep)); + } + + nestedProjects->appendProperty( + generator->d->solutionProjects.value(productData.name())->guid().toString(), + generator->d->solutionFolders.value(projectData.uniqueName())->guid() + .toString()); + } + +private: + VisualStudioGenerator *generator; + VisualStudioSolutionGlobalSection *nestedProjects; +}; + +VisualStudioGenerator::VisualStudioGenerator(const VisualStudioVersionInfo &versionInfo) + : d(new VisualStudioGeneratorPrivate(versionInfo)) +{ + if (d->versionInfo.usesVcBuild()) + throw ErrorInfo(Tr::tr("VCBuild (Visual Studio 2008 and below) is not supported")); + else if (!d->versionInfo.usesMsBuild()) + throw ErrorInfo(Tr::tr("Unknown/unsupported build engine")); + Q_ASSERT(d->versionInfo.usesSolutions()); +} + +VisualStudioGenerator::~VisualStudioGenerator() +{ +} + +QString VisualStudioGenerator::generatorName() const +{ + return QStringLiteral("visualstudio%1").arg(d->versionInfo.marketingVersion()); +} + +void VisualStudioGenerator::addPropertySheets(const GeneratableProject &project) +{ + { + const auto fileName = QStringLiteral("qbs.props"); + d->propertySheetNames.append({ fileName, true }); + d->msbuildProjects.insert(project.baseBuildDirectory().absoluteFilePath(fileName), + std::make_shared<MSBuildSolutionPropertiesProject>( + d->versionInfo, project, + qbsExecutableFilePath(), qbsSettingsDir())); + } + + { + const auto fileName = QStringLiteral("qbs-shared.props"); + d->propertySheetNames.append({ fileName, false }); + d->msbuildProjects.insert(project.baseBuildDirectory().absoluteFilePath(fileName), + std::make_shared<MSBuildSharedSolutionPropertiesProject>( + d->versionInfo, project, + qbsExecutableFilePath(), qbsSettingsDir())); + } +} + +void VisualStudioGenerator::addPropertySheets( + const std::shared_ptr<MSBuildTargetProject> &targetProject) +{ + for (const auto &pair : d->propertySheetNames) { + targetProject->appendPropertySheet( + QStringLiteral("$(SolutionDir)\\") + pair.first, pair.second); + } +} + +static QString targetFilePath(const QString &baseName, const QString &baseBuildDirectory) +{ + return QDir(baseBuildDirectory).absoluteFilePath(baseName + QStringLiteral(".vcxproj")); +} + +static QString targetFilePath(const GeneratableProductData &product, + const QString &baseBuildDirectory) +{ + return targetFilePath(product.name(), baseBuildDirectory); +} + +static void addDefaultGlobalSections(const GeneratableProject &topLevelProject, + VisualStudioSolution *solution) +{ + auto configurationPlatformsSection = new VisualStudioSolutionGlobalSection( + QStringLiteral("SolutionConfigurationPlatforms"), solution); + solution->appendGlobalSection(configurationPlatformsSection); + for (const auto &qbsProject : topLevelProject.projects) + configurationPlatformsSection->appendProperty(MSBuildUtils::fullName(qbsProject), + MSBuildUtils::fullName(qbsProject)); + + auto projectConfigurationPlatformsSection = new VisualStudioSolutionGlobalSection( + QStringLiteral("ProjectConfigurationPlatforms"), solution); + solution->appendGlobalSection(projectConfigurationPlatformsSection); + projectConfigurationPlatformsSection->setPost(true); + for (const auto project : solution->projects()) { + for (const auto &qbsProject : topLevelProject.projects) { + projectConfigurationPlatformsSection->appendProperty( + QStringLiteral("%1.%2.ActiveCfg") + .arg(project->guid().toString()) + .arg(MSBuildUtils::fullDisplayName(qbsProject)), + MSBuildUtils::fullName(qbsProject)); + projectConfigurationPlatformsSection->appendProperty( + QStringLiteral("%1.%2.Build.0") + .arg(project->guid().toString()) + .arg(MSBuildUtils::fullDisplayName(qbsProject)), + MSBuildUtils::fullName(qbsProject)); + } + } + + auto solutionPropsSection = new VisualStudioSolutionGlobalSection( + QStringLiteral("SolutionProperties"), solution); + solution->appendGlobalSection(solutionPropsSection); + solutionPropsSection->appendProperty(QStringLiteral("HideSolutionNode"), + QStringLiteral("FALSE")); +} + +static void writeProjectFiles(const QMap<QString, std::shared_ptr<MSBuildProject>> &projects) +{ + // Write out all the MSBuild project files to disk + QMapIterator<QString, std::shared_ptr<MSBuildProject>> it(projects); + while (it.hasNext()) { + it.next(); + const auto projectFilePath = it.key(); + Internal::FileSaver file(projectFilePath); + if (!file.open()) + throw ErrorInfo(Tr::tr("Cannot open %s for writing").arg(projectFilePath)); + + std::shared_ptr<MSBuildProject> project = it.value(); + MSBuildProjectWriter writer(file.device()); + if (!(writer.write(project.get()) && file.commit())) + throw ErrorInfo(Tr::tr("Failed to generate %1").arg(projectFilePath)); + } +} + +static void writeSolution(const std::shared_ptr<VisualStudioSolution> &solution, + const QString &solutionFilePath) +{ + Internal::FileSaver file(solutionFilePath); + if (!file.open()) + throw ErrorInfo(Tr::tr("Cannot open %s for writing").arg(solutionFilePath)); + + VisualStudioSolutionWriter writer(file.device()); + writer.setProjectBaseDirectory(QFileInfo(solutionFilePath).path()); + if (!(writer.write(solution.get()) && file.commit())) + throw ErrorInfo(Tr::tr("Failed to generate %1").arg(solutionFilePath)); + + qDebug() << "Generated" << qPrintable(QFileInfo(solutionFilePath).fileName()); +} + +void VisualStudioGenerator::generate() +{ + GeneratableProjectIterator it(project()); + it.accept(this); + + addDefaultGlobalSections(project(), d->solution.get()); + + // Second pass: connection solution project interdependencies and project nesting hierarchy + SolutionDependenciesVisitor solutionDependenciesVisitor(this); + it.accept(&solutionDependenciesVisitor); + + writeProjectFiles(d->msbuildProjects); + writeSolution(d->solution, d->solutionFilePath); + + d->reset(); +} + +void VisualStudioGenerator::visitProject(const GeneratableProject &project) +{ + addPropertySheets(project); + + const auto buildDir = project.baseBuildDirectory(); + + d->guidPool = std::make_shared<VisualStudioGuidPool>( + buildDir.absoluteFilePath(project.name() + QStringLiteral(".guid.txt"))); + + d->solutionFilePath = buildDir.absoluteFilePath(project.name() + QStringLiteral(".sln")); + d->solution = std::make_shared<VisualStudioSolution>(d->versionInfo); + + // Create a helper project to re-run qbs generate + const auto qbsGenerate = QStringLiteral("qbs-generate"); + const auto projectFilePath = targetFilePath(qbsGenerate, buildDir.absolutePath()); + const auto relativeProjectFilePath = QFileInfo(d->solutionFilePath).dir() + .relativeFilePath(projectFilePath); + auto targetProject = std::make_shared<MSBuildQbsGenerateProject>(project, d->versionInfo); + targetProject->setGuid(d->guidPool->drawProductGuid(relativeProjectFilePath)); + d->msbuildProjects.insert(projectFilePath, targetProject); + + addPropertySheets(targetProject); + + auto solutionProject = new VisualStudioSolutionFileProject( + targetFilePath(qbsGenerate, project.baseBuildDirectory().absolutePath()), + d->solution.get()); + solutionProject->setGuid(targetProject->guid()); + d->solution->appendProject(solutionProject); + d->solutionProjects.insert(qbsGenerate, solutionProject); +} + +void VisualStudioGenerator::visitProjectData(const GeneratableProject &project, + const GeneratableProjectData &projectData) +{ + Q_UNUSED(project); + auto solutionFolder = new VisualStudioSolutionFolderProject(d->solution.get()); + solutionFolder->setName(projectData.name()); + d->solution->appendProject(solutionFolder); + QBS_CHECK(!d->solutionFolders.contains(projectData.uniqueName())); + d->solutionFolders.insert(projectData.uniqueName(), solutionFolder); +} + +void VisualStudioGenerator::visitProduct(const GeneratableProject &project, + const GeneratableProjectData &projectData, + const GeneratableProductData &productData) +{ + Q_UNUSED(projectData); + const auto projectFilePath = targetFilePath(productData, + project.baseBuildDirectory().absolutePath()); + const auto relativeProjectFilePath = QFileInfo(d->solutionFilePath) + .dir().relativeFilePath(projectFilePath); + auto targetProject = std::make_shared<MSBuildQbsProductProject>(project, productData, + d->versionInfo); + targetProject->setGuid(d->guidPool->drawProductGuid(relativeProjectFilePath)); + + addPropertySheets(targetProject); + + d->msbuildProjects.insert(projectFilePath, targetProject); + d->msbuildProjects.insert(projectFilePath + QStringLiteral(".filters"), + std::make_shared<MSBuildFiltersProject>(productData)); + + auto solutionProject = new VisualStudioSolutionFileProject( + targetFilePath(productData, project.baseBuildDirectory().absolutePath()), + d->solution.get()); + solutionProject->setGuid(targetProject->guid()); + d->solution->appendProject(solutionProject); + d->solutionProjects.insert(productData.name(), solutionProject); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/visualstudiogenerator.h b/src/plugins/generator/visualstudio/visualstudiogenerator.h new file mode 100644 index 000000000..8e120d5cc --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudiogenerator.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QBS_VISUALSTUDIOGENERATOR_H +#define QBS_VISUALSTUDIOGENERATOR_H + +#include <generators/generator.h> +#include <generators/igeneratableprojectvisitor.h> +#include <tools/visualstudioversioninfo.h> +#include "visualstudioguidpool.h" + +#include <QtCore/qfileinfo.h> +#include <QtCore/qdir.h> +#include <QtCore/qmap.h> + +namespace qbs { + +namespace Internal { class VisualStudioVersionInfo; } + +class MSBuildProject; +class MSBuildTargetProject; + +class VisualStudioGeneratorPrivate; +class VisualStudioSolution; +class VisualStudioSolutionFileProject; +class VisualStudioSolutionFolderProject; + +class VisualStudioGenerator : public ProjectGenerator, private IGeneratableProjectVisitor +{ + friend class SolutionDependenciesVisitor; +public: + explicit VisualStudioGenerator(const Internal::VisualStudioVersionInfo &versionInfo); + ~VisualStudioGenerator(); + QString generatorName() const override; + void generate() override; + +private: + virtual void visitProject(const GeneratableProject &project) override; + virtual void visitProjectData(const GeneratableProject &project, + const GeneratableProjectData &projectData) override; + virtual void visitProduct(const GeneratableProject &project, + const GeneratableProjectData &projectData, + const GeneratableProductData &productData) override; + + void addPropertySheets(const GeneratableProject &project); + void addPropertySheets(const std::shared_ptr<MSBuildTargetProject> &targetProject); + + QScopedPointer<VisualStudioGeneratorPrivate> d; +}; + +} // namespace qbs + +#endif // QBS_VISUALSTUDIOGENERATOR_H diff --git a/src/plugins/generator/visualstudio/visualstudiogeneratorplugin.cpp b/src/plugins/generator/visualstudio/visualstudiogeneratorplugin.cpp new file mode 100644 index 000000000..9907c27f7 --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudiogeneratorplugin.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** 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. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "visualstudiogenerator.h" + +#include <tools/projectgeneratormanager.h> +#include <tools/qbspluginmanager.h> + +static void QbsVisualStudioGeneratorPluginLoad() +{ + for (const auto &info : qbs::Internal::VisualStudioVersionInfo::knownVersions()) { + if (info.usesMsBuild()) + qbs::ProjectGeneratorManager::registerGenerator( + std::make_shared<qbs::VisualStudioGenerator>(info)); + } +} + +static void QbsVisualStudioGeneratorPluginUnload() +{ +} + +#ifndef GENERATOR_EXPORT +#if defined(WIN32) || defined(_WIN32) +#define GENERATOR_EXPORT __declspec(dllexport) +#else +#define GENERATOR_EXPORT __attribute__((visibility("default"))) +#endif +#endif + +QBS_REGISTER_STATIC_PLUGIN(extern "C" GENERATOR_EXPORT, QbsVisualStudioGeneratorPlugin, + QbsVisualStudioGeneratorPluginLoad, QbsVisualStudioGeneratorPluginUnload) diff --git a/src/plugins/generator/visualstudio/visualstudioguidpool.cpp b/src/plugins/generator/visualstudio/visualstudioguidpool.cpp new file mode 100644 index 000000000..543d64063 --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudioguidpool.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "visualstudioguidpool.h" +#include <tools/filesaver.h> +#include <QtCore/qfile.h> +#include <QtCore/qjsondocument.h> +#include <QtCore/qmap.h> +#include <QtCore/qvariant.h> + +namespace qbs { + +class VisualStudioGuidPoolPrivate +{ +public: + QString storeFilePath; + QMap<QString, QUuid> productGuids; +}; + +VisualStudioGuidPool::VisualStudioGuidPool(const QString &storeFilePath) + : d(new VisualStudioGuidPoolPrivate) +{ + // Read any existing GUIDs from the on-disk store + QFile file(d->storeFilePath = storeFilePath); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + const auto data = QJsonDocument::fromJson(file.readAll()).toVariant().toMap(); + + QMapIterator<QString, QVariant> it = data; + while (it.hasNext()) { + it.next(); + d->productGuids.insert(it.key(), QUuid(it.value().toString())); + } + } +} + +VisualStudioGuidPool::~VisualStudioGuidPool() +{ + Internal::FileSaver file(d->storeFilePath); + if (file.open()) { + QVariantMap productData; + QMapIterator<QString, QUuid> it(d->productGuids); + while (it.hasNext()) { + it.next(); + productData.insert(it.key(), it.value().toString()); + } + + file.write(QJsonDocument::fromVariant(productData).toJson()); + file.commit(); + } +} + +QUuid VisualStudioGuidPool::drawProductGuid(const QString &productName) +{ + if (!d->productGuids.contains(productName)) + d->productGuids.insert(productName, QUuid::createUuid()); + return d->productGuids.value(productName); +} + +} // namespace qbs diff --git a/src/plugins/generator/visualstudio/visualstudioguidpool.h b/src/plugins/generator/visualstudio/visualstudioguidpool.h new file mode 100644 index 000000000..a21bb1f94 --- /dev/null +++ b/src/plugins/generator/visualstudio/visualstudioguidpool.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef VISUALSTUDIOGUIDPOOL_H +#define VISUALSTUDIOGUIDPOOL_H + +#include <QtCore/qobject.h> +#include <QtCore/qscopedpointer.h> +#include <QtCore/quuid.h> + +namespace qbs { + +class VisualStudioGuidPoolPrivate; + +/*! + * Provides persistent storage for GUIDs related to Visual Studio project file nodes. + * These are stored on disk separately from project files and so allow projects to be + * regenerated while retaining the same GUIDs. This helps avoid unnecessary project + * reloads in Visual Studio, and helps ease source control usage. + */ +class VisualStudioGuidPool +{ +public: + explicit VisualStudioGuidPool(const QString &storeFilePath); + ~VisualStudioGuidPool(); + + QUuid drawProductGuid(const QString &productName); + +private: + QScopedPointer<VisualStudioGuidPoolPrivate> d; +}; + +} // namespace qbs + +#endif // VISUALSTUDIOGUIDPOOL_H |