diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 56291ab159..3f62661807 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -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> value = { + "CMAKE_INSTALL_PREFIX", var + }; + auto prop = cache_to_property(value); add_to_property_list(ret, std::move(prop)); } } diff --git a/Tests/CMakeGUI/CMakeGUITest.cmake b/Tests/CMakeGUI/CMakeGUITest.cmake index 7f0d187a96..95f05d8e75 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cmake +++ b/Tests/CMakeGUI/CMakeGUITest.cmake @@ -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" diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx index 99c006b8b3..1b4919f955 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cxx +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -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{}; diff --git a/Tests/CMakeGUI/presetArg-installDir/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-installDir/CMakePresets.json.in new file mode 100644 index 0000000000..801f257260 --- /dev/null +++ b/Tests/CMakeGUI/presetArg-installDir/CMakePresets.json.in @@ -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" + } + } + } + ] +}