cmake: Stop parsing after `--` when detecting script mode

Fixes #24220
3 files changed