Skip to content
Snippets Groups Projects

cmake: Fix option parsing robustness issues

Merged Craig Scott requested to merge craig.scott/cmake:cmake-option-parsing into master

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

Pipeline #127560 passed

Pipeline passed for 27eb7c5b on craig.scott:cmake-option-parsing

Merged by Kitware RobotKitware Robot 6 years ago (Jan 14, 2019 12:25pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading