diff --git a/src/plugins/cmakeprojectmanager/CMakeProjectManager.json.in b/src/plugins/cmakeprojectmanager/CMakeProjectManager.json.in
index c5022d24a32..b34a5b09254 100644
--- a/src/plugins/cmakeprojectmanager/CMakeProjectManager.json.in
+++ b/src/plugins/cmakeprojectmanager/CMakeProjectManager.json.in
@@ -38,6 +38,7 @@
" ",
" CMake Project file",
" ",
+ " ",
" ",
""
]
diff --git a/src/plugins/cmakeprojectmanager/builddirparameters.cpp b/src/plugins/cmakeprojectmanager/builddirparameters.cpp
index 90f5f522299..0785ca8d959 100644
--- a/src/plugins/cmakeprojectmanager/builddirparameters.cpp
+++ b/src/plugins/cmakeprojectmanager/builddirparameters.cpp
@@ -5,6 +5,7 @@
#include "cmakebuildconfiguration.h"
#include "cmakebuildsystem.h"
+#include "cmakeprojectconstants.h"
#include "cmakekitaspect.h"
#include "cmaketoolmanager.h"
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index d7d6b14ce93..3b5935dd8fa 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -29,11 +29,24 @@ using namespace CMakeProjectManager::Internal;
namespace CMakeProjectManager {
+static FilePath cmakeListTxtFromFilePath(const FilePath &filepath)
+{
+ if (filepath.endsWith(Constants::CMAKE_CACHE_TXT)) {
+ QString errorMessage;
+ const CMakeConfig config = CMakeConfig::fromFile(filepath, &errorMessage);
+ const FilePath cmakeListsTxt = config.filePathValueOf("CMAKE_HOME_DIRECTORY")
+ .pathAppended(Constants::CMAKE_LISTS_TXT);
+ if (cmakeListsTxt.exists())
+ return cmakeListsTxt;
+ }
+ return filepath;
+}
+
/*!
\class CMakeProject
*/
CMakeProject::CMakeProject(const FilePath &fileName)
- : Project(Utils::Constants::CMAKE_MIMETYPE, fileName)
+ : Project(Utils::Constants::CMAKE_MIMETYPE, cmakeListTxtFromFilePath(fileName))
, m_settings(this, true)
{
setId(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
@@ -47,6 +60,9 @@ CMakeProject::CMakeProject(const FilePath &fileName)
setHasMakeInstallEquivalent(false);
readPresets();
+
+ if (fileName.endsWith(Constants::CMAKE_CACHE_TXT))
+ m_buildDirToImport = fileName.parentDir();
}
CMakeProject::~CMakeProject()
@@ -332,6 +348,11 @@ void CMakeProject::readPresets()
}
}
+FilePath CMakeProject::buildDirectoryToImport() const
+{
+ return m_buildDirToImport;
+}
+
bool CMakeProject::setupTarget(Target *t)
{
t->updateDefaultBuildConfigurations();
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h
index 832977c41a1..2bad55249e2 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.h
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.h
@@ -31,6 +31,7 @@ public:
Internal::PresetsData presetsData() const;
void readPresets();
+ Utils::FilePath buildDirectoryToImport() const;
void setOldPresetKits(const QList &presetKits) const;
QList oldPresetKits() const;
@@ -54,6 +55,7 @@ private:
ProjectExplorer::Tasks m_issues;
Internal::PresetsData m_presetsData;
Internal::CMakeSpecificSettings m_settings;
+ Utils::FilePath m_buildDirToImport;
};
} // namespace CMakeProjectManager
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
index 1766719178f..25361499116 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
@@ -167,6 +167,9 @@ static QString displayPresetName(const QString &presetName)
FilePaths CMakeProjectImporter::importCandidates()
{
+ if (!m_project->buildDirectoryToImport().isEmpty())
+ return {m_project->buildDirectoryToImport()};
+
FilePaths candidates = presetCandidates();
if (candidates.isEmpty()) {
@@ -299,6 +302,13 @@ static QVariant findOrRegisterDebugger(
Target *CMakeProjectImporter::preferredTarget(const QList &possibleTargets)
{
+ if (!m_project->buildDirectoryToImport().isEmpty()) {
+ return Utils::findOrDefault(possibleTargets, [this](const Target *t) {
+ return t->activeBuildConfiguration()->buildDirectory()
+ == m_project->buildDirectoryToImport();
+ });
+ }
+
for (Kit *kit : m_project->oldPresetKits()) {
const bool haveKit = Utils::contains(possibleTargets, [kit](const auto &target) {
return target->kit() == kit;