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
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "cmakewriterlib.h"
#include "cmakegenerator.h"
#include "qmlprojectmanager/buildsystem/qmlbuildsystem.h"
#include <coreplugin/icore.h>
namespace QmlProjectManager {
namespace QmlProjectExporter {
CMakeWriterLib::CMakeWriterLib(CMakeGenerator *parent)
: CMakeWriterV1(parent)
{ }
QString CMakeWriterLib::mainLibName() const
{
QTC_ASSERT(parent(), return {});
return parent()->projectName() + "Lib";
}
void CMakeWriterLib::transformNode(NodePtr &node) const
{
CMakeWriterV1::transformNode(node);
}
int CMakeWriterLib::identifier() const
{
return 3;
}
void CMakeWriterLib::writeRootCMakeFile(const NodePtr &node) const
{
QTC_ASSERT(parent(), return);
const Utils::FilePath cmakeFolderPath = node->dir.pathAppended("cmake");
if (!cmakeFolderPath.exists())
cmakeFolderPath.createDir();
const Utils::FilePath insightPath = cmakeFolderPath.pathAppended("insight.cmake");
if (!insightPath.exists()) {
const QString insightTemplate = readTemplate(":/templates/insight");
writeFile(insightPath, insightTemplate);
}
createDependencies(node->dir);
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
if (!file.exists()) {
QString fileSection = "";
const QString configFile = getEnvironmentVariable(ENV_VARIABLE_CONTROLCONF);
if (!configFile.isEmpty())
fileSection = QString("\t\t%1").arg(configFile);
const QString fileTemplate = readTemplate(":/templates/cmakeroot_lib");
const QString fileContent = fileTemplate.arg(mainLibName(), fileSection);
writeFile(file, fileContent);
}
}
void CMakeWriterLib::writeModuleCMakeFile(const NodePtr &node, const NodePtr &root) const
{
CMakeWriterV1::writeModuleCMakeFile(node, root);
}
void CMakeWriterLib::writeSourceFiles(const NodePtr &node, const NodePtr &root) const
{
QTC_ASSERT(parent(), return);
QTC_ASSERT(parent()->buildSystem(), return);
const QmlBuildSystem *buildSystem = parent()->buildSystem();
const Utils::FilePath srcDir = node->dir;
if (!srcDir.exists())
srcDir.createDir();
const Utils::FilePath cmakePath = srcDir.pathAppended("CMakeLists.txt");
if (!cmakePath.exists()) {
const QString includeAutogen =
"\ntarget_include_directories(%1 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})";
writeFile(cmakePath, includeAutogen.arg(mainLibName()));
}
const Utils::FilePath autogenDir = srcDir.pathAppended("autogen");
if (!autogenDir.exists())
autogenDir.createDir();
const Utils::FilePath headerPath = autogenDir.pathAppended("environment.h");
QString environmentPrefix;
for (const QString &module : plugins(root))
environmentPrefix.append(QString("Q_IMPORT_QML_PLUGIN(%1)\n").arg(module + "Plugin"));
const QString mainFile("const char mainQmlFile[] = \"qrc:/qt/qml/%1\";");
environmentPrefix.append("\n");
environmentPrefix.append(mainFile.arg(buildSystem->mainFile()));
const QString environmentPostfix = makeSetEnvironmentFn();
const QString headerTemplate = readTemplate(":/templates/environment_h");
writeFile(headerPath, headerTemplate.arg(environmentPrefix, environmentPostfix));
}
} // namespace QmlProjectExporter
} // namespace QmlProjectManager
|