source_group(TREE ... FILES ...) behaves unexpected for empty files list
I have written an utlity function to easily create source groups for any target, it creates multiple groups like this:
source_group(
TREE "${binaryTreeDir}"
PREFIX "Generated Files"
FILES ${filterSources}
)
This was working well for many months, but recently public projects fail because sometimes calls like the one above try to add files that are not part of the tree, like here. The user discovered that this happens since CMake 3.28.0-rc1 because of d85238a2. The code above fails because sometimes ${filterSources}
is an empty list. Previously, this created an empty group, but since that commit, it tries to add all files of ${CMAKE_CURRENT_SOURCE_DIR}
.
According to the commit message, this should happen if no FILES keyword is present. In my case, the keyword is present, just no arguments have been given to it. I think it is a regression to handle this case as if the keyword is missing, even plain CMake script can differentiate between a nonpresent keyword and a keyword without arguments.