diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-07-16 14:18:31 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2021-07-16 14:25:40 (GMT) |
commit | aa874dc6090cf6b6c9621572419738d105ff4ba3 (patch) | |
tree | c61ee79c28a4d8b3ff104eb317195eb738c8f2f7 | |
parent | 7c6234dd21b7af95e7edea6b281d859dafb2ae81 (diff) | |
download | CMake-aa874dc6090cf6b6c9621572419738d105ff4ba3.zip CMake-aa874dc6090cf6b6c9621572419738d105ff4ba3.tar.gz CMake-aa874dc6090cf6b6c9621572419738d105ff4ba3.tar.bz2 |
CMakePresets.json: Fix expansion issue with empty binaryDir
When resolving binaryDir into a full path from a relative path, we
forgot to check if binaryDir is altogether empty, causing empty
binaryDir's to resolve to the source directory. Fix this.
Fixes: #22434
4 files changed, 24 insertions, 4 deletions
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index 2f9972c..fd578fa 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -197,11 +197,13 @@ bool ExpandMacros(const cmCMakePresetsFile& file, std::string binaryDir = preset.BinaryDir; CHECK_EXPAND(out, binaryDir, macroExpanders, file.GetVersion(preset)) - if (!cmSystemTools::FileIsFullPath(binaryDir)) { - binaryDir = cmStrCat(file.SourceDir, '/', binaryDir); + if (!binaryDir.empty()) { + if (!cmSystemTools::FileIsFullPath(binaryDir)) { + binaryDir = cmStrCat(file.SourceDir, '/', binaryDir); + } + out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir); + cmSystemTools::ConvertToUnixSlashes(out->BinaryDir); } - out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir); - cmSystemTools::ConvertToUnixSlashes(out->BinaryDir); if (!preset.InstallDir.empty()) { std::string installDir = preset.InstallDir; diff --git a/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.cmake b/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.cmake new file mode 100644 index 0000000..ae8a0de --- /dev/null +++ b/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.cmake @@ -0,0 +1,4 @@ +include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake) + +get_filename_component(_parent_dir "${CMAKE_SOURCE_DIR}" DIRECTORY) +test_variable(CMAKE_BINARY_DIR "" "${_parent_dir}/OptionalBinaryDirFieldNoS-build") diff --git a/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.json.in b/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.json.in new file mode 100644 index 0000000..0e3addd --- /dev/null +++ b/Tests/RunCMake/CMakePresets/OptionalBinaryDirFieldNoS.json.in @@ -0,0 +1,9 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "OptionalBinaryDirFieldNoS", + "generator": "@RunCMake_GENERATOR@" + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake index 3b9806a..31bd8a4 100644 --- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake @@ -312,6 +312,11 @@ unset(CMakePresets_FILE) # Test optional generator and buildDir fields run_cmake_presets(OptionalBinaryDirField -B "${RunCMake_BINARY_DIR}/OptionalBinaryDirField/build") run_cmake_presets(OptionalGeneratorField -G "${RunCMake_GENERATOR}") +set(CMakePresets_NO_S_ARG TRUE) +set(CMakePresets_SOURCE_ARG "../OptionalBinaryDirFieldNoS") +run_cmake_presets(OptionalBinaryDirFieldNoS) +unset(CMakePresets_SOURCE_ARG) +unset(CMakePresets_NO_S_ARG) # Test the example from the documentation file(READ "${RunCMake_SOURCE_DIR}/../../../Help/manual/presets/example.json" _example) |