-
Notifications
You must be signed in to change notification settings - Fork 258
[cmake] Use source_group TREE on source_group_by_folder #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,22 +27,27 @@ function(source_group_by_folder target) | |||||||||
| endif() | ||||||||||
| endif() | ||||||||||
| foreach(file ${files}) | ||||||||||
| if(file MATCHES "^\\$<") | ||||||||||
| list(POP_FRONT files) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MAJOR] Incorrect list manipulation during iteration. The
Suggested change
|
||||||||||
| continue() | ||||||||||
| endif() | ||||||||||
|
|
||||||||||
| if(NOT IS_ABSOLUTE ${file}) | ||||||||||
| set(file ${CMAKE_CURRENT_SOURCE_DIR}/${file}) | ||||||||||
| endif() | ||||||||||
| file(RELATIVE_PATH relative_file ${relative_dir} ${file}) | ||||||||||
| get_filename_component(dir "${relative_file}" DIRECTORY) | ||||||||||
| if(NOT dir STREQUAL "${last_dir}") | ||||||||||
| if(files) | ||||||||||
| source_group("${last_dir}" FILES ${files}) | ||||||||||
| source_group(TREE "${relative_dir}" FILES ${files}) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MAJOR] Non-standard usage pattern for The While multiple calls may work, this approach is:
Standard pattern: # Filter generator expressions
set(filtered_files "")
foreach(file ${files})
if(NOT file MATCHES "^\\$<")
list(APPEND filtered_files "${file}")
endif()
endforeach()
# Create hierarchy in one call
if(filtered_files)
source_group(TREE "${relative_dir}" FILES ${filtered_files})
endif()This would eliminate the entire directory-grouping loop (lines 29-48) since |
||||||||||
| endif() | ||||||||||
| set(files "") | ||||||||||
| endif() | ||||||||||
| set(files ${files} ${file}) | ||||||||||
| set(last_dir "${dir}") | ||||||||||
| endforeach(file) | ||||||||||
| if(files) | ||||||||||
| source_group("${last_dir}" FILES ${files}) | ||||||||||
| source_group(TREE "${relative_dir}" FILES ${files}) | ||||||||||
| endif() | ||||||||||
| endfunction() | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list(POP_FRONT files)only works because$<(ASCII 36) sorts before letters, putting gen-exprs at the front of the sorted list. It's fragile — any filename starting with a char < ASCII 36 (!,#,%, etc.) would sort first, andPOP_FRONTwould then remove a legitimate source file instead.Filter gen-exprs from
filesbefore the loop and drop this line entirely:Add before the
foreach:continue()alone is sufficient since the gen-expr is never appended tofileswhen we skip the rest of the loop body.