CMakeLists.txt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. if(CONFIG_OPENTHREAD_ENABLED)
  2. set(public_include_dirs
  3. "include"
  4. "openthread/include")
  5. set(private_include_dirs
  6. "openthread/examples/platforms"
  7. "openthread/include/openthread"
  8. "openthread/src"
  9. "openthread/src/core"
  10. "openthread/src/lib/hdlc"
  11. "openthread/src/lib/spinel"
  12. "openthread/src/ncp"
  13. "private_include")
  14. set(src_dirs
  15. "openthread/examples/platforms/utils"
  16. "openthread/src/core/api"
  17. "openthread/src/core/common"
  18. "openthread/src/core/crypto"
  19. "openthread/src/core/diags"
  20. "openthread/src/core/mac"
  21. "openthread/src/core/radio"
  22. "openthread/src/core/thread"
  23. "openthread/src/core/utils"
  24. "openthread/src/lib/hdlc"
  25. "openthread/src/lib/spinel")
  26. set(exclude_srcs
  27. "openthread/examples/platforms/utils/logging_rtt.c"
  28. "openthread/examples/platforms/utils/soft_source_match_table.c"
  29. "openthread/src/core/common/extension_example.cpp")
  30. if(CONFIG_OPENTHREAD_FTD OR CONFIG_OPENTHREAD_MTD)
  31. list(APPEND src_dirs
  32. "src"
  33. "openthread/examples/apps/cli"
  34. "openthread/src/core/backbone_router"
  35. "openthread/src/core/coap"
  36. "openthread/src/core/meshcop"
  37. "openthread/src/core/net"
  38. "openthread/src/cli"
  39. "openthread/src/lib/platform")
  40. list(APPEND exclude_srcs
  41. "openthread/examples/apps/cli/main.c")
  42. elseif(CONFIG_OPENTHREAD_RADIO)
  43. list(APPEND src_dirs
  44. "openthread/src/ncp"
  45. "openthread/examples/apps/ncp")
  46. list(APPEND exclude_srcs
  47. "openthread/examples/apps/ncp/main.c"
  48. "openthread/src/core/api/backbone_router_api.cpp"
  49. "openthread/src/core/api/dataset_api.cpp"
  50. "openthread/src/core/api/dns_api.cpp"
  51. "openthread/src/core/api/entropy_api.cpp"
  52. "openthread/src/core/api/heap_api.cpp"
  53. "openthread/src/core/api/icmp6_api.cpp"
  54. "openthread/src/core/api/ip6_api.cpp"
  55. "openthread/src/core/api/link_api.cpp"
  56. "openthread/src/core/api/message_api.cpp"
  57. "openthread/src/core/api/netdata_api.cpp"
  58. "openthread/src/core/api/random_crypto_api.cpp"
  59. "openthread/src/core/api/tcp_api.cpp"
  60. "openthread/src/core/api/udp_api.cpp"
  61. "openthread/src/core/common/heap.cpp"
  62. "openthread/src/core/common/heap_string.cpp"
  63. "openthread/src/core/common/notifier.cpp"
  64. "openthread/src/core/common/settings.cpp"
  65. "openthread/src/core/common/time_ticker.cpp"
  66. "openthread/src/core/mac/channel_mask.cpp"
  67. "openthread/src/core/mac/data_poll_handler.cpp"
  68. "openthread/src/core/mac/data_poll_sender.cpp"
  69. "openthread/src/core/mac/mac.cpp"
  70. "openthread/src/core/mac/mac_filter.cpp"
  71. "openthread/src/core/mac/mac_links.cpp"
  72. "openthread/src/core/thread/announce_begin_server.cpp"
  73. "openthread/src/core/thread/announce_sender.cpp"
  74. "openthread/src/core/thread/address_resolver.cpp"
  75. "openthread/src/core/thread/discover_scanner.cpp"
  76. "openthread/src/core/thread/energy_scan_server.cpp"
  77. "openthread/src/core/thread/key_manager.cpp"
  78. "openthread/src/core/thread/lowpan.cpp"
  79. "openthread/src/core/thread/mesh_forwarder.cpp"
  80. "openthread/src/core/thread/mesh_forwarder_ftd.cpp"
  81. "openthread/src/core/thread/mesh_forwarder_mtd.cpp"
  82. "openthread/src/core/thread/mle.cpp"
  83. "openthread/src/core/thread/neighbor_table.cpp"
  84. "openthread/src/core/thread/network_data.cpp"
  85. "openthread/src/core/thread/network_data_leader.cpp"
  86. "openthread/src/core/thread/network_data_leader_ftd.cpp"
  87. "openthread/src/core/thread/network_data_types.cpp"
  88. "openthread/src/core/thread/network_data_service.cpp"
  89. "openthread/src/core/thread/panid_query_server.cpp"
  90. "openthread/src/core/thread/thread_netif.cpp"
  91. "openthread/src/core/thread/tmf.cpp"
  92. "openthread/src/core/thread/topology.cpp"
  93. "openthread/src/core/utils/child_supervision.cpp")
  94. endif()
  95. if(CONFIG_OPENTHREAD_BORDER_ROUTER)
  96. list(APPEND src_dirs
  97. "openthread/src/core/border_router")
  98. endif()
  99. if(CONFIG_OPENTHREAD_FTD)
  100. set_source_files_properties("openthread/src/core/net/srp_server.cpp"
  101. PROPERTIES COMPILE_FLAGS
  102. -Wno-maybe-uninitialized)
  103. endif()
  104. if(CONFIG_OPENTHREAD_FTD)
  105. set(device_type "OPENTHREAD_FTD=1")
  106. elseif(CONFIG_OPENTHREAD_MTD)
  107. set(device_type "OPENTHREAD_MTD=1")
  108. elseif(CONFIG_OPENTHREAD_RADIO)
  109. set(device_type "OPENTHREAD_RADIO=1")
  110. endif()
  111. endif()
  112. execute_process(
  113. COMMAND git rev-parse --short HEAD
  114. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  115. OUTPUT_VARIABLE IDF_VERSION_FOR_OPENTHREAD_PACKAGE OUTPUT_STRIP_TRAILING_WHITESPACE
  116. )
  117. execute_process(
  118. COMMAND git rev-parse --short HEAD
  119. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/openthread
  120. OUTPUT_VARIABLE OPENTHREAD_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
  121. )
  122. string(TIMESTAMP OT_BUILD_TIMESTAMP " %Y-%m-%d %H:%M:%S UTC" UTC)
  123. string(CONCAT OT_FULL_VERSION_STRING
  124. "openthread-esp32/"
  125. "${IDF_VERSION_FOR_OPENTHREAD_PACKAGE}-${OPENTHREAD_VERSION}\; "
  126. "${CONFIG_IDF_TARGET}\; ${OT_BUILD_TIMESTAMP}")
  127. idf_component_register(SRC_DIRS "${src_dirs}"
  128. EXCLUDE_SRCS "${exclude_srcs}"
  129. INCLUDE_DIRS "${public_include_dirs}"
  130. PRIV_INCLUDE_DIRS "${private_include_dirs}"
  131. REQUIRES esp_event mbedtls ieee802154 console lwip)
  132. if(CONFIG_OPENTHREAD_ENABLED)
  133. if(CONFIG_OPENTHREAD_RADIO)
  134. set(CONFIG_FILE_TYPE "radio")
  135. elseif(CONFIG_OPENTHREAD_FTD)
  136. set(CONFIG_FILE_TYPE "ftd")
  137. elseif(CONFIG_OPENTHREAD_MTD)
  138. set(CONFIG_FILE_TYPE "mtd")
  139. endif()
  140. target_compile_definitions(
  141. ${COMPONENT_LIB}
  142. PUBLIC
  143. "OPENTHREAD_CONFIG_FILE=\"openthread-core-esp32x-${CONFIG_FILE_TYPE}-config.h\""
  144. "${device_type}"
  145. PRIVATE
  146. "PACKAGE_VERSION=\"${IDF_VERSION_FOR_OPENTHREAD_PACKAGE}-${OPENTHREAD_VERSION}\""
  147. "OPENTHREAD_BUILD_DATETIME=\"${OT_BUILD_TIMESTAMP}\""
  148. )
  149. if(CONFIG_OPENTHREAD_RADIO)
  150. file(WRITE ${CMAKE_BINARY_DIR}/rcp_version ${OT_FULL_VERSION_STRING})
  151. endif()
  152. if($ENV{OPENTHREAD_ESP_LIB_FROM_INTERNAL_SRC})
  153. idf_component_get_property(openthread_port_lib openthread_port COMPONENT_LIB)
  154. idf_component_get_property(lwip_lib lwip COMPONENT_LIB)
  155. idf_component_get_property(esp_netif_lib esp_netif COMPONENT_LIB)
  156. idf_component_get_property(esp_system_lib esp_system COMPONENT_LIB)
  157. target_link_libraries(${COMPONENT_LIB} PUBLIC
  158. $<TARGET_FILE:${openthread_port_lib}>
  159. $<TARGET_FILE:${esp_system_lib}>)
  160. target_link_libraries(${COMPONENT_LIB} PUBLIC
  161. $<TARGET_FILE:${lwip_lib}>
  162. $<TARGET_FILE:${esp_netif_lib}>
  163. $<TARGET_FILE:${openthread_port_lib}>
  164. $<TARGET_FILE:${esp_netif_lib}>
  165. $<TARGET_FILE:${lwip_lib}>)
  166. if(CONFIG_OPENTHREAD_BORDER_ROUTER)
  167. idf_component_get_property(openthread_br_lib openthread_br COMPONENT_LIB)
  168. target_link_libraries(${COMPONENT_LIB} PUBLIC $<TARGET_FILE:${openthread_br_lib}>)
  169. endif()
  170. else()
  171. if(IDF_TARGET STREQUAL "esp32h2")
  172. if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1)
  173. add_prebuilt_library(openthread_port
  174. "${CMAKE_CURRENT_SOURCE_DIR}/lib/${idf_target}/rev1/libopenthread_port.a"
  175. REQUIRES openthread)
  176. endif()
  177. if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2)
  178. add_prebuilt_library(openthread_port
  179. "${CMAKE_CURRENT_SOURCE_DIR}/lib/${idf_target}/rev2/libopenthread_port.a"
  180. REQUIRES openthread)
  181. endif()
  182. else()
  183. add_prebuilt_library(openthread_port "${CMAKE_CURRENT_SOURCE_DIR}/lib/${idf_target}/libopenthread_port.a"
  184. REQUIRES openthread)
  185. endif()
  186. add_prebuilt_library(openthread_br "${CMAKE_CURRENT_SOURCE_DIR}/lib/${idf_target}/libopenthread_br.a"
  187. REQUIRES openthread)
  188. target_link_libraries(${COMPONENT_LIB} INTERFACE openthread_port)
  189. if(CONFIG_OPENTHREAD_BORDER_ROUTER)
  190. target_link_libraries(${COMPONENT_LIB} INTERFACE openthread_br)
  191. endif()
  192. endif()
  193. endif()