family_support.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. if (NOT TARGET _family_support_marker)
  2. add_library(_family_support_marker INTERFACE)
  3. if (NOT FAMILY)
  4. message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line")
  5. endif()
  6. if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
  7. message(FATAL_ERROR "Family '${FAMILY}' is not known/supported")
  8. endif()
  9. function(family_filter RESULT DIR)
  10. get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  11. if (EXISTS "${DIR}/only.txt")
  12. file(READ "${DIR}/only.txt" ONLYS)
  13. # Replace newlines with semicolon so that it is treated as a list by CMake
  14. string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS})
  15. # For each mcu
  16. foreach(MCU IN LISTS FAMILY_MCUS)
  17. # For each line in only.txt
  18. foreach(_line ${ONLYS_LINES})
  19. # If mcu:xxx exists for this mcu then include
  20. if (${_line} STREQUAL "mcu:${MCU}")
  21. set(${RESULT} 1 PARENT_SCOPE)
  22. return()
  23. endif()
  24. endforeach()
  25. endforeach()
  26. # Didn't find it in only file so don't build
  27. set(${RESULT} 0 PARENT_SCOPE)
  28. elseif (EXISTS "${DIR}/skip.txt")
  29. file(READ "${DIR}/skip.txt" SKIPS)
  30. # Replace newlines with semicolon so that it is treated as a list by CMake
  31. string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS})
  32. # For each mcu
  33. foreach(MCU IN LISTS FAMILY_MCUS)
  34. # For each line in only.txt
  35. foreach(_line ${SKIPS_LINES})
  36. # If mcu:xxx exists for this mcu then skip
  37. if (${_line} STREQUAL "mcu:${MCU}")
  38. set(${RESULT} 0 PARENT_SCOPE)
  39. return()
  40. endif()
  41. endforeach()
  42. endforeach()
  43. # Didn't find in skip file so build
  44. set(${RESULT} 1 PARENT_SCOPE)
  45. else()
  46. # Didn't find skip or only file so build
  47. set(${RESULT} 1 PARENT_SCOPE)
  48. endif()
  49. endfunction()
  50. function(family_add_subdirectory DIR)
  51. family_filter(SHOULD_ADD "${DIR}")
  52. if (SHOULD_ADD)
  53. add_subdirectory(${DIR})
  54. endif()
  55. endfunction()
  56. function(family_get_project_name OUTPUT_NAME DIR)
  57. get_filename_component(SHORT_NAME ${DIR} NAME)
  58. set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE)
  59. endfunction()
  60. function(family_initialize_project PROJECT DIR)
  61. family_filter(ALLOWED "${DIR}")
  62. if (NOT ALLOWED)
  63. get_filename_component(SHORT_NAME ${DIR} NAME)
  64. message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}")
  65. endif()
  66. endfunction()
  67. # configure an executable target to link to tinyusb in device mode, and add the board implementation
  68. function(family_configure_device_example TARGET)
  69. # default implentation is empty, the function should be redefined in the FAMILY/family.cmake
  70. endfunction()
  71. # configure an executable target to link to tinyusb in host mode, and add the board implementation
  72. function(family_configure_host_example TARGET)
  73. # default implentation is empty, the function should be redefined in the FAMILY/family.cmake
  74. endfunction()
  75. include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
  76. if (NOT FAMILY_MCUS)
  77. set(FAMILY_MCUS ${FAMILY})
  78. endif()
  79. # save it in case of re-inclusion
  80. set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "")
  81. endif()