CMakePresets.json: Don't warn if no path argument is given

If --preset is specified with no path argument, use the current
directory as the source directory, the preset's binaryDir as the
binary directory, and don't issue the standard warning for no path
specified.

Fixes: #21386
This commit is contained in:
Kyle Edwards
2020-11-02 09:26:51 -05:00
parent 013c4133f7
commit cb2d01c182
4 changed files with 22 additions and 1 deletions

View File

@@ -1005,9 +1005,15 @@ void cmake::SetArgs(const std::vector<std::string>& args)
const bool haveSourceDir = !this->GetHomeDirectory().empty();
const bool haveBinaryDir = !this->GetHomeOutputDirectory().empty();
const bool havePreset =
#ifdef CMAKE_BOOTSTRAP
false;
#else
!presetName.empty();
#endif
if (this->CurrentWorkingMode == cmake::NORMAL_MODE && !haveSourceDir &&
!haveBinaryDir) {
!haveBinaryDir && !havePreset) {
this->IssueMessage(
MessageType::WARNING,
"No source or binary directory provided. Both will be assumed to be "

View File

@@ -169,6 +169,11 @@
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build"
},
{
"name": "GoodNoSourceArg",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build"
},
{
"name": "GoodInheritanceParentBase",
"hidden": true,

View File

@@ -0,0 +1,3 @@
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
test_variable(CMAKE_BINARY_DIR "" "${CMAKE_SOURCE_DIR}/build")

View File

@@ -179,6 +179,13 @@ unset(RunCMake_TEST_NO_CLEAN)
unset(CMakePresets_SOURCE_ARG)
unset(RunCMake_TEST_BINARY_DIR)
unset(CMakePresets_NO_S_ARG)
set(CMakePresets_NO_SOURCE_ARGS 1)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/GoodNoSourceArg")
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_presets(GoodNoSourceArg)
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)
unset(CMakePresets_NO_SOURCE_ARGS)
run_cmake_presets(GoodInheritanceParent)
run_cmake_presets(GoodInheritanceChild)
run_cmake_presets(GoodInheritanceOverride)