forked from qt-creator/qt-creator
CMakePM: Allow presets without buildDirectory
CMakePresets v3 relax the requirement of having the buildDirectory specified. This way Qt Creator should use its own mechanism of specifying the build directory. Change-Id: I6ba69e6a03cdc058e7b8fa540a6fc564356aba63 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1956,19 +1956,8 @@ CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory()
|
|||||||
|
|
||||||
// Skip the default shadow build directories for build types if we have presets
|
// Skip the default shadow build directories for build types if we have presets
|
||||||
const CMakeConfigItem presetItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
|
const CMakeConfigItem presetItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
|
||||||
if (!presetItem.isNull()) {
|
if (!presetItem.isNull())
|
||||||
const QString presetName = presetItem.expandedValue(k);
|
|
||||||
const auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
|
||||||
|
|
||||||
PresetsDetails::ConfigurePreset configurePreset
|
|
||||||
= Utils::findOrDefault(project->presetsData().configurePresets,
|
|
||||||
[&presetName] (const PresetsDetails::ConfigurePreset &preset) {
|
|
||||||
return preset.name == presetName;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (configurePreset.binaryDir)
|
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
for (int type = BuildTypeDebug; type != BuildTypeLast; ++type) {
|
for (int type = BuildTypeDebug; type != BuildTypeLast; ++type) {
|
||||||
BuildInfo info = createBuildInfo(BuildType(type));
|
BuildInfo info = createBuildInfo(BuildType(type));
|
||||||
|
|||||||
@@ -453,13 +453,11 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
|||||||
if (configurePreset.toolset && configurePreset.toolset.value().value)
|
if (configurePreset.toolset && configurePreset.toolset.value().value)
|
||||||
data->toolset = configurePreset.toolset.value().value.value();
|
data->toolset = configurePreset.toolset.value().value.value();
|
||||||
|
|
||||||
QString binaryDir = importPath.toString();
|
|
||||||
if (configurePreset.binaryDir) {
|
if (configurePreset.binaryDir) {
|
||||||
binaryDir = configurePreset.binaryDir.value();
|
QString binaryDir = configurePreset.binaryDir.value();
|
||||||
CMakePresets::Macros::expand(configurePreset, env, projectDirectory(), binaryDir);
|
CMakePresets::Macros::expand(configurePreset, env, projectDirectory(), binaryDir);
|
||||||
}
|
|
||||||
|
|
||||||
data->buildDirectory = Utils::FilePath::fromString(binaryDir);
|
data->buildDirectory = Utils::FilePath::fromString(binaryDir);
|
||||||
|
}
|
||||||
|
|
||||||
CMakePresets::Macros::updateToolchainFile(configurePreset,
|
CMakePresets::Macros::updateToolchainFile(configurePreset,
|
||||||
env,
|
env,
|
||||||
@@ -566,9 +564,24 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeProjectImporter::ensureBuildDirectory(DirectoryData &data, const Kit *k) const
|
||||||
|
{
|
||||||
|
if (!data.buildDirectory.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto cmakeBuildType = CMakeBuildConfigurationFactory::buildTypeFromByteArray(
|
||||||
|
data.cmakeBuildType);
|
||||||
|
auto buildInfo = CMakeBuildConfigurationFactory::createBuildInfo(cmakeBuildType);
|
||||||
|
|
||||||
|
data.buildDirectory = CMakeBuildConfiguration::shadowBuildDirectory(projectFilePath(),
|
||||||
|
k,
|
||||||
|
buildInfo.typeName,
|
||||||
|
buildInfo.buildType);
|
||||||
|
}
|
||||||
|
|
||||||
bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
||||||
{
|
{
|
||||||
const DirectoryData *data = static_cast<DirectoryData *>(directoryData);
|
DirectoryData *data = static_cast<DirectoryData *>(directoryData);
|
||||||
|
|
||||||
CMakeTool *cm = CMakeKitAspect::cmakeTool(k);
|
CMakeTool *cm = CMakeKitAspect::cmakeTool(k);
|
||||||
if (!cm || cm->cmakeExecutable() != data->cmakeBinary)
|
if (!cm || cm->cmakeExecutable() != data->cmakeBinary)
|
||||||
@@ -600,6 +613,8 @@ bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
|||||||
auto presetConfigItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
|
auto presetConfigItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
|
||||||
if (data->cmakePreset != presetConfigItem.expandedValue(k))
|
if (data->cmakePreset != presetConfigItem.expandedValue(k))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ensureBuildDirectory(*data, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(cmInputLog) << k->displayName()
|
qCDebug(cmInputLog) << k->displayName()
|
||||||
@@ -609,7 +624,7 @@ bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
|||||||
|
|
||||||
Kit *CMakeProjectImporter::createKit(void *directoryData) const
|
Kit *CMakeProjectImporter::createKit(void *directoryData) const
|
||||||
{
|
{
|
||||||
const DirectoryData *data = static_cast<DirectoryData *>(directoryData);
|
DirectoryData *data = static_cast<DirectoryData *>(directoryData);
|
||||||
|
|
||||||
return QtProjectImporter::createTemporaryKit(data->qt, [&data, this](Kit *k) {
|
return QtProjectImporter::createTemporaryKit(data->qt, [&data, this](Kit *k) {
|
||||||
const CMakeToolData cmtd = findOrCreateCMakeTool(data->cmakeBinary);
|
const CMakeToolData cmtd = findOrCreateCMakeTool(data->cmakeBinary);
|
||||||
@@ -629,6 +644,8 @@ Kit *CMakeProjectImporter::createKit(void *directoryData) const
|
|||||||
|
|
||||||
CMakeConfigurationKitAspect::setCMakePreset(k, data->cmakePreset);
|
CMakeConfigurationKitAspect::setCMakePreset(k, data->cmakePreset);
|
||||||
}
|
}
|
||||||
|
if (!data->cmakePreset.isEmpty())
|
||||||
|
ensureBuildDirectory(*data, k);
|
||||||
|
|
||||||
SysRootKitAspect::setSysRoot(k, data->sysroot);
|
SysRootKitAspect::setSysRoot(k, data->sysroot);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class CMakeTool;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
struct DirectoryData;
|
||||||
|
|
||||||
class CMakeProjectImporter : public QtSupport::QtProjectImporter
|
class CMakeProjectImporter : public QtSupport::QtProjectImporter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -39,6 +41,8 @@ private:
|
|||||||
void cleanupTemporaryCMake(ProjectExplorer::Kit *k, const QVariantList &vl);
|
void cleanupTemporaryCMake(ProjectExplorer::Kit *k, const QVariantList &vl);
|
||||||
void persistTemporaryCMake(ProjectExplorer::Kit *k, const QVariantList &vl);
|
void persistTemporaryCMake(ProjectExplorer::Kit *k, const QVariantList &vl);
|
||||||
|
|
||||||
|
void ensureBuildDirectory(DirectoryData &data, const ProjectExplorer::Kit *k) const;
|
||||||
|
|
||||||
Internal::PresetsData m_presetsData;
|
Internal::PresetsData m_presetsData;
|
||||||
Utils::TemporaryDirectory m_presetsTempDir;
|
Utils::TemporaryDirectory m_presetsTempDir;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
"name": "mingw",
|
"name": "mingw",
|
||||||
"displayName": "MinGW 11.2.0",
|
"displayName": "MinGW 11.2.0",
|
||||||
"generator": "Ninja",
|
"generator": "Ninja",
|
||||||
"binaryDir": "${sourceDir}/build-${presetName}-release",
|
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"CMAKE_BUILD_TYPE": "Release",
|
"CMAKE_BUILD_TYPE": "Release",
|
||||||
"CMAKE_PREFIX_PATH": "c:/Qt/6.3.2/mingw_64"
|
"CMAKE_PREFIX_PATH": "c:/Qt/6.3.2/mingw_64"
|
||||||
@@ -29,6 +28,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mingw-make",
|
"name": "mingw-make",
|
||||||
|
"binaryDir": "${sourceDir}/build-${presetName}-release",
|
||||||
"displayName": "MinGW 11.2.0 Makefiles",
|
"displayName": "MinGW 11.2.0 Makefiles",
|
||||||
"generator": "MinGW Makefiles",
|
"generator": "MinGW Makefiles",
|
||||||
"inherits" : "mingw"
|
"inherits" : "mingw"
|
||||||
|
|||||||
Reference in New Issue
Block a user