forked from qt-creator/qt-creator
QmlProjectManager: Cleanup cmake generator
- Consider qmlModules file like any other qml module - Use ${CMAKE_PROJECT_NAME} when possible - Break up big functions into smaller ones - Reorder arguments for tpl files Change-Id: Ie73cca8596b22adf67eba1019610a00c34976421 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -19,19 +19,16 @@ namespace GenerateCmake {
|
|||||||
const char TEMPLATE_CMAKELISTS_ROOT[] = ":/boilerplatetemplates/gencmakeroot.tpl";
|
const char TEMPLATE_CMAKELISTS_ROOT[] = ":/boilerplatetemplates/gencmakeroot.tpl";
|
||||||
const char TEMPLATE_CMAKELISTS_MODULE[] = ":/boilerplatetemplates/gencmakemodule.tpl";
|
const char TEMPLATE_CMAKELISTS_MODULE[] = ":/boilerplatetemplates/gencmakemodule.tpl";
|
||||||
|
|
||||||
const char TEMPLATE_QMLMODULES[] = ":/boilerplatetemplates/qmlprojectmodules.tpl";
|
|
||||||
const char TEMPLATE_SOURCE_MAIN[] = ":/boilerplatetemplates/qmlprojectmaincpp.tpl";
|
const char TEMPLATE_SOURCE_MAIN[] = ":/boilerplatetemplates/qmlprojectmaincpp.tpl";
|
||||||
const char TEMPLATE_HEADER_IMPORT_COMPS[] = ":/boilerplatetemplates/gencmakeheadercomponents.tpl";
|
const char TEMPLATE_HEADER_IMPORT_COMPS[] = ":/boilerplatetemplates/gencmakeheadercomponents.tpl";
|
||||||
const char TEMPLATE_HEADER_IMPORT_PLUGINS[] = ":/boilerplatetemplates/qmlprojectmaincppheader.tpl";
|
const char TEMPLATE_HEADER_IMPORT_PLUGINS[] = ":/boilerplatetemplates/qmlprojectmaincppheader.tpl";
|
||||||
const char TEMPLATE_HEADER_ENVIRONMENT[] = ":/boilerplatetemplates/qmlprojectenvheader.tpl";
|
const char TEMPLATE_HEADER_ENVIRONMENT[] = ":/boilerplatetemplates/qmlprojectenvheader.tpl";
|
||||||
|
|
||||||
const char DO_NOT_EDIT_FILE_COMMENT[] =
|
const char DO_NOT_EDIT_FILE_COMMENT[]
|
||||||
"### This file is automatically generated by Qt Design Studio.\n"
|
= "### This file is automatically generated by Qt Design Studio.\n"
|
||||||
"### Do not change\n\n";
|
"### Do not change\n\n";
|
||||||
|
|
||||||
const char ADD_SUBDIR[] = "add_subdirectory(%1)\n";
|
const char TEMPLATE_BIG_RESOURCES[] = R"(
|
||||||
|
|
||||||
const char BIG_RESOURCE_TEMPLATE[] = R"(
|
|
||||||
qt6_add_resources(%1 %2
|
qt6_add_resources(%1 %2
|
||||||
BIG_RESOURCES
|
BIG_RESOURCES
|
||||||
PREFIX "%3"
|
PREFIX "%3"
|
||||||
@@ -39,6 +36,11 @@ qt6_add_resources(%1 %2
|
|||||||
FILES %4
|
FILES %4
|
||||||
))";
|
))";
|
||||||
|
|
||||||
|
const char TEMPLATE_LINK_LIBRARIES[] = R"(
|
||||||
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
|
%3
|
||||||
|
))";
|
||||||
|
|
||||||
CMakeGenerator::CMakeGenerator(QmlBuildSystem *bs, QObject *parent)
|
CMakeGenerator::CMakeGenerator(QmlBuildSystem *bs, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_root(std::make_shared<Node>())
|
, m_root(std::make_shared<Node>())
|
||||||
@@ -59,7 +61,9 @@ void CMakeGenerator::initialize(QmlProject *project)
|
|||||||
m_moduleNames.clear();
|
m_moduleNames.clear();
|
||||||
|
|
||||||
m_root = std::make_shared<Node>();
|
m_root = std::make_shared<Node>();
|
||||||
m_root->name = QString("Root");
|
m_root->module = true;
|
||||||
|
m_root->uri = QString("Main");
|
||||||
|
m_root->name = QString("Main");
|
||||||
m_root->dir = project->rootProjectDirectory();
|
m_root->dir = project->rootProjectDirectory();
|
||||||
|
|
||||||
m_projectName = project->displayName();
|
m_projectName = project->displayName();
|
||||||
@@ -102,66 +106,48 @@ void CMakeGenerator::update(const QSet<QString> &added, const QSet<QString> &rem
|
|||||||
createModuleCMakeFile(module);
|
createModuleCMakeFile(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Utils::FilePath> CMakeGenerator::qmlFiles(const NodePtr &node) const
|
std::vector<Utils::FilePath> CMakeGenerator::files(const NodePtr &node,
|
||||||
|
const FileGetter &getter) const
|
||||||
{
|
{
|
||||||
std::vector<Utils::FilePath> out = node->files;
|
std::vector<Utils::FilePath> out = getter(node);
|
||||||
for (const NodePtr &child : node->subdirs) {
|
for (const CMakeGenerator::NodePtr &child : node->subdirs) {
|
||||||
if (child->module)
|
if (child->module)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto childFiles = qmlFiles(child);
|
auto childFiles = files(child, getter);
|
||||||
out.insert(out.end(), childFiles.begin(), childFiles.end());
|
out.insert(out.end(), childFiles.begin(), childFiles.end());
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Utils::FilePath> CMakeGenerator::qmlFiles(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
return files(node, [](const NodePtr &n) { return n->files; });
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Utils::FilePath> CMakeGenerator::singletons(const NodePtr &node) const
|
std::vector<Utils::FilePath> CMakeGenerator::singletons(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
std::vector<Utils::FilePath> out = node->singletons;
|
return files(node, [](const NodePtr &n) { return n->singletons; });
|
||||||
for (const NodePtr &child : node->subdirs) {
|
|
||||||
if (child->module)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto childFiles = singletons(child);
|
|
||||||
out.insert(out.end(), childFiles.begin(), childFiles.end());
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Utils::FilePath> CMakeGenerator::resources(const NodePtr &node) const
|
std::vector<Utils::FilePath> CMakeGenerator::resources(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
std::vector<Utils::FilePath> out = node->resources;
|
return files(node, [](const NodePtr &n) { return n->resources; });
|
||||||
for (const NodePtr &child : node->subdirs) {
|
|
||||||
if (child->module)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto childFiles = resources(child);
|
|
||||||
out.insert(out.end(), childFiles.begin(), childFiles.end());
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Utils::FilePath> CMakeGenerator::sources(const NodePtr &node) const
|
std::vector<Utils::FilePath> CMakeGenerator::sources(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
std::vector<Utils::FilePath> out = node->sources;
|
return files(node, [](const NodePtr &n) { return n->sources; });
|
||||||
for (const NodePtr &child : node->subdirs) {
|
|
||||||
if (child->module)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto childFiles = sources(child);
|
|
||||||
out.insert(out.end(), childFiles.begin(), childFiles.end());
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeGenerator::createCMakeFiles(const NodePtr &node) const
|
void CMakeGenerator::createCMakeFiles(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
if (node->name == "Root") {
|
if (isRootNode(node))
|
||||||
createMainCMakeFile(node);
|
createMainCMakeFile(node);
|
||||||
createQmlModuleFile(node);
|
|
||||||
} else if (node->module || hasChildModule(node)) {
|
if (node->module || hasChildModule(node))
|
||||||
createModuleCMakeFile(node);
|
createModuleCMakeFile(node);
|
||||||
}
|
|
||||||
for (const NodePtr &n : node->subdirs)
|
for (const NodePtr &n : node->subdirs)
|
||||||
createCMakeFiles(n);
|
createCMakeFiles(n);
|
||||||
}
|
}
|
||||||
@@ -183,103 +169,43 @@ void CMakeGenerator::createMainCMakeFile(const NodePtr &node) const
|
|||||||
writeFile(file, fileContent);
|
writeFile(file, fileContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeGenerator::createQmlModuleFile(const NodePtr &node) const
|
|
||||||
{
|
|
||||||
const QString appName = m_projectName + "App";
|
|
||||||
|
|
||||||
QString subdirIncludes;
|
|
||||||
for (const NodePtr &n : node->subdirs)
|
|
||||||
subdirIncludes.append(QString(ADD_SUBDIR).arg(n->name));
|
|
||||||
|
|
||||||
QString modulesAsPlugins;
|
|
||||||
for (const QString &moduleName : m_moduleNames)
|
|
||||||
modulesAsPlugins.append(" " + moduleName + "plugin\n");
|
|
||||||
|
|
||||||
const QString fileTemplate = readTemplate(TEMPLATE_QMLMODULES);
|
|
||||||
const QString fileContent = fileTemplate.arg(appName, subdirIncludes, modulesAsPlugins);
|
|
||||||
|
|
||||||
const Utils::FilePath file = node->dir.pathAppended("qmlModules");
|
|
||||||
writeFile(file, fileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMakeGenerator::createModuleCMakeFile(const NodePtr &node) const
|
void CMakeGenerator::createModuleCMakeFile(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
QString subDirContent;
|
Utils::FilePath writeToFile = node->dir.pathAppended("CMakeLists.txt");
|
||||||
for (const NodePtr &n : node->subdirs) {
|
|
||||||
if (n->module || hasChildModule(n))
|
|
||||||
subDirContent.append(QString(ADD_SUBDIR).arg(n->dir.fileName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString content;
|
|
||||||
if (!node->module && hasChildModule(node)) {
|
if (!node->module && hasChildModule(node)) {
|
||||||
content.append(DO_NOT_EDIT_FILE_COMMENT);
|
QString content(DO_NOT_EDIT_FILE_COMMENT);
|
||||||
content.append(subDirContent);
|
content.append(makeSubdirectoriesBlock(node));
|
||||||
Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
|
writeFile(writeToFile, content);
|
||||||
writeFile(file, content);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto makeRelative = [](const Utils::FilePath &base,
|
QString templatePrefix;
|
||||||
const Utils::FilePath &converted) -> QString {
|
templatePrefix.append(makeSubdirectoriesBlock(node));
|
||||||
return "\"" + Utils::FilePath::calcRelativePath(converted.toString(), base.toString()) + "\"";
|
templatePrefix.append(makeSingletonBlock(node));
|
||||||
};
|
|
||||||
|
|
||||||
QString uri = node->uri;
|
|
||||||
if (uri.isEmpty())
|
|
||||||
uri = node->dir.baseName();
|
|
||||||
|
|
||||||
const QString setProperties(
|
|
||||||
"set_source_files_properties(%1\n PROPERTIES\n %2 %3\n)\n\n");
|
|
||||||
|
|
||||||
for (const Utils::FilePath &path : node->singletons) {
|
|
||||||
content.append(setProperties.arg(path.fileName()).arg("QT_QML_SINGLETON_TYPE").arg("true"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subDirContent.isEmpty())
|
|
||||||
content.append(subDirContent);
|
|
||||||
|
|
||||||
QString qmlFileContent;
|
|
||||||
for (const Utils::FilePath &path : qmlFiles(node)) {
|
|
||||||
qmlFileContent.append(QString(" %1\n").arg(makeRelative(node->dir, path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
auto [resources, bigResources] = makeResourcesBlocks(node);
|
||||||
QString moduleContent;
|
QString moduleContent;
|
||||||
if (!qmlFileContent.isEmpty())
|
moduleContent.append(makeQmlFilesBlock(node));
|
||||||
moduleContent.append(QString(" QML_FILES\n%1").arg(qmlFileContent));
|
moduleContent.append(resources);
|
||||||
|
|
||||||
std::vector<QString> bigResources;
|
QString templatePostfix;
|
||||||
QString resourceFiles;
|
templatePostfix.append(bigResources);
|
||||||
for (const Utils::FilePath &path : resources(node)) {
|
|
||||||
if (path.fileSize() > 5000000) {
|
|
||||||
bigResources.push_back(makeRelative(node->dir, path));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
resourceFiles.append(QString(" %1\n").arg(makeRelative(node->dir, path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resourceFiles.isEmpty())
|
if (isRootNode(node)) {
|
||||||
moduleContent.append(QString(" RESOURCES\n%1").arg(resourceFiles));
|
writeToFile = node->dir.pathAppended("qmlModules");
|
||||||
|
QString pluginNames;
|
||||||
|
for (const QString &moduleName : m_moduleNames)
|
||||||
|
pluginNames.append(" " + moduleName + "plugin\n");
|
||||||
|
|
||||||
QString bigResourceContent;
|
templatePostfix += QString::fromUtf8(TEMPLATE_LINK_LIBRARIES, -1).arg(pluginNames);
|
||||||
if (!bigResources.empty()) {
|
|
||||||
QString resourceContent;
|
|
||||||
for (const QString &res : bigResources)
|
|
||||||
resourceContent.append(QString("\n %1").arg(res));
|
|
||||||
|
|
||||||
const QString prefixPath = QString(uri).replace('.', '/');
|
|
||||||
const QString prefix = "/qt/qml/" + prefixPath;
|
|
||||||
const QString resourceName = node->name + "BigResource";
|
|
||||||
|
|
||||||
bigResourceContent = QString::fromUtf8(BIG_RESOURCE_TEMPLATE, -1)
|
|
||||||
.arg(node->name, resourceName, prefix, resourceContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString fileTemplate = readTemplate(TEMPLATE_CMAKELISTS_MODULE);
|
const QString fileTemplate = readTemplate(TEMPLATE_CMAKELISTS_MODULE);
|
||||||
const QString fileContent =
|
const QString fileContent
|
||||||
fileTemplate.arg(content, node->name, uri, moduleContent, bigResourceContent);
|
= fileTemplate.arg(node->name, node->uri, templatePrefix, moduleContent, templatePostfix);
|
||||||
|
|
||||||
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
|
writeFile(writeToFile, fileContent);
|
||||||
writeFile(file, fileContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeGenerator::createEntryPoints(const NodePtr &node) const
|
void CMakeGenerator::createEntryPoints(const NodePtr &node) const
|
||||||
@@ -295,6 +221,7 @@ void CMakeGenerator::createMainCppFile(const NodePtr &node) const
|
|||||||
|
|
||||||
const Utils::FilePath componentsHeaderPath = srcDir.pathAppended(
|
const Utils::FilePath componentsHeaderPath = srcDir.pathAppended(
|
||||||
"import_qml_components_plugins.h");
|
"import_qml_components_plugins.h");
|
||||||
|
|
||||||
const QString componentsHeaderContent = readTemplate(TEMPLATE_HEADER_IMPORT_COMPS);
|
const QString componentsHeaderContent = readTemplate(TEMPLATE_HEADER_IMPORT_COMPS);
|
||||||
writeFile(componentsHeaderPath, componentsHeaderContent);
|
writeFile(componentsHeaderPath, componentsHeaderContent);
|
||||||
|
|
||||||
@@ -314,7 +241,8 @@ void CMakeGenerator::createMainCppFile(const NodePtr &node) const
|
|||||||
value.prepend(":/");
|
value.prepend(":/");
|
||||||
environment.append(QString(" qputenv(\"%1\", \"%2\");\n").arg(key).arg(value));
|
environment.append(QString(" qputenv(\"%1\", \"%2\");\n").arg(key).arg(value));
|
||||||
}
|
}
|
||||||
const QString envHeaderContent = readTemplate(TEMPLATE_HEADER_ENVIRONMENT).arg(environment);
|
const QString envHeaderContent
|
||||||
|
= readTemplate(TEMPLATE_HEADER_ENVIRONMENT).arg(environment);
|
||||||
writeFile(envHeaderPath, envHeaderContent);
|
writeFile(envHeaderPath, envHeaderContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,10 +265,15 @@ void CMakeGenerator::writeFile(const Utils::FilePath &path, const QString &conte
|
|||||||
fileHandle.close();
|
fileHandle.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CMakeGenerator::makeRelative(const NodePtr &node, const Utils::FilePath &path) const
|
||||||
|
{
|
||||||
|
const QString dir = node->dir.toString();
|
||||||
|
return "\"" + Utils::FilePath::calcRelativePath(path.toString(), dir) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
QString CMakeGenerator::makeEnvironmentVariable(const QString &key) const
|
QString CMakeGenerator::makeEnvironmentVariable(const QString &key) const
|
||||||
{
|
{
|
||||||
QString value = {};
|
QString value;
|
||||||
|
|
||||||
if (m_buildSystem) {
|
if (m_buildSystem) {
|
||||||
auto envItems = m_buildSystem->environment();
|
auto envItems = m_buildSystem->environment();
|
||||||
auto confEnv = std::find_if(envItems.begin(),
|
auto confEnv = std::find_if(envItems.begin(),
|
||||||
@@ -352,6 +285,78 @@ QString CMakeGenerator::makeEnvironmentVariable(const QString &key) const
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CMakeGenerator::makeSingletonBlock(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
const QString setProperties(
|
||||||
|
"set_source_files_properties(%1\n PROPERTIES\n %2 %3\n)\n\n");
|
||||||
|
|
||||||
|
QString str;
|
||||||
|
for (const Utils::FilePath &path : node->singletons)
|
||||||
|
str.append(setProperties.arg(path.fileName()).arg("QT_QML_SINGLETON_TYPE").arg("true"));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CMakeGenerator::makeSubdirectoriesBlock(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
QString str;
|
||||||
|
for (const NodePtr &n : node->subdirs) {
|
||||||
|
if (n->module || hasChildModule(n))
|
||||||
|
str.append(QString("add_subdirectory(%1)\n").arg(n->dir.fileName()));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CMakeGenerator::makeQmlFilesBlock(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
QString qmlFileContent;
|
||||||
|
for (const Utils::FilePath &path : qmlFiles(node))
|
||||||
|
qmlFileContent.append(QString(" %1\n").arg(makeRelative(node, path)));
|
||||||
|
|
||||||
|
if (isRootNode(node) && qmlFileContent.isEmpty())
|
||||||
|
qmlFileContent.append(QString(" %1\n").arg("\"main.qml\""));
|
||||||
|
|
||||||
|
QString str;
|
||||||
|
if (!qmlFileContent.isEmpty())
|
||||||
|
str.append(QString(" QML_FILES\n%1").arg(qmlFileContent));
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<QString, QString> CMakeGenerator::makeResourcesBlocks(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
QString resourcesOut;
|
||||||
|
QString bigResourcesOut;
|
||||||
|
|
||||||
|
QString resourceFiles;
|
||||||
|
std::vector<QString> bigResources;
|
||||||
|
for (const Utils::FilePath &path : resources(node)) {
|
||||||
|
if (path.fileSize() > 5000000) {
|
||||||
|
bigResources.push_back(makeRelative(node, path));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
resourceFiles.append(QString(" %1\n").arg(makeRelative(node, path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!resourceFiles.isEmpty())
|
||||||
|
resourcesOut.append(QString(" RESOURCES\n%1").arg(resourceFiles));
|
||||||
|
|
||||||
|
QString templatePostfix;
|
||||||
|
if (!bigResources.empty()) {
|
||||||
|
QString resourceContent;
|
||||||
|
for (const QString &res : bigResources)
|
||||||
|
resourceContent.append(QString("\n %1").arg(res));
|
||||||
|
|
||||||
|
const QString prefixPath = QString(node->uri).replace('.', '/');
|
||||||
|
const QString prefix = "/qt/qml/" + prefixPath;
|
||||||
|
const QString resourceName = node->name + "BigResource";
|
||||||
|
|
||||||
|
bigResourcesOut = QString::fromUtf8(TEMPLATE_BIG_RESOURCES, -1)
|
||||||
|
.arg(node->name, resourceName, prefix, resourceContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {resourcesOut, bigResourcesOut};
|
||||||
|
}
|
||||||
|
|
||||||
QString CMakeGenerator::readTemplate(const QString &templatePath) const
|
QString CMakeGenerator::readTemplate(const QString &templatePath) const
|
||||||
{
|
{
|
||||||
QFile templatefile(templatePath);
|
QFile templatefile(templatePath);
|
||||||
@@ -384,7 +389,6 @@ void CMakeGenerator::readQmlDir(const Utils::FilePath &filePath, NodePtr &node)
|
|||||||
node->singletons.push_back(tmp);
|
node->singletons.push_back(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +474,11 @@ void CMakeGenerator::removeFile(NodePtr &node, const Utils::FilePath &path) cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMakeGenerator::isRootNode(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
return node->name == "Main";
|
||||||
|
}
|
||||||
|
|
||||||
bool CMakeGenerator::hasChildModule(const NodePtr &node) const
|
bool CMakeGenerator::hasChildModule(const NodePtr &node) const
|
||||||
{
|
{
|
||||||
for (const NodePtr &child : node->subdirs) {
|
for (const NodePtr &child : node->subdirs) {
|
||||||
@@ -484,11 +493,20 @@ bool CMakeGenerator::hasChildModule(const NodePtr &node) const
|
|||||||
bool CMakeGenerator::isResource(const Utils::FilePath &path) const
|
bool CMakeGenerator::isResource(const Utils::FilePath &path) const
|
||||||
{
|
{
|
||||||
static const QStringList suffixes = {
|
static const QStringList suffixes = {
|
||||||
"json", "mesh", "dae", "qad", "hints", "png", "hdr", "ttf", "jpg",
|
"json", "mesh", "dae", "qad", "hints", "png", "hdr", "ttf", "jpg", "JPG",
|
||||||
"JPG", "js", "qsb", "frag", "frag.qsb", "vert", "vert.qsb", "svg", "ktx"};
|
"js", "qsb", "frag", "frag.qsb", "vert", "vert.qsb", "svg", "ktx"};
|
||||||
return suffixes.contains(path.suffix());
|
return suffixes.contains(path.suffix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeGenerator::printModules(const NodePtr &node) const
|
||||||
|
{
|
||||||
|
if (node->module)
|
||||||
|
qDebug() << "Module: " << node->name;
|
||||||
|
|
||||||
|
for (const auto &child : node->subdirs)
|
||||||
|
printModules(child);
|
||||||
|
}
|
||||||
|
|
||||||
void CMakeGenerator::printNodeTree(const NodePtr &generatorNode, size_t indent) const
|
void CMakeGenerator::printNodeTree(const NodePtr &generatorNode, size_t indent) const
|
||||||
{
|
{
|
||||||
auto addIndent = [](size_t level) -> QString {
|
auto addIndent = [](size_t level) -> QString {
|
||||||
@@ -516,8 +534,9 @@ void CMakeGenerator::parseNodeTree(NodePtr &generatorNode,
|
|||||||
if (const auto *subFolderNode = childNode->asFolderNode()) {
|
if (const auto *subFolderNode = childNode->asFolderNode()) {
|
||||||
CMakeGenerator::NodePtr childGeneratorNode = std::make_shared<Node>();
|
CMakeGenerator::NodePtr childGeneratorNode = std::make_shared<Node>();
|
||||||
childGeneratorNode->parent = generatorNode;
|
childGeneratorNode->parent = generatorNode;
|
||||||
childGeneratorNode->name = subFolderNode->displayName();
|
|
||||||
childGeneratorNode->dir = subFolderNode->filePath();
|
childGeneratorNode->dir = subFolderNode->filePath();
|
||||||
|
childGeneratorNode->name = subFolderNode->displayName();
|
||||||
|
childGeneratorNode->uri = childGeneratorNode->name;
|
||||||
parseNodeTree(childGeneratorNode, subFolderNode);
|
parseNodeTree(childGeneratorNode, subFolderNode);
|
||||||
generatorNode->subdirs.push_back(childGeneratorNode);
|
generatorNode->subdirs.push_back(childGeneratorNode);
|
||||||
} else if (auto *fileNode = childNode->asFileNode()) {
|
} else if (auto *fileNode = childNode->asFileNode()) {
|
||||||
|
@@ -17,11 +17,6 @@ class QmlBuildSystem;
|
|||||||
|
|
||||||
namespace GenerateCmake {
|
namespace GenerateCmake {
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - Create "module" for src dir
|
|
||||||
// - Replace AppName in templates with ${CMAKE_PROJECT_NAME}
|
|
||||||
// - Introduce Blacklist (designer)
|
|
||||||
|
|
||||||
class CMakeGenerator : public QObject
|
class CMakeGenerator : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -53,15 +48,15 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
using NodePtr = std::shared_ptr<Node>;
|
using NodePtr = std::shared_ptr<Node>;
|
||||||
|
using FileGetter = std::function<std::vector<Utils::FilePath>(const NodePtr &)>;
|
||||||
|
|
||||||
|
std::vector<Utils::FilePath> files(const NodePtr &node, const FileGetter &getter) const;
|
||||||
std::vector<Utils::FilePath> qmlFiles(const NodePtr &node) const;
|
std::vector<Utils::FilePath> qmlFiles(const NodePtr &node) const;
|
||||||
std::vector<Utils::FilePath> singletons(const NodePtr &node) const;
|
std::vector<Utils::FilePath> singletons(const NodePtr &node) const;
|
||||||
std::vector<Utils::FilePath> resources(const NodePtr &node) const;
|
std::vector<Utils::FilePath> resources(const NodePtr &node) const;
|
||||||
std::vector<Utils::FilePath> sources(const NodePtr &node) const;
|
std::vector<Utils::FilePath> sources(const NodePtr &node) const;
|
||||||
|
|
||||||
void createCMakeFiles(const NodePtr &node) const;
|
void createCMakeFiles(const NodePtr &node) const;
|
||||||
|
|
||||||
void createQmlModuleFile(const NodePtr &node) const;
|
|
||||||
void createMainCMakeFile(const NodePtr &node) const;
|
void createMainCMakeFile(const NodePtr &node) const;
|
||||||
void createModuleCMakeFile(const NodePtr &node) const;
|
void createModuleCMakeFile(const NodePtr &node) const;
|
||||||
|
|
||||||
@@ -69,7 +64,12 @@ private:
|
|||||||
void createMainCppFile(const NodePtr &node) const;
|
void createMainCppFile(const NodePtr &node) const;
|
||||||
void writeFile(const Utils::FilePath &path, const QString &content) const;
|
void writeFile(const Utils::FilePath &path, const QString &content) const;
|
||||||
|
|
||||||
|
QString makeRelative(const NodePtr &node, const Utils::FilePath &path) const;
|
||||||
QString makeEnvironmentVariable(const QString &key) const;
|
QString makeEnvironmentVariable(const QString &key) const;
|
||||||
|
QString makeSingletonBlock(const NodePtr &node) const;
|
||||||
|
QString makeSubdirectoriesBlock(const NodePtr &node) const;
|
||||||
|
QString makeQmlFilesBlock(const NodePtr &node) const;
|
||||||
|
std::tuple<QString, QString> makeResourcesBlocks(const NodePtr &node) const;
|
||||||
|
|
||||||
QString readTemplate(const QString &templatePath) const;
|
QString readTemplate(const QString &templatePath) const;
|
||||||
void readQmlDir(const Utils::FilePath &filePath, NodePtr &node) const;
|
void readQmlDir(const Utils::FilePath &filePath, NodePtr &node) const;
|
||||||
@@ -81,9 +81,11 @@ private:
|
|||||||
void insertFile(NodePtr &node, const Utils::FilePath &path) const;
|
void insertFile(NodePtr &node, const Utils::FilePath &path) const;
|
||||||
void removeFile(NodePtr &node, const Utils::FilePath &path) const;
|
void removeFile(NodePtr &node, const Utils::FilePath &path) const;
|
||||||
|
|
||||||
|
bool isRootNode(const NodePtr &node) const;
|
||||||
bool hasChildModule(const NodePtr &node) const;
|
bool hasChildModule(const NodePtr &node) const;
|
||||||
bool isResource(const Utils::FilePath &path) const;
|
bool isResource(const Utils::FilePath &path) const;
|
||||||
|
|
||||||
|
void printModules(const NodePtr &generatorNode) const;
|
||||||
void printNodeTree(const NodePtr &generatorNode, size_t indent = 0) const;
|
void printNodeTree(const NodePtr &generatorNode, size_t indent = 0) const;
|
||||||
|
|
||||||
void parseNodeTree(NodePtr &generatorNode, const ProjectExplorer::FolderNode *folderNode);
|
void parseNodeTree(NodePtr &generatorNode, const ProjectExplorer::FolderNode *folderNode);
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
### This file is automatically generated by Qt Design Studio.
|
### This file is automatically generated by Qt Design Studio.
|
||||||
### Do not change
|
### Do not change
|
||||||
|
|
||||||
%1
|
%3
|
||||||
|
|
||||||
qt_add_library(%2 STATIC)
|
qt_add_library(%1 STATIC)
|
||||||
qt6_add_qml_module(%2
|
qt6_add_qml_module(%1
|
||||||
URI "%3"
|
URI "%2"
|
||||||
VERSION 1.0
|
VERSION 1.0
|
||||||
RESOURCE_PREFIX "/qt/qml"
|
RESOURCE_PREFIX "/qt/qml"
|
||||||
%4
|
%4
|
||||||
|
@@ -19,14 +19,14 @@ if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
|
|||||||
qt_standard_project_setup()
|
qt_standard_project_setup()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
qt_add_executable(%1 %2)
|
qt_add_executable(${CMAKE_PROJECT_NAME} %2)
|
||||||
|
|
||||||
qt_add_resources(%1 "configuration"
|
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
|
||||||
PREFIX "/"
|
PREFIX "/"
|
||||||
%3
|
%3
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(%1 PRIVATE
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
Qt${QT_VERSION_MAJOR}::Core
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
Qt${QT_VERSION_MAJOR}::Gui
|
Qt${QT_VERSION_MAJOR}::Gui
|
||||||
Qt${QT_VERSION_MAJOR}::Quick
|
Qt${QT_VERSION_MAJOR}::Quick
|
||||||
@@ -44,7 +44,7 @@ if (LINK_INSIGHT)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
install(TARGETS %1
|
install(TARGETS ${CMAKE_PROJECT_NAME}
|
||||||
BUNDLE DESTINATION .
|
BUNDLE DESTINATION .
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
Reference in New Issue
Block a user