QmlProjectManager: Check the uri when generating cmake files

and use the Qt and QtQuick version specified in the qmlproject file.

Fixes: QDS-12799
Fixes: QDS-12798
Change-Id: I1b7cec3f3a1cc4c9e2c70a60a68e2acce0ce4b7e
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
(cherry picked from commit bb17d6617f)
This commit is contained in:
Knud Dollereder
2024-05-29 15:30:38 +02:00
committed by Thomas Hartmann
parent dc0c01974f
commit 15eddd9cbc
6 changed files with 53 additions and 7 deletions

View File

@@ -236,6 +236,22 @@ bool CMakeGenerator::ignore(const Utils::FilePath &path) const
return false;
}
bool CMakeGenerator::checkUri(const QString& uri, const Utils::FilePath &path) const
{
Utils::FilePath relative = path.relativeChildPath(m_root->dir);
const QList<QStringView> pathComponents = relative.pathView().split('/', Qt::SkipEmptyParts);
const QStringList uriComponents = uri.split('.', Qt::SkipEmptyParts);
if (pathComponents.size() == uriComponents.size()) {
for (qsizetype i=0; i<pathComponents.size(); ++i) {
if (pathComponents[i] != uriComponents[i])
return false;
}
return true;
}
return false;
}
void CMakeGenerator::createCMakeFiles(const NodePtr &node) const
{
QTC_ASSERT(m_writer, return);
@@ -288,6 +304,11 @@ void CMakeGenerator::readQmlDir(const Utils::FilePath &filePath, NodePtr &node)
}
}
f.close();
if (!checkUri(node->uri, node->dir)) {
QString text("Unexpected uri %1");
logIssue(ProjectExplorer::Task::Warning, text.arg(node->uri), node->dir);
}
}
NodePtr CMakeGenerator::findModuleFor(const NodePtr &node) const

View File

@@ -48,6 +48,7 @@ private:
bool isQml(const Utils::FilePath &path) const;
bool isResource(const Utils::FilePath &path) const;
bool ignore(const Utils::FilePath &path) const;
bool checkUri(const QString& uri, const Utils::FilePath &path) const;
void createCMakeFiles(const NodePtr &node) const;
void createSourceFiles() const;

View File

@@ -133,6 +133,31 @@ QString CMakeWriter::getEnvironmentVariable(const QString &key) const
return value;
}
QString CMakeWriter::makeFindPackageBlock(const QmlBuildSystem* buildSystem) const
{
QString head = "find_package(Qt" + buildSystem->versionQt();
const QString tail = " REQUIRED COMPONENTS Core Gui Qml Quick)\n";
const QStringList versions = buildSystem->versionQtQuick().split('.', Qt::SkipEmptyParts);
if (versions.size() < 2)
return head + tail;
bool majorOk = false;
bool minorOk = false;
int major = versions[0].toInt(&majorOk);
int minor = versions[1].toInt(&minorOk);
if (!majorOk || !minorOk)
return head + tail;
const QString from = versions[0] + "." + versions[1];
QString out = head + " " + from + tail;
if (major >= 6 && minor >= 3)
out += "qt_standard_project_setup()\n";
return out;
}
QString CMakeWriter::makeRelative(const NodePtr &node, const Utils::FilePath &path) const
{
const QString dir = node->dir.toString();

View File

@@ -82,6 +82,7 @@ protected:
QString getEnvironmentVariable(const QString &key) const;
QString makeFindPackageBlock(const QmlBuildSystem* buildSystem) const;
QString makeRelative(const NodePtr &node, const Utils::FilePath &path) const;
QString makeQmlFilesBlock(const NodePtr &node) const;
QString makeSingletonBlock(const NodePtr &node) const;

View File

@@ -40,6 +40,7 @@ void CMakeWriterV1::transformNode(NodePtr &node) const
void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
{
QTC_ASSERT(parent(), return);
QTC_ASSERT(parent()->buildSystem(), return);
const Utils::FilePath cmakeFolderPath = node->dir.pathAppended("cmake");
if (!cmakeFolderPath.exists())
@@ -66,6 +67,7 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
if (!file.exists()) {
const QString appName = parent()->projectName() + "App";
const QString findPackage = makeFindPackageBlock(parent()->buildSystem());
QString fileSection = "";
const QString configFile = getEnvironmentVariable(ENV_VARIABLE_CONTROLCONF);
@@ -73,7 +75,7 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
fileSection = QString("\t\t%1").arg(configFile);
const QString fileTemplate = readTemplate(":/templates/cmakeroot_v1");
const QString fileContent = fileTemplate.arg(appName, fileSection);
const QString fileContent = fileTemplate.arg(appName, findPackage, fileSection);
writeFile(file, fileContent);
}
}

View File

@@ -16,17 +16,13 @@ set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY}
FORCE
)
find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)
if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
qt_standard_project_setup()
endif()
%2
qt_add_executable(${CMAKE_PROJECT_NAME})
qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
PREFIX "/"
FILES
%2)
%3)
include(qds)