CMakeLists: Derive the source file listings from targets directly (#118)

This gets rid of the need to store to individual variables before creating
the target itself, cleaning up the variables in the surrounding scope a little bit.
This commit is contained in:
Mat M 2017-11-26 06:39:27 -05:00 committed by MerryMage
parent 12eaf496fd
commit c6d09adcb7
3 changed files with 22 additions and 22 deletions

View file

@ -1,12 +1,14 @@
# This function should be passed a list of all files in a target. It will automatically generate
# This function should be passed a name of an existing target. It will automatically generate
# file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
# one in the filesystem.
function(create_directory_groups)
function(create_target_directory_groups target_name)
# Place any files that aren't in the source list in a separate group so that they don't get in
# the way.
source_group("Other Files" REGULAR_EXPRESSION ".")
foreach(file_name ${ARGV})
get_target_property(target_sources "${target_name}" SOURCES)
foreach(file_name IN LISTS target_sources)
get_filename_component(dir_name "${file_name}" PATH)
# Group names use '\' as a separator even though the entire rest of CMake uses '/'...
string(REPLACE "/" "\\" group_name "${dir_name}")