forked from qt-creator/qt-creator
CMakePM: Allow using CMakeCache.txt as project file
The CMakeCache.txt file has CMAKE_HOME_DIRECTORY pointing to the project source directory used to configure the project. Use that as source directory, and the directory of CMakeCache.txt as the build directory. Task-number: QTCREATORBUG-24439 Task-number: QTCREATORBUG-30507 Change-Id: Ib032406b014f8f7ee5fc1d47bbe3796c6b8f8060 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
" <sub-class-of type='text/x-cmake'/>",
|
||||
" <comment>CMake Project file</comment>",
|
||||
" <glob pattern='CMakeLists.txt'/>",
|
||||
" <glob pattern='CMakeCache.txt'/>",
|
||||
" </mime-type>",
|
||||
"</mime-info>"
|
||||
]
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakebuildsystem.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakekitaspect.h"
|
||||
#include "cmaketoolmanager.h"
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -31,6 +31,7 @@ public:
|
||||
|
||||
Internal::PresetsData presetsData() const;
|
||||
void readPresets();
|
||||
Utils::FilePath buildDirectoryToImport() const;
|
||||
|
||||
void setOldPresetKits(const QList<ProjectExplorer::Kit *> &presetKits) const;
|
||||
QList<ProjectExplorer::Kit *> 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
|
||||
|
@@ -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<Target *> &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;
|
||||
|
Reference in New Issue
Block a user