cmake: Improve error message if CMAKE_BINARY_DIR not writable
New behavior:
cmake -B /usr/bin
CMake Error: Unable to (re)create the private pkgRedirects directory:
/usr/bin/CMakeFiles/pkgRedirects
This may be caused by not having read/write access to CMAKE_BINARY_DIR. Try specifying a location with read/write access like:
cmake -B ./build
If using a CMake presets file, ensure that preset parameter "binaryDir" expands to a writable directory.
I figured rather than add new logic, simply give more helpful error message when the failure occurs. This is to avoid risk from obscure filesystems / platforms that might have unexpected directory properties but still work currently.
Someday we could consider distinct error messages if one specified CMAKE_BINARY_DIR as a file instead of a writeable directory. With the new code, this error results:
cmake -B CMakeLists.txt
CMake Error: Unable to (re)create the private pkgRedirects directory:
/tmp/CMakeLists.txt/CMakeFiles/pkgRedirects
This may be caused by not having read/write access to CMAKE_BINARY_DIR. Try specifying a location with read/write access like:
cmake -B ./build
If using a CMake presets file, ensure that preset parameter "binaryDir" expands to a writable directory.
Fixes: #24407 (closed)
Topic-rename: cmake-non-writable-build-dir
Edited by Brad King