PrintHelpers: Fix target SOURCES property
CMakePrintHelpers.cmake
Bugfix to It's been a long-standing bug (#14883 (closed)) in CMakePrintHelpers that the cmake_print_properties()
function cannot print the SOURCES
property of a requested TARGET
, confusing it with a request to print properties of SOURCES
.
This MR works around this by parsing the arguments in two stages, so that a SOURCES
that comes after the PROPERTIES
keyword is handled differently from a SOURCES
that comes before it.
This adds the new restriction that the "mode"/scope keyword (TARGETS
SOURCES
DIRECTORIES
etc...) and its arguments must precede the PROPERTIES
keyword and its arguments. In other words:
-
Both of these are now valid and will be interpreted correctly, whereas previously only the first was, and the second caused a
FATAL_ERROR
:cmake_print_properties(SOURCES foo.c PROPERTIES LANGUAGE) cmake_print_properties(TARGETS foo PROPERTIES SOURCES)
-
This, OTOH, which used to be valid, no longer is, and will now trigger a
FATAL_ERROR
:cmake_print_properties(PROPERTIES LANGUAGE SOURCES foo.c)
The new restriction is somewhat unfortunate (the unfortunate part being that it wasn't previously imposed, but should have been), however the only realistic alternative would be to change the scope keyword for SOURCE
type requests from SOURCES
to SOURCE_FILES
, which would be at least as big of a breaking change.
Tests added
In addition, after what felt like a half-dozen false starts flailing around inside the Tests/
directory, a second commit also adds basic functionality tests for the CMakePrintHelpers
module, in the directory Tests/RunCMake/PrintHelpers/
. Tests added are:
-
Variables
: Test the results of acmake_print_variables()
call on two variables set within the test script. -
Properties
: Testcmake_print_properties()
calls on a pair ofSOURCES
and a pair ofTARGETS
, printing some basic properties. -
PropertiesSources
: Specifically test the fix implemented in the previous commit, by callingcmake_print_properties(TARGET ___ PROPERTIES SOURCES)
which, in any CMake prior to this fix, produced aFATAL_ERROR
.
Hopefully I haven't made too much of a disaster of the test construction.
Additional housekeeping
In addition to fixing the bug, the commits in this MR:
-
Update the module documentation to display a more accurate grammar for the
cmake_print_properties()
command (using the more modern notation found in the documentation for commands likeset_property()
), and to make the argument order restrictions explicit. -
Remove
PROPERTIES
from the list of scope keywords presented in the error messages whencmake_print_properties()
fails. Instead, the${multiValueArgs}
argument to the second-stagecmake_parse_arguments()
call is used to construct an error message that will always accurately reflect the currently-implemented syntax.
Fixes: #14883 (closed)