Script mode (-P) documentation appears to imply non-existent behavior
The Run a Script docs talk about cmake “parsing“ arguments preceding --
—which tends to imply that it will reject arguments before --
for which parsing fails, and that there's a set of arguments that will be meaningful to CMake—and it explicitly documents -D
as a meaningful argument that “Define[s] a variable for script mode”—which tends to imply that the script will run with the given variables set per the command-line options. My experiments seem to contradict that. I think my presumptions about what the documentation implies are at least plausible and reasonable, so if some other meaning is intended, that should be clarified. Otherwise it should be corrected.
I built this script:
#!/usr/bin/env cmake -P
macro(dump_cmake_variables)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
if ((NOT DEFINED ARGV0) OR _variableName MATCHES ${ARGV0})
message(STATUS "${_variableName}=${${_variableName}}")
endif()
endforeach()
endmacro()
dump_cmake_variables(.*)
Ran it with ./x -Q jxx -D FOOBAR=1 quack --bizt -- --final box
and got the attachedoutput.txt, with no errors. Note that FOOBAR
doesn't appear to be a defined variable and -Q
, which isn't a valid cmake option isn't rejected.