CreateDirectoryGroups.cmake 859 B

123456789101112131415161718
  1. # This function should be passed a name of an existing target. It will automatically generate
  2. # file groups following the directory hierarchy, so that the layout of the files in IDEs matches the
  3. # one in the filesystem.
  4. function(create_target_directory_groups target_name)
  5. # Place any files that aren't in the source list in a separate group so that they don't get in
  6. # the way.
  7. source_group("Other Files" REGULAR_EXPRESSION ".")
  8. get_target_property(target_sources "${target_name}" SOURCES)
  9. foreach(file_name IN LISTS target_sources)
  10. get_filename_component(dir_name "${file_name}" PATH)
  11. # Group names use '\' as a separator even though the entire rest of CMake uses '/'...
  12. string(REPLACE "/" "\\" group_name "${dir_name}")
  13. source_group("${group_name}" FILES "${file_name}")
  14. endforeach()
  15. endfunction()