Skip to content

Commit 8d93815

Browse files
committed
source_group command ensures that FILES arguments are actually files
1 parent 4ccf40e commit 8d93815

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Source/cmSourceGroupCommand.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ std::vector<std::string> prepareFilesPathsForTree(
8080
prepared.reserve(filesPaths.size());
8181

8282
for (auto const& filePath : filesPaths) {
83-
prepared.push_back(prepareFilePathForTree(filePath, currentSourceDir));
83+
// If provided file path is actually not a file, silently ignore it.
84+
if (cmSystemTools::FileExists(filePath, /*isFile=*/true)) {
85+
prepared.push_back(prepareFilePathForTree(filePath, currentSourceDir));
86+
}
8487
}
8588

8689
return prepared;

Tests/SourceGroups/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ set(tree_files_with_prefix ${root}/tree_prefix_foo.c
4242
set(tree_files_with_empty_prefix ${root}/tree_empty_prefix_foo.c
4343
tree_empty_prefix_bar.c)
4444

45+
set(tree_files_which_are_actually_directories ${root}
46+
${root}/
47+
${root}/sub1
48+
${root}/sub1/)
49+
4550
source_group(TREE ${root} FILES ${tree_files_without_prefix})
4651

52+
# Should not crash and not add any files - just silently ignore the directories
53+
source_group(TREE ${root} FILES ${tree_files_which_are_actually_directories})
54+
4755
source_group(FILES ${tree_files_with_prefix} PREFIX tree_root/subgroup TREE ${root})
4856

4957
source_group(PREFIX "" FILES ${tree_files_with_empty_prefix} TREE ${root})

0 commit comments

Comments
 (0)