CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. idf_build_get_property(target IDF_TARGET)
  2. if(${target} STREQUAL "linux")
  3. return() # This component is not supported by the POSIX/Linux simulator
  4. endif()
  5. set(srcs
  6. "app_trace.c"
  7. "app_trace_util.c"
  8. "host_file_io.c")
  9. if(CONFIG_APPTRACE_GCOV_ENABLE)
  10. if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
  11. list(APPEND srcs
  12. "gcov/gcov_rtio.c")
  13. else()
  14. fail_at_build_time(app_trace "Only GNU compiler can link with Gcov library")
  15. endif()
  16. endif()
  17. set(include_dirs "include")
  18. set(priv_include_dirs "private_include" "port/include")
  19. if(CONFIG_APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE)
  20. list(APPEND srcs
  21. "app_trace_membufs_proto.c")
  22. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  23. list(APPEND srcs
  24. "port/xtensa/port.c")
  25. endif()
  26. if(CONFIG_IDF_TARGET_ARCH_RISCV)
  27. list(APPEND srcs
  28. "port/riscv/port.c")
  29. endif()
  30. endif()
  31. list(APPEND srcs
  32. "port/port_uart.c")
  33. if(CONFIG_APPTRACE_SV_ENABLE)
  34. list(APPEND include_dirs
  35. sys_view/Config
  36. sys_view/SEGGER
  37. sys_view/Sample/FreeRTOSV10.4)
  38. list(APPEND srcs
  39. "sys_view/SEGGER/SEGGER_SYSVIEW.c"
  40. "sys_view/Sample/FreeRTOSV10.4/Config/esp/SEGGER_SYSVIEW_Config_FreeRTOS.c"
  41. "sys_view/Sample/FreeRTOSV10.4/SEGGER_SYSVIEW_FreeRTOS.c"
  42. "sys_view/esp/SEGGER_RTT_esp.c"
  43. "sys_view/ext/heap_trace_module.c"
  44. "sys_view/ext/logging.c")
  45. endif()
  46. if(CONFIG_HEAP_TRACING_TOHOST)
  47. list(APPEND srcs "heap_trace_tohost.c")
  48. set_source_files_properties(heap_trace_tohost.c
  49. PROPERTIES COMPILE_FLAGS
  50. -Wno-frame-address)
  51. endif()
  52. idf_component_register(SRCS "${srcs}"
  53. INCLUDE_DIRS "${include_dirs}"
  54. PRIV_INCLUDE_DIRS "${priv_include_dirs}"
  55. PRIV_REQUIRES soc esp_driver_gptimer esp_driver_gpio
  56. driver # TODO: replace with esp_driver_uart (IDF-8384)
  57. REQUIRES esp_timer
  58. LDFRAGMENTS linker.lf)
  59. # Force app_trace to also appear later than gcov in link line
  60. idf_component_get_property(app_trace app_trace COMPONENT_LIB)
  61. if(CONFIG_APPTRACE_GCOV_ENABLE)
  62. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  63. # Coverage info is not supported when clang is used
  64. # TODO: LLVM-214
  65. message(FATAL_ERROR "Coverage info is not supported when building with Clang!")
  66. endif()
  67. # The original Gcov library from toolchain will be objcopy with symbols redefinitions (see file gcov/io_sym.map).
  68. # This needs because ESP has no file-system onboard, and redefined functions solves this problem and transmits
  69. # output file to host PC.
  70. # Set a name for Gcov library
  71. set(GCOV_LIB libgcov_rtio)
  72. # Set include direcrory of Gcov internal headers
  73. execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=plugin
  74. OUTPUT_VARIABLE gcc_plugin_dir
  75. OUTPUT_STRIP_TRAILING_WHITESPACE
  76. ERROR_QUIET)
  77. set_source_files_properties(gcov/gcov_rtio.c
  78. PROPERTIES COMPILE_FLAGS "-I${gcc_plugin_dir}/include")
  79. # Copy libgcov.a with symbols redefinition
  80. find_library(GCOV_LIBRARY_PATH gcov ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
  81. add_custom_command(OUTPUT ${GCOV_LIB}.a
  82. COMMAND ${_CMAKE_TOOLCHAIN_PREFIX}objcopy
  83. --redefine-syms ${CMAKE_CURRENT_LIST_DIR}/gcov/io_sym.map
  84. ${GCOV_LIBRARY_PATH} ${GCOV_LIB}.a
  85. MAIN_DEPENDENCY ${GCOV_LIBRARY_PATH}
  86. VERBATIM)
  87. add_custom_target(${GCOV_LIB}_target DEPENDS ${GCOV_LIB}.a)
  88. add_library(${GCOV_LIB} STATIC IMPORTED)
  89. set_target_properties(${GCOV_LIB}
  90. PROPERTIES
  91. IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${GCOV_LIB}.a)
  92. add_dependencies(${GCOV_LIB} ${GCOV_LIB}_target)
  93. add_dependencies(${COMPONENT_LIB} ${GCOV_LIB})
  94. # disable --coverage for this component, as it is used as transport for gcov
  95. target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-profile-arcs" "-fno-test-coverage")
  96. target_link_options(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=__gcov_init")
  97. target_link_libraries(${COMPONENT_LIB} INTERFACE ${GCOV_LIB} $<TARGET_FILE:${app_trace}> c)
  98. else()
  99. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${app_trace}> c)
  100. endif()
  101. # This function adds a dependency on the given component if the component is included into the build.
  102. function(maybe_add_component component_name)
  103. idf_build_get_property(components BUILD_COMPONENTS)
  104. if(${component_name} IN_LIST components)
  105. idf_component_get_property(lib_name ${component_name} COMPONENT_LIB)
  106. target_link_libraries(${COMPONENT_LIB} PUBLIC ${lib_name})
  107. endif()
  108. endfunction()
  109. if(CONFIG_APPTRACE_DEST_UART0 OR CONFIG_APPTRACE_DEST_UART1 OR CONFIG_APPTRACE_DEST_UART2)
  110. maybe_add_component(driver)
  111. endif()