QmlProjectExporter: Initialize CMakeLists.txt.shared before modification

Fixes: QDS-15419
Change-Id: I5b68b82379fb03da7eceef123861d3858a095dfb
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2025-05-27 13:01:34 +02:00
parent b7aa9f5598
commit b1ac7ed789
4 changed files with 13 additions and 12 deletions

View File

@@ -601,6 +601,15 @@ void CMakeGenerator::createWriter()
const Utils::FilePath rootPath = project->projectDirectory(); const Utils::FilePath rootPath = project->projectDirectory();
const Utils::FilePath settingsFile = rootPath.pathAppended("CMakeLists.txt.shared"); const Utils::FilePath settingsFile = rootPath.pathAppended("CMakeLists.txt.shared");
if (!settingsFile.exists()) {
const QString sharedTemplate = CMakeWriter::readTemplate(":/templates/cmake_shared");
const QString sharedContent = sharedTemplate.arg(writer->identifier());
CMakeWriter::writeFile(settingsFile, sharedContent);
m_writer = writer;
return;
}
Utils::PersistentSettingsReader reader; Utils::PersistentSettingsReader reader;
reader.load(settingsFile); reader.load(settingsFile);
auto store = reader.restoreValues(); auto store = reader.restoreValues();

View File

@@ -47,12 +47,6 @@ void CMakeWriterLib::writeRootCMakeFile(const NodePtr &node) const
createDependencies(node->dir); createDependencies(node->dir);
const Utils::FilePath sharedFile = node->dir.pathAppended("CMakeLists.txt.shared");
if (!sharedFile.exists()) {
const QString sharedTemplate = readTemplate(":/templates/cmake_shared");
writeFile(sharedFile, sharedTemplate);
}
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt"); const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
if (!file.exists()) { if (!file.exists()) {
QString fileSection = ""; QString fileSection = "";

View File

@@ -74,12 +74,6 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
createDependencies(node->dir); createDependencies(node->dir);
const Utils::FilePath sharedFile = node->dir.pathAppended("CMakeLists.txt.shared");
if (!sharedFile.exists()) {
const QString sharedTemplate = readTemplate(":/templates/cmake_shared");
writeFile(sharedFile, sharedTemplate);
}
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt"); const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
if (!file.exists()) { if (!file.exists()) {
const QString appName = parent()->projectName() + "App"; const QString appName = parent()->projectName() + "App";

View File

@@ -13,4 +13,8 @@
<variable>Version</variable> <variable>Version</variable>
<value type="int">22</value> <value type="int">22</value>
</data> </data>
<data>
<variable>CMake Generator</variable>
<value type="int">%1</value>
</data>
</qtcreator> </qtcreator>