CMakePM: Refactor CMakeLists|Cache.txt as constants

Change-Id: I7165fa1d219a0c59bc519a9af1cd194414c4311c
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2024-01-22 18:10:43 +01:00
parent b953735b22
commit 76a8966739
13 changed files with 39 additions and 25 deletions

View File

@@ -4,6 +4,7 @@
#include "cmakeabstractprocessstep.h" #include "cmakeabstractprocessstep.h"
#include "cmakekitaspect.h" #include "cmakekitaspect.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmaketool.h" #include "cmaketool.h"
@@ -50,7 +51,7 @@ bool CMakeAbstractProcessStep::init()
// Warn if doing out-of-source builds with a CMakeCache.txt is the source directory // Warn if doing out-of-source builds with a CMakeCache.txt is the source directory
const Utils::FilePath projectDirectory = bc->target()->project()->projectDirectory(); const Utils::FilePath projectDirectory = bc->target()->project()->projectDirectory();
if (bc->buildDirectory() != projectDirectory) { if (bc->buildDirectory() != projectDirectory) {
if (projectDirectory.pathAppended("CMakeCache.txt").exists()) { if (projectDirectory.pathAppended(Constants::CMAKE_CACHE_TXT).exists()) {
emit addTask(BuildSystemTask( emit addTask(BuildSystemTask(
Task::Warning, Task::Warning,
Tr::tr("There is a CMakeCache.txt file in \"%1\", which suggest an " Tr::tr("There is a CMakeCache.txt file in \"%1\", which suggest an "

View File

@@ -853,7 +853,8 @@ CMakeConfig CMakeBuildSettingsWidget::getQmlDebugCxxFlags()
CMakeConfig changedConfig; CMakeConfig changedConfig;
if (enable) { if (enable) {
const FilePath cmakeCache = m_buildConfig->buildDirectory().pathAppended("CMakeCache.txt"); const FilePath cmakeCache = m_buildConfig->buildDirectory().pathAppended(
Constants::CMAKE_CACHE_TXT);
// Only modify the CMAKE_CXX_FLAGS variable if the project was previously configured // Only modify the CMAKE_CXX_FLAGS variable if the project was previously configured
// otherwise CMAKE_CXX_FLAGS_INIT will take care of setting the qmlDebug define // otherwise CMAKE_CXX_FLAGS_INIT will take care of setting the qmlDebug define
@@ -1349,8 +1350,10 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Id id)
if (oldDir.isEmpty()) if (oldDir.isEmpty())
return newDir; return newDir;
const FilePath oldDirCMakeCache = FilePath::fromUserInput(oldDir).pathAppended("CMakeCache.txt"); const FilePath oldDirCMakeCache = FilePath::fromUserInput(oldDir).pathAppended(
const FilePath newDirCMakeCache = FilePath::fromUserInput(newDir).pathAppended("CMakeCache.txt"); Constants::CMAKE_CACHE_TXT);
const FilePath newDirCMakeCache = FilePath::fromUserInput(newDir).pathAppended(
Constants::CMAKE_CACHE_TXT);
if (oldDirCMakeCache.exists() && !newDirCMakeCache.exists()) { if (oldDirCMakeCache.exists() && !newDirCMakeCache.exists()) {
if (QMessageBox::information( if (QMessageBox::information(
@@ -2048,7 +2051,8 @@ QString CMakeBuildSystem::cmakeBuildType() const
QString cmakeBuildType = cmakeBuildConfiguration()->buildTypeAspect(); QString cmakeBuildType = cmakeBuildConfiguration()->buildTypeAspect();
const Utils::FilePath cmakeCacheTxt = buildConfiguration()->buildDirectory().pathAppended("CMakeCache.txt"); const Utils::FilePath cmakeCacheTxt = buildConfiguration()->buildDirectory().pathAppended(
Constants::CMAKE_CACHE_TXT);
const bool hasCMakeCache = cmakeCacheTxt.exists(); const bool hasCMakeCache = cmakeCacheTxt.exists();
CMakeConfig config; CMakeConfig config;

View File

@@ -176,7 +176,7 @@ void CMakeBuildSystem::triggerParsing()
qCDebug(cmakeBuildSystemLog) << "Parse called with flags:" qCDebug(cmakeBuildSystemLog) << "Parse called with flags:"
<< reparseParametersString(reparseParameters); << reparseParametersString(reparseParameters);
const FilePath cache = m_parameters.buildDirectory.pathAppended("CMakeCache.txt"); const FilePath cache = m_parameters.buildDirectory.pathAppended(Constants::CMAKE_CACHE_TXT);
if (!cache.exists()) { if (!cache.exists()) {
reparseParameters |= REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN; reparseParameters |= REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN;
qCDebug(cmakeBuildSystemLog) qCDebug(cmakeBuildSystemLog)
@@ -973,7 +973,7 @@ FilePaths CMakeBuildSystem::filesGeneratedFrom(const FilePath &sourceFile) const
FilePath baseDirectory = sourceFile.parentDir(); FilePath baseDirectory = sourceFile.parentDir();
while (baseDirectory.isChildOf(project)) { while (baseDirectory.isChildOf(project)) {
const FilePath cmakeListsTxt = baseDirectory.pathAppended("CMakeLists.txt"); const FilePath cmakeListsTxt = baseDirectory.pathAppended(Constants::CMAKE_LISTS_TXT);
if (cmakeListsTxt.exists()) if (cmakeListsTxt.exists())
break; break;
baseDirectory = baseDirectory.parentDir(); baseDirectory = baseDirectory.parentDir();
@@ -1178,8 +1178,8 @@ void CMakeBuildSystem::clearCMakeCache()
stopParsingAndClearState(); stopParsingAndClearState();
const FilePath pathsToDelete[] = { const FilePath pathsToDelete[] = {
m_parameters.buildDirectory / "CMakeCache.txt", m_parameters.buildDirectory / Constants::CMAKE_CACHE_TXT,
m_parameters.buildDirectory / "CMakeCache.txt.prev", m_parameters.buildDirectory / Constants::CMAKE_CACHE_TXT_PREV,
m_parameters.buildDirectory / "CMakeFiles", m_parameters.buildDirectory / "CMakeFiles",
m_parameters.buildDirectory / ".cmake/api/v1/reply", m_parameters.buildDirectory / ".cmake/api/v1/reply",
m_parameters.buildDirectory / ".cmake/api/v1/reply.prev", m_parameters.buildDirectory / ".cmake/api/v1/reply.prev",
@@ -1601,7 +1601,8 @@ void CMakeBuildSystem::wireUpConnections()
// No CMakeCache? Run with initial arguments! // No CMakeCache? Run with initial arguments!
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change"; qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change";
const BuildDirParameters parameters(this); const BuildDirParameters parameters(this);
const FilePath cmakeCacheTxt = parameters.buildDirectory.pathAppended("CMakeCache.txt"); const FilePath cmakeCacheTxt = parameters.buildDirectory.pathAppended(
Constants::CMAKE_CACHE_TXT);
const bool hasCMakeCache = cmakeCacheTxt.exists(); const bool hasCMakeCache = cmakeCacheTxt.exists();
const auto options = ReparseParameters( const auto options = ReparseParameters(
hasCMakeCache hasCMakeCache

View File

@@ -398,7 +398,7 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
fileName = dir.pathAppended(fileName.path()); fileName = dir.pathAppended(fileName.path());
if (fileName.exists()) { if (fileName.exists()) {
if (fileName.isDir()) { if (fileName.isDir()) {
Utils::FilePath subProject = fileName.pathAppended("CMakeLists.txt"); Utils::FilePath subProject = fileName.pathAppended(Constants::CMAKE_LISTS_TXT);
if (subProject.exists()) if (subProject.exists())
fileName = subProject; fileName = subProject;
else else

View File

@@ -82,7 +82,7 @@ CMakeFileCompletionAssist::CMakeFileCompletionAssist()
Icon::MenuTintedStyle) Icon::MenuTintedStyle)
.icon()) .icon())
, m_snippetCollector(Constants::CMAKE_SNIPPETS_GROUP_ID, , m_snippetCollector(Constants::CMAKE_SNIPPETS_GROUP_ID,
FileIconProvider::icon(FilePath::fromString("CMakeLists.txt"))) FileIconProvider::icon(FilePath::fromString(Constants::CMAKE_LISTS_TXT)))
{} {}
static bool isInComment(const AssistInterface *interface) static bool isInComment(const AssistInterface *interface)

View File

@@ -27,6 +27,10 @@ const char CMAKE_DEBUGGING_GROUP[] = "Debugger.Group.CMake";
const char PACKAGE_MANAGER_DIR[] = ".qtc/package-manager"; const char PACKAGE_MANAGER_DIR[] = ".qtc/package-manager";
const char CMAKE_LISTS_TXT[] = "CMakeLists.txt";
const char CMAKE_CACHE_TXT[] = "CMakeCache.txt";
const char CMAKE_CACHE_TXT_PREV[] = "CMakeCache.txt.prev";
// Project // Project
const char CMAKE_PROJECT_ID[] = "CMakeProjectManager.CMakeProject"; const char CMAKE_PROJECT_ID[] = "CMakeProjectManager.CMakeProject";

View File

@@ -210,7 +210,7 @@ static CMakeConfig configurationFromPresetProbe(
const FilePath &sourceDirectory, const FilePath &sourceDirectory,
const PresetsDetails::ConfigurePreset &configurePreset) const PresetsDetails::ConfigurePreset &configurePreset)
{ {
const FilePath cmakeListTxt = importPath / "CMakeLists.txt"; const FilePath cmakeListTxt = importPath / Constants::CMAKE_LISTS_TXT;
cmakeListTxt.writeFileContents(QByteArray("cmake_minimum_required(VERSION 3.15)\n" cmakeListTxt.writeFileContents(QByteArray("cmake_minimum_required(VERSION 3.15)\n"
"\n" "\n"
"project(preset-probe)\n" "project(preset-probe)\n"
@@ -358,7 +358,7 @@ static QMakeAndCMakePrefixPath qtInfoFromCMakeCache(const CMakeConfig &config,
// Run a CMake project that would do qmake probing // Run a CMake project that would do qmake probing
TemporaryDirectory qtcQMakeProbeDir("qtc-cmake-qmake-probe-XXXXXXXX"); TemporaryDirectory qtcQMakeProbeDir("qtc-cmake-qmake-probe-XXXXXXXX");
FilePath cmakeListTxt(qtcQMakeProbeDir.filePath("CMakeLists.txt")); FilePath cmakeListTxt(qtcQMakeProbeDir.filePath(Constants::CMAKE_LISTS_TXT));
cmakeListTxt.writeFileContents(QByteArray(R"( cmakeListTxt.writeFileContents(QByteArray(R"(
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
@@ -829,7 +829,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
return result; return result;
} }
const FilePath cacheFile = importPath.pathAppended("CMakeCache.txt"); const FilePath cacheFile = importPath.pathAppended(Constants::CMAKE_CACHE_TXT);
if (!cacheFile.exists()) { if (!cacheFile.exists()) {
qCDebug(cmInputLog) << cacheFile.toUserOutput() << "does not exist, returning."; qCDebug(cmInputLog) << cacheFile.toUserOutput() << "does not exist, returning.";

View File

@@ -53,7 +53,7 @@ bool CMakeListsNode::showInSimpleTree() const
std::optional<FilePath> CMakeListsNode::visibleAfterAddFileAction() const std::optional<FilePath> CMakeListsNode::visibleAfterAddFileAction() const
{ {
return filePath().pathAppended("CMakeLists.txt"); return filePath().pathAppended(Constants::CMAKE_LISTS_TXT);
} }
CMakeProjectNode::CMakeProjectNode(const FilePath &directory) : CMakeProjectNode::CMakeProjectNode(const FilePath &directory) :
@@ -189,7 +189,7 @@ void CMakeTargetNode::setConfig(const CMakeConfig &config)
std::optional<FilePath> CMakeTargetNode::visibleAfterAddFileAction() const std::optional<FilePath> CMakeTargetNode::visibleAfterAddFileAction() const
{ {
return filePath().pathAppended("CMakeLists.txt"); return filePath().pathAppended(Constants::CMAKE_LISTS_TXT);
} }
void CMakeTargetNode::build() void CMakeTargetNode::build()

View File

@@ -93,7 +93,7 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake"); FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY, FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
"CMakeLists.txt"); Constants::CMAKE_LISTS_TXT);
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID, TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
Tr::tr("CMake", "SnippetProvider")); Tr::tr("CMake", "SnippetProvider"));

View File

@@ -415,7 +415,8 @@ static RawProjectParts generateRawProjectParts(const QFuture<void> &cancelFuture
} }
RawProjectPart rpp; RawProjectPart rpp;
rpp.setProjectFileLocation(t.sourceDir.pathAppended("CMakeLists.txt").toString()); rpp.setProjectFileLocation(
t.sourceDir.pathAppended(Constants::CMAKE_LISTS_TXT).toString());
rpp.setBuildSystemTarget(t.name); rpp.setBuildSystemTarget(t.name);
const QString postfix = needPostfix ? QString("_%1_%2").arg(ci.language).arg(count) const QString postfix = needPostfix ? QString("_%1_%2").arg(ci.language).arg(count)
: QString(); : QString();

View File

@@ -4,6 +4,7 @@
#include "fileapiparser.h" #include "fileapiparser.h"
#include "cmakeprocess.h" #include "cmakeprocess.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
@@ -230,7 +231,7 @@ static std::vector<CMakeFileInfo> readCMakeFilesFile(const FilePath &cmakeFilesF
info.isCMake = input.value("isCMake").toBool(); info.isCMake = input.value("isCMake").toBool();
const QString filename = info.path.fileName(); const QString filename = info.path.fileName();
info.isCMakeListsDotTxt = (filename.compare("CMakeLists.txt", info.isCMakeListsDotTxt = (filename.compare(Constants::CMAKE_LISTS_TXT,
HostOsInfo::fileNameCaseSensitivity()) HostOsInfo::fileNameCaseSensitivity())
== 0); == 0);
@@ -860,7 +861,7 @@ FileApiData FileApiParser::parseData(QPromise<std::shared_ptr<FileApiQtcData>> &
return {}; return {};
const FilePath cachePathFromReply = result.replyFile.jsonFile("cache", replyDir); const FilePath cachePathFromReply = result.replyFile.jsonFile("cache", replyDir);
if (cachePathFromReply.isEmpty()) if (cachePathFromReply.isEmpty())
result.cache = CMakeConfig::fromFile(buildDir / "CMakeCache.txt", &errorMessage); result.cache = CMakeConfig::fromFile(buildDir / Constants::CMAKE_CACHE_TXT, &errorMessage);
else else
result.cache = readCacheFile(cachePathFromReply, errorMessage); result.cache = readCacheFile(cachePathFromReply, errorMessage);
if (cancelCheck()) if (cancelCheck())

View File

@@ -5,6 +5,7 @@
#include "cmakeprocess.h" #include "cmakeprocess.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmakeprojectconstants.h"
#include "cmakespecificsettings.h" #include "cmakespecificsettings.h"
#include "fileapidataextractor.h" #include "fileapidataextractor.h"
#include "fileapiparser.h" #include "fileapiparser.h"
@@ -73,7 +74,7 @@ void FileApiReader::resetData()
m_cmakeFiles.clear(); m_cmakeFiles.clear();
if (!m_parameters.sourceDirectory.isEmpty()) { if (!m_parameters.sourceDirectory.isEmpty()) {
CMakeFileInfo cmakeListsTxt; CMakeFileInfo cmakeListsTxt;
cmakeListsTxt.path = m_parameters.sourceDirectory.pathAppended("CMakeLists.txt"); cmakeListsTxt.path = m_parameters.sourceDirectory.pathAppended(Constants::CMAKE_LISTS_TXT);
cmakeListsTxt.isCMakeListsDotTxt = true; cmakeListsTxt.isCMakeListsDotTxt = true;
m_cmakeFiles.insert(cmakeListsTxt); m_cmakeFiles.insert(cmakeListsTxt);
} }
@@ -316,8 +317,8 @@ void FileApiReader::makeBackupConfiguration(bool store)
.arg(reply.toString(), replyPrev.toString()))); .arg(reply.toString(), replyPrev.toString())));
} }
FilePath cmakeCacheTxt = m_parameters.buildDirectory.pathAppended("CMakeCache.txt"); FilePath cmakeCacheTxt = m_parameters.buildDirectory.pathAppended(Constants::CMAKE_CACHE_TXT);
FilePath cmakeCacheTxtPrev = m_parameters.buildDirectory.pathAppended("CMakeCache.txt.prev"); FilePath cmakeCacheTxtPrev = m_parameters.buildDirectory.pathAppended(Constants::CMAKE_CACHE_TXT_PREV);
if (!store) if (!store)
std::swap(cmakeCacheTxt, cmakeCacheTxtPrev); std::swap(cmakeCacheTxt, cmakeCacheTxtPrev);

View File

@@ -4,6 +4,7 @@
#include "projecttreehelper.h" #include "projecttreehelper.h"
#include "cmakeproject.h" #include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
@@ -98,7 +99,7 @@ void addCMakePresets(FolderNode *root, const Utils::FilePath &sourceDir)
presetFileNames << "CMakeUserPresets.json"; presetFileNames << "CMakeUserPresets.json";
const CMakeProject *cp = static_cast<const CMakeProject *>( const CMakeProject *cp = static_cast<const CMakeProject *>(
ProjectManager::projectForFile(sourceDir.pathAppended("CMakeLists.txt"))); ProjectManager::projectForFile(sourceDir.pathAppended(Constants::CMAKE_LISTS_TXT)));
if (cp && cp->presetsData().include) if (cp && cp->presetsData().include)
presetFileNames.append(cp->presetsData().include.value()); presetFileNames.append(cp->presetsData().include.value());