SourceGroupFunctions.cmake 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Generate source groups which mimic the original folder hierarchy.
  2. # This is mainly useful for MSVC's project explorer
  3. # - SRCS list of source files
  4. # - HDRS list of header files
  5. function(source_group_hierarchy SRCS HDRS)
  6. if(MSVC)
  7. # This removes the 'Source Files' folder, which is
  8. # not really necessary. Also, put header and source
  9. # files into the same folder
  10. foreach(source_file ${${SRCS}})
  11. source_group_file(${source_file} "")
  12. endforeach()
  13. foreach(header_file ${${HDRS}})
  14. source_group_file(${header_file} "")
  15. endforeach()
  16. else()
  17. foreach(source_file ${${SRCS}})
  18. source_group_file(${source_file} "Source Files\\")
  19. endforeach()
  20. foreach(header_file ${${HDRS}})
  21. source_group_file(${header_file} "Source Files\\")
  22. endforeach()
  23. endif()
  24. endfunction()
  25. # Determine source_group depending on file path
  26. # - FILE path to a file (header or source)
  27. # - GROUP_PREFIX prefix for group name
  28. function(source_group_file file group_prefix)
  29. get_filename_component(file_path ${file} PATH)
  30. if(${file_path} STREQUAL "src")
  31. source_group("${group_prefix}" FILES ${file})
  32. else()
  33. string(REGEX REPLACE "^src/(.*)$" "\\1" group_name ${file_path})
  34. string(REPLACE "/" "\\\\" group_name ${group_name})
  35. source_group("${group_prefix}${group_name}" FILES ${file})
  36. endif()
  37. endfunction()