nice_target_sources.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This file is part of Desktop App Toolkit,
  2. # a set of libraries for developing nice desktop applications.
  3. #
  4. # For license and copyright information please follow this link:
  5. # https://github.com/desktop-app/legal/blob/master/LEGAL
  6. function(nice_target_sources target_name src_loc)
  7. set(writing_now "")
  8. set(private_sources "")
  9. set(public_sources "")
  10. set(interface_sources "")
  11. set(not_win_sources "")
  12. set(not_mac_sources "")
  13. set(not_linux_sources "")
  14. foreach (entry ${ARGN})
  15. if (${entry} STREQUAL "PRIVATE" OR ${entry} STREQUAL "PUBLIC" OR ${entry} STREQUAL "INTERFACE")
  16. set(writing_now ${entry})
  17. else()
  18. set(full_name ${src_loc}/${entry})
  19. if (${entry} MATCHES "(^|/)win/" OR ${entry} MATCHES "(^|/)winrc/" OR ${entry} MATCHES "(^|/)windows/" OR ${entry} MATCHES "[_\\/]win\\.")
  20. list(APPEND not_mac_sources ${full_name})
  21. list(APPEND not_linux_sources ${full_name})
  22. elseif (${entry} MATCHES "(^|/)mac/" OR ${entry} MATCHES "(^|/)darwin/" OR ${entry} MATCHES "(^|/)osx/" OR ${entry} MATCHES "[_\\/]mac\\." OR ${entry} MATCHES "[_\\/]darwin\\." OR ${entry} MATCHES "[_\\/]osx\\.")
  23. list(APPEND not_win_sources ${full_name})
  24. list(APPEND not_linux_sources ${full_name})
  25. elseif (${entry} MATCHES "(^|/)linux/" OR ${entry} MATCHES "[_\\/]linux\\.")
  26. list(APPEND not_win_sources ${full_name})
  27. list(APPEND not_mac_sources ${full_name})
  28. elseif (${entry} MATCHES "(^|/)posix/" OR ${entry} MATCHES "[_\\/]posix\\.")
  29. list(APPEND not_win_sources ${full_name})
  30. endif()
  31. if ("${writing_now}" STREQUAL "PRIVATE")
  32. list(APPEND private_sources ${full_name})
  33. elseif ("${writing_now}" STREQUAL "PUBLIC")
  34. list(APPEND public_sources ${full_name})
  35. elseif ("${writing_now}" STREQUAL "INTERFACE")
  36. list(APPEND interface_sources ${full_name})
  37. else()
  38. message(FATAL_ERROR "Unknown sources scope for target ${target_name}")
  39. endif()
  40. if (${src_loc} MATCHES "/Resources$")
  41. source_group(TREE ${src_loc} PREFIX Resources FILES ${full_name})
  42. else()
  43. source_group(TREE ${src_loc} PREFIX Sources FILES ${full_name})
  44. endif()
  45. endif()
  46. endforeach()
  47. if (NOT "${public_sources}" STREQUAL "")
  48. target_sources(${target_name} PUBLIC ${public_sources})
  49. endif()
  50. if (NOT "${private_sources}" STREQUAL "")
  51. target_sources(${target_name} PRIVATE ${private_sources})
  52. endif()
  53. if (NOT "${interface_sources}" STREQUAL "")
  54. target_sources(${target_name} INTERFACE ${interface_sources})
  55. endif()
  56. if (WIN32)
  57. set_source_files_properties(${not_win_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
  58. set_source_files_properties(${not_win_sources} PROPERTIES SKIP_AUTOGEN TRUE)
  59. elseif (APPLE)
  60. set_source_files_properties(${not_mac_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
  61. set_source_files_properties(${not_mac_sources} PROPERTIES SKIP_AUTOGEN TRUE)
  62. elseif (LINUX)
  63. set_source_files_properties(${not_linux_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
  64. set_source_files_properties(${not_linux_sources} PROPERTIES SKIP_AUTOGEN TRUE)
  65. endif()
  66. endfunction()
  67. function(remove_target_sources target_name src_loc)
  68. set(sources "")
  69. foreach (entry ${ARGN})
  70. set(full_name ${src_loc}/${entry})
  71. list(APPEND sources ${full_name})
  72. endforeach()
  73. set_source_files_properties(${sources} PROPERTIES HEADER_FILE_ONLY TRUE)
  74. set_source_files_properties(${sources} PROPERTIES SKIP_AUTOGEN TRUE)
  75. endfunction()