cmake: Fix option parsing robustness issues
The cmake command-line parsing logic did not always set valid source and binary directories. In particular, with the formal addition/documentation of the -S and -B options in CMake 3.13, specifying just -S would result in an empty string for the binary directory. This results in the root directory being used as the build directory and in the case of Windows where the current user will often have write access to there, CMake pollutes the root directory with build output. No error message was being logged. It is ambiguous whether specifying -S without -B is valid - the cmake command docs seem to show them as always specified together, but the 3.13 release notes state that they can be used independently. Either way though, it is already clear that people often try to use just -S without -B (I've seen multiple people do this), so best we make that behavior predictable and safe.
While clearing up the -S/-B handling and updating the tests, it also became clear that although an error message was logged if no script file name was given with the -P option, processing would continue with the -P omitted from the arguments. If the remaining arguments formed a valid set, cmake would continue processing and could have fairly arbitrary unintended side effects. This becomes more important with the -S/-B handling fixed since the likelihood of a valid set of options increases (source/binary directory defaults are applied more consistently now).
Merge request reports
Activity
Errors:
- commit 0d673b5f is not allowed because the following files are not formatted according to the 'clang-format-6.0' check:
Source/cmake.cxx
. Post a comment ending in the lineDo: reformat
to rewrite the MR source branch automatically.
Warnings:
- Eligible for the 3.13.x branch.
The warnings do not need to be fixed, but it is recommended to do so.
Please rewrite commits to fix the errors listed above (adding fixup commits will not resolve the errors) and force-push the branch again to update the merge request.
- commit 0d673b5f is not allowed because the following files are not formatted according to the 'clang-format-6.0' check:
added 1 commit
- 76612572 - cmake: Ensure source and binary dirs are set
added workflow:nightly-testing label and removed workflow:wip label
assigned to @brad.king
removed workflow:nightly-testing label
mentioned in commit 1f411b0c
mentioned in commit c63a19e9
We had some build scripts that implicitly used the working directory fallback when no directory was specified.
Using a clone of https://github.com/google/flatbuffers as the working directory, on cmake 3.13.2 one could run
cmake -G "Unix Makefiles"
and the command would run correctly. cmake 3.13.3 gave an error:
"CMake Error: No source or binary directory provided"
. Changing the command to:cmake -G "Unix Makefiles" .
fixed the problem.
Just figured this may be good to know in case other people were also relying on this bug :)
Edited by Jeremy Day
mentioned in issue #18817 (closed)