forked from qt-creator/qt-creator
CMakePM: Detect CMAKE_PREFIX_PATH from qmake's path when empty
If qmake -query fails for some reason then %{Qt:QT_INSTALL_PREFIX} would evaluate to an empty string and CMAKE_PREFIX_PATH will not help CMake find Qt packages. By using the path to qmake itself we can safely determine a valid CMAKE_PREFIX_PATH and CMAKE_FIND_ROOT_PATH. Fixes: QTCREATORBUG-31194 Change-Id: Ib649dd57bfe3a97ef93a42603d83331922f99612 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -26,6 +26,43 @@ namespace CMakeProjectManager::Internal {
|
||||
|
||||
BuildDirParameters::BuildDirParameters() = default;
|
||||
|
||||
static void updateCMakePathsFromQMake(QStringList &initialCMakeArguments)
|
||||
{
|
||||
const CMakeConfigItem qmake = CMakeConfigItem::fromString(
|
||||
Utils::findOrDefault(initialCMakeArguments, [](const QString &arg) {
|
||||
return arg.startsWith("-DQT_QMAKE_EXECUTABLE");
|
||||
}));
|
||||
const FilePath qmakeFilePath = FilePath::fromUtf8(qmake.value);
|
||||
if (qmakeFilePath.isEmpty())
|
||||
return;
|
||||
|
||||
// ~Qt/6.x/platform/bin/qmake -> ~Qt/6.x/platform
|
||||
const QByteArray qmakePrefixPath = qmakeFilePath.parentDir().parentDir().toString().toUtf8();
|
||||
const QByteArrayList cmakePathsVariables = {"CMAKE_PREFIX_PATH", "CMAKE_FIND_ROOT_PATH"};
|
||||
|
||||
for (const QByteArray &var : cmakePathsVariables) {
|
||||
const QString varPrefix = QString("-D") + var;
|
||||
auto it = std::find_if(
|
||||
initialCMakeArguments.begin(),
|
||||
initialCMakeArguments.end(),
|
||||
[varPrefix](const QString &arg) { return arg.startsWith(varPrefix); });
|
||||
|
||||
if (it == initialCMakeArguments.end())
|
||||
continue;
|
||||
|
||||
CMakeConfigItem cmakeVar = CMakeConfigItem::fromString(*it);
|
||||
if (cmakeVar.isNull())
|
||||
continue;
|
||||
|
||||
if (cmakeVar.value.isEmpty())
|
||||
cmakeVar.value = qmakePrefixPath;
|
||||
else
|
||||
cmakeVar.value += ";" + qmakePrefixPath;
|
||||
|
||||
*it = cmakeVar.toString();
|
||||
}
|
||||
}
|
||||
|
||||
BuildDirParameters::BuildDirParameters(CMakeBuildSystem *buildSystem)
|
||||
{
|
||||
QTC_ASSERT(buildSystem, return);
|
||||
@@ -40,6 +77,11 @@ BuildDirParameters::BuildDirParameters(CMakeBuildSystem *buildSystem)
|
||||
});
|
||||
initialCMakeArguments = Utils::filtered(expandedArguments,
|
||||
[](const QString &s) { return !s.isEmpty(); });
|
||||
|
||||
const bool noQtInstallPrefix = expander->expand(QString("%{Qt:QT_INSTALL_PREFIX}")).isEmpty();
|
||||
if (noQtInstallPrefix)
|
||||
updateCMakePathsFromQMake(initialCMakeArguments);
|
||||
|
||||
configurationChangesArguments = Utils::transform(buildSystem->configurationChangesArguments(),
|
||||
[this](const QString &s) {
|
||||
return expander->expand(s);
|
||||
|
Reference in New Issue
Block a user