forked from qt-creator/qt-creator
CMakePM: Fix Qt SDK Kits when ninja is missing
Qt SDK is setting "Ninja" as default generator, make sure to get a working generator when CMake is newly registered as a default tool. Fixes: QTCREATORBUG-31129 Change-Id: I6b93a8904696eedadec04c882495c644db7ddce7 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -97,6 +97,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant defaultValue(const Kit *k) const;
|
QVariant defaultValue(const Kit *k) const;
|
||||||
|
bool isNinjaPresent(const Kit *k, const CMakeTool *tool) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMakeConfigurationKitAspectFactory : public KitAspectFactory
|
class CMakeConfigurationKitAspectFactory : public KitAspectFactory
|
||||||
@@ -556,6 +557,17 @@ CMakeGeneratorKitAspectFactory::CMakeGeneratorKitAspectFactory()
|
|||||||
setDescription(Tr::tr("CMake generator defines how a project is built when using CMake.<br>"
|
setDescription(Tr::tr("CMake generator defines how a project is built when using CMake.<br>"
|
||||||
"This setting is ignored when using other build systems."));
|
"This setting is ignored when using other build systems."));
|
||||||
setPriority(19000);
|
setPriority(19000);
|
||||||
|
|
||||||
|
auto updateKits = [this] {
|
||||||
|
if (KitManager::isLoaded()) {
|
||||||
|
for (Kit *k : KitManager::kits())
|
||||||
|
fix(k);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//make sure the default value is set if a new default CMake is set
|
||||||
|
connect(CMakeToolManager::instance(), &CMakeToolManager::defaultCMakeChanged,
|
||||||
|
this, updateKits);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CMakeGeneratorKitAspect::generator(const Kit *k)
|
QString CMakeGeneratorKitAspect::generator(const Kit *k)
|
||||||
@@ -664,18 +676,7 @@ QVariant CMakeGeneratorKitAspectFactory::defaultValue(const Kit *k) const
|
|||||||
return g.matches("Ninja");
|
return g.matches("Ninja");
|
||||||
});
|
});
|
||||||
if (it != known.constEnd()) {
|
if (it != known.constEnd()) {
|
||||||
const bool hasNinja = [k, tool] {
|
if (isNinjaPresent(k, tool))
|
||||||
if (Internal::settings(nullptr).ninjaPath().isEmpty()) {
|
|
||||||
auto findNinja = [](const Environment &env) -> bool {
|
|
||||||
return !env.searchInPath("ninja").isEmpty();
|
|
||||||
};
|
|
||||||
if (!findNinja(tool->filePath().deviceEnvironment()))
|
|
||||||
return findNinja(k->buildEnvironment());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (hasNinja)
|
|
||||||
return GeneratorInfo("Ninja").toVariant();
|
return GeneratorInfo("Ninja").toVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -725,6 +726,18 @@ QVariant CMakeGeneratorKitAspectFactory::defaultValue(const Kit *k) const
|
|||||||
return GeneratorInfo(it->name).toVariant();
|
return GeneratorInfo(it->name).toVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMakeGeneratorKitAspectFactory::isNinjaPresent(const Kit *k, const CMakeTool *tool) const
|
||||||
|
{
|
||||||
|
if (Internal::settings(nullptr).ninjaPath().isEmpty()) {
|
||||||
|
auto findNinja = [](const Environment &env) -> bool {
|
||||||
|
return !env.searchInPath("ninja").isEmpty();
|
||||||
|
};
|
||||||
|
if (!findNinja(tool->filePath().deviceEnvironment()))
|
||||||
|
return findNinja(k->buildEnvironment());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Tasks CMakeGeneratorKitAspectFactory::validate(const Kit *k) const
|
Tasks CMakeGeneratorKitAspectFactory::validate(const Kit *k) const
|
||||||
{
|
{
|
||||||
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
|
||||||
@@ -783,7 +796,7 @@ void CMakeGeneratorKitAspectFactory::fix(Kit *k)
|
|||||||
[info](const CMakeTool::Generator &g) {
|
[info](const CMakeTool::Generator &g) {
|
||||||
return g.matches(info.generator);
|
return g.matches(info.generator);
|
||||||
});
|
});
|
||||||
if (it == known.constEnd()) {
|
if (it == known.constEnd() || (info.generator == "Ninja" && !isNinjaPresent(k, tool))) {
|
||||||
GeneratorInfo dv;
|
GeneratorInfo dv;
|
||||||
dv.fromVariant(defaultValue(k));
|
dv.fromVariant(defaultValue(k));
|
||||||
setGeneratorInfo(k, dv);
|
setGeneratorInfo(k, dv);
|
||||||
|
Reference in New Issue
Block a user