1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "builddirparameters.h"
#include "cmakebuildconfiguration.h"
#include "cmakebuildsystem.h"
#include "cmakeprojectconstants.h"
#include "cmakekitaspect.h"
#include "cmaketoolmanager.h"
#include <projectexplorer/customparser.h>
#include <projectexplorer/environmentkitaspect.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <utils/algorithm.h>
#include <utils/aspects.h>
#include <utils/macroexpander.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace CMakeProjectManager::Internal {
BuildDirParameters::BuildDirParameters() = default;
static void updateCMakePathsFromQMake(QStringList &initialCMakeArguments)
{
const CMakeConfigItem qmake = CMakeConfigItem::fromString(
Utils::findOrDefault(initialCMakeArguments, [](const QString &arg) {
return arg.startsWith("-DQT_QMAKE_EXECUTABLE");
}));
const FilePath qmakeFilePath = FilePath::fromUtf8(qmake.value);
if (qmakeFilePath.isEmpty())
return;
// ~Qt/6.x/platform/bin/qmake -> ~Qt/6.x/platform
const QByteArray qmakePrefixPath = qmakeFilePath.parentDir().parentDir().path().toUtf8();
const QByteArrayList cmakePathsVariables = {"CMAKE_PREFIX_PATH", "CMAKE_FIND_ROOT_PATH"};
for (const QByteArray &var : cmakePathsVariables) {
const QString varPrefix = QString("-D") + var;
auto it = std::find_if(
initialCMakeArguments.begin(),
initialCMakeArguments.end(),
[varPrefix](const QString &arg) { return arg.startsWith(varPrefix); });
if (it == initialCMakeArguments.end())
continue;
CMakeConfigItem cmakeVar = CMakeConfigItem::fromString(*it);
if (cmakeVar.isNull())
continue;
if (cmakeVar.value.isEmpty())
cmakeVar.value = qmakePrefixPath;
else
cmakeVar.value += ";" + qmakePrefixPath;
*it = cmakeVar.toString();
}
}
BuildDirParameters::BuildDirParameters(CMakeBuildSystem *buildSystem)
{
QTC_ASSERT(buildSystem, return);
auto bc = buildSystem->cmakeBuildConfiguration();
QTC_ASSERT(bc, return);
expander = bc->macroExpander();
const QStringList expandedArguments = Utils::transform(bc->initialCMakeArguments.allValues(),
[this](const QString &s) {
return expander->expand(s);
});
initialCMakeArguments = Utils::filtered(expandedArguments,
[](const QString &s) { return !s.isEmpty(); });
const bool noQtInstallPrefix = expander->expand(QString("%{Qt:QT_INSTALL_PREFIX}")).isEmpty();
if (noQtInstallPrefix)
updateCMakePathsFromQMake(initialCMakeArguments);
configurationChangesArguments = Utils::transform(buildSystem->configurationChangesArguments(),
[this](const QString &s) {
return expander->expand(s);
});
additionalCMakeArguments = Utils::transform(bc->additionalCMakeArguments(),
[this](const QString &s) {
return expander->expand(s);
});
const Kit *k = bc->kit();
project = bc->project();
projectName = project->displayName();
sourceDirectory = bc->sourceDirectory();
if (sourceDirectory.isEmpty())
sourceDirectory = project->projectDirectory();
buildDirectory = bc->buildDirectory();
cmakeBuildType = buildSystem->cmakeBuildType();
environment = bc->configureEnvironment();
// Disable distributed building for configuration runs. CMake does not do those in parallel,
// so there is no win in sending data over the network.
// Unfortunately distcc does not have a simple environment flag to turn it off:-/
if (Utils::HostOsInfo::isAnyUnixHost())
environment.set("ICECC", "no");
environment.set("QTC_RUN", "1");
environment.setFallback("CLICOLOR_FORCE", "1");
cmakeToolId = CMakeKitAspect::cmakeToolId(k);
outputParserGenerator = [k, bc]() {
QList<OutputLineParser *> outputParsers = k->createOutputParsers();
for (const Id id : bc->customParsers()) {
if (auto parser = createCustomParserFromId(id))
outputParsers << parser;
}
return outputParsers;
};
}
bool BuildDirParameters::isValid() const
{
return cmakeTool();
}
CMakeTool *BuildDirParameters::cmakeTool() const
{
return CMakeToolManager::findById(cmakeToolId);
}
QList<OutputLineParser *> BuildDirParameters::outputParsers() const
{
QTC_ASSERT(outputParserGenerator, return {});
return outputParserGenerator();
}
} // CMakeProjectManager::Internal
|