mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmake-gui: Honor installDir from configure presets
The GUI ignored a preset's installDir, so CMAKE_INSTALL_PREFIX fell back to the platform default instead of the value the command line uses. This fixes that by reading installDir in QCMake::properties(), and while we're there, it applies toolchainFile after the cacheVariables loop so both override a same-named entry. Fixes: #27804
This commit is contained in:
@@ -470,6 +470,14 @@ QCMakePropertyList QCMake::properties() const
|
||||
auto const& p =
|
||||
this->CMakePresetsGraph.ConfigurePresets.at(presetName).Expanded;
|
||||
if (p) {
|
||||
for (auto const& v : p->CacheVariables) {
|
||||
if (!v.second) {
|
||||
continue;
|
||||
}
|
||||
auto prop = cache_to_property(v);
|
||||
add_to_property_list(ret, std::move(prop));
|
||||
}
|
||||
// Dedicated fields override same-named cacheVariables, so apply last.
|
||||
if (!p->ToolchainFile.empty()) {
|
||||
using CacheVariable = cmCMakePresetsGraph::CacheVariable;
|
||||
CacheVariable var{ "FILEPATH", p->ToolchainFile };
|
||||
@@ -479,11 +487,13 @@ QCMakePropertyList QCMake::properties() const
|
||||
auto prop = cache_to_property(value);
|
||||
add_to_property_list(ret, std::move(prop));
|
||||
}
|
||||
for (auto const& v : p->CacheVariables) {
|
||||
if (!v.second) {
|
||||
continue;
|
||||
}
|
||||
auto prop = cache_to_property(v);
|
||||
if (!p->InstallDir.empty()) {
|
||||
using CacheVariable = cmCMakePresetsGraph::CacheVariable;
|
||||
CacheVariable var{ "PATH", p->InstallDir };
|
||||
std::pair<std::string, cm::optional<CacheVariable>> value = {
|
||||
"CMAKE_INSTALL_PREFIX", var
|
||||
};
|
||||
auto prop = cache_to_property(value);
|
||||
add_to_property_list(ret, std::move(prop));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +176,11 @@ run_cmake_gui_test(presetArg:presetConfigExists
|
||||
-S "${CMakeGUITest_BINARY_DIR}/presetArg-presetConfigExists/src"
|
||||
"--preset=ninja"
|
||||
)
|
||||
run_cmake_gui_test(presetArg:installDir
|
||||
ARGS
|
||||
-S "${CMakeGUITest_BINARY_DIR}/presetArg-installDir/src/"
|
||||
"--preset=installDir"
|
||||
)
|
||||
run_cmake_gui_test(presetArg:noExist
|
||||
ARGS
|
||||
-S "${CMakeGUITest_BINARY_DIR}/presetArg-noExist/src"
|
||||
|
||||
@@ -353,6 +353,33 @@ void CMakeGUITest::presetArg_data()
|
||||
<< CMakeGUITest_BINARY_DIR "/presetArg-presetConfigExists/src"
|
||||
<< CMakeGUITest_BINARY_DIR "/presetArg-presetConfigExists/src/build"
|
||||
<< makePresetProperties("presetArg-presetConfigExists");
|
||||
QCMakePropertyList installDirProperties{
|
||||
QCMakeProperty{
|
||||
/*Key=*/"CMAKE_INSTALL_PREFIX",
|
||||
/*Value=*/
|
||||
QString::fromLocal8Bit(CMakeGUITest_BINARY_DIR
|
||||
"/presetArg-installDir/src/install"),
|
||||
/*Strings=*/{},
|
||||
/*Help=*/"",
|
||||
/*Type=*/QCMakeProperty::PATH,
|
||||
/*Advanced=*/false,
|
||||
},
|
||||
QCMakeProperty{
|
||||
/*Key=*/"CMAKE_TOOLCHAIN_FILE",
|
||||
/*Value=*/
|
||||
QString::fromLocal8Bit(CMakeGUITest_BINARY_DIR
|
||||
"/presetArg-installDir/src/toolchain.cmake"),
|
||||
/*Strings=*/{},
|
||||
/*Help=*/"",
|
||||
/*Type=*/QCMakeProperty::FILEPATH,
|
||||
/*Advanced=*/false,
|
||||
},
|
||||
};
|
||||
QTest::newRow("installDir")
|
||||
<< WindowSetupHelper{} << "installDir"
|
||||
<< CMakeGUITest_BINARY_DIR "/presetArg-installDir/src"
|
||||
<< CMakeGUITest_BINARY_DIR "/presetArg-installDir/src/build"
|
||||
<< installDirProperties;
|
||||
QTest::newRow("noExist") << WindowSetupHelper{} << QString{}
|
||||
<< CMakeGUITest_BINARY_DIR "/presetArg-noExist/src"
|
||||
<< "" << QCMakePropertyList{};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "installDir",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"installDir": "${sourceDir}/install",
|
||||
"toolchainFile": "${sourceDir}/toolchain.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_INSTALL_PREFIX": {
|
||||
"type": "PATH",
|
||||
"value": "${sourceDir}/bad_install"
|
||||
},
|
||||
"CMAKE_TOOLCHAIN_FILE": {
|
||||
"type": "FILEPATH",
|
||||
"value": "${sourceDir}/bad_toolchain.cmake"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user