2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 Alexis Jeandet.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
#pragma once
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-06-24 09:44:55 +02:00
|
|
|
#include <utils/algorithm.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
#include <utils/fileutils.h>
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-06-24 09:44:55 +02:00
|
|
|
#include <QDir>
|
2020-05-01 18:20:56 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-06-24 09:44:55 +02:00
|
|
|
inline QStringList cleanPath(QStringList &&paths)
|
|
|
|
|
{
|
|
|
|
|
return Utils::transform(paths, QDir::cleanPath);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
struct Target
|
|
|
|
|
{
|
|
|
|
|
enum class Type {
|
|
|
|
|
executable,
|
|
|
|
|
run,
|
|
|
|
|
custom,
|
|
|
|
|
sharedLibrary,
|
|
|
|
|
sharedModule,
|
|
|
|
|
staticLibrary,
|
|
|
|
|
jar,
|
|
|
|
|
unknown
|
|
|
|
|
};
|
|
|
|
|
struct SourceGroup
|
|
|
|
|
{
|
|
|
|
|
const QString language;
|
|
|
|
|
const QStringList compiler;
|
|
|
|
|
const QStringList parameters;
|
|
|
|
|
const QStringList sources;
|
|
|
|
|
const QStringList generatedSources;
|
|
|
|
|
SourceGroup(QString &&language,
|
|
|
|
|
QStringList &&compiler,
|
|
|
|
|
QStringList &¶meters,
|
|
|
|
|
QStringList &&sources,
|
|
|
|
|
QStringList &&generatedSources)
|
|
|
|
|
: language{std::move(language)}
|
|
|
|
|
, compiler{std::move(compiler)}
|
|
|
|
|
, parameters{std::move(parameters)}
|
2020-06-24 09:44:55 +02:00
|
|
|
, sources{cleanPath(std::move(sources))}
|
|
|
|
|
, generatedSources{cleanPath(std::move(generatedSources))}
|
2020-05-01 18:20:56 +02:00
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
using SourceGroupList = std::vector<SourceGroup>;
|
|
|
|
|
const Type type;
|
|
|
|
|
const QString name;
|
|
|
|
|
const QString id;
|
|
|
|
|
const QString definedIn;
|
|
|
|
|
const QStringList fileName;
|
2020-10-25 21:45:35 +01:00
|
|
|
const QStringList extraFiles;
|
2022-08-26 10:30:00 +02:00
|
|
|
const std::optional<QString> subproject;
|
2020-05-01 18:20:56 +02:00
|
|
|
const SourceGroupList sources;
|
|
|
|
|
|
2023-07-10 13:05:52 +02:00
|
|
|
static inline QString fullName(const Utils::FilePath &buildDir, const Target &target)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2020-06-24 09:44:55 +02:00
|
|
|
using namespace Utils;
|
2023-07-10 13:05:52 +02:00
|
|
|
auto fname = target.fileName.first();
|
|
|
|
|
if (FilePath::fromString(fname).isAbsolutePath()) {
|
|
|
|
|
fname.remove(buildDir.toString());
|
|
|
|
|
if (fname.startsWith('/'))
|
|
|
|
|
fname.removeFirst();
|
|
|
|
|
return fname;
|
2020-05-01 18:20:56 +02:00
|
|
|
} else {
|
2023-07-10 13:05:52 +02:00
|
|
|
return fname;
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Type toType(const QString &typeStr)
|
|
|
|
|
{
|
|
|
|
|
if (typeStr == "executable")
|
|
|
|
|
return Type::executable;
|
|
|
|
|
if (typeStr == "static library")
|
|
|
|
|
return Type::staticLibrary;
|
|
|
|
|
if (typeStr == "shared library")
|
|
|
|
|
return Type::sharedLibrary;
|
|
|
|
|
if (typeStr == "shared module")
|
|
|
|
|
return Type::sharedModule;
|
|
|
|
|
if (typeStr == "custom")
|
|
|
|
|
return Type::custom;
|
|
|
|
|
if (typeStr == "run")
|
|
|
|
|
return Type::run;
|
|
|
|
|
if (typeStr == "jar")
|
|
|
|
|
return Type::jar;
|
|
|
|
|
return Type::unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Target(const QString &type,
|
|
|
|
|
QString &&name,
|
|
|
|
|
QString &&id,
|
|
|
|
|
QString &&definedIn,
|
|
|
|
|
QStringList &&fileName,
|
2020-10-25 21:45:35 +01:00
|
|
|
QStringList &&extraFiles,
|
2020-05-01 18:20:56 +02:00
|
|
|
QString &&subproject,
|
|
|
|
|
SourceGroupList &&sources)
|
|
|
|
|
: type{toType(type)}
|
|
|
|
|
, name{std::move(name)}
|
|
|
|
|
, id{std::move(id)}
|
2020-06-24 09:44:55 +02:00
|
|
|
, definedIn{QDir::cleanPath(definedIn)}
|
|
|
|
|
, fileName{cleanPath(std::move(fileName))}
|
2020-10-25 21:45:35 +01:00
|
|
|
, extraFiles{cleanPath(std::move(extraFiles))}
|
2022-08-26 10:30:00 +02:00
|
|
|
, subproject{subproject.isNull() ? std::nullopt
|
|
|
|
|
: std::optional<QString>{std::move(subproject)}}
|
2020-05-01 18:20:56 +02:00
|
|
|
, sources{std::move(sources)}
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using TargetsList = std::vector<Target>;
|
|
|
|
|
|
|
|
|
|
template<class function>
|
|
|
|
|
void for_each_source_group(const TargetsList &targets, const function &f)
|
|
|
|
|
{
|
|
|
|
|
for (const Target &target : targets) {
|
|
|
|
|
for (const Target::SourceGroup &group : target.sources) {
|
|
|
|
|
f(target, group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|