CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. idf_build_get_property(target IDF_TARGET)
  2. idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
  3. if(NOT "${target}" STREQUAL "esp32s2")
  4. return()
  5. endif()
  6. if(BOOTLOADER_BUILD)
  7. # For bootloader, all we need from esp32s2 is headers
  8. idf_component_register(INCLUDE_DIRS include)
  9. target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
  10. else()
  11. # Regular app build
  12. set(srcs "cache_err_int.c"
  13. "memprot.c"
  14. "clk.c"
  15. "cpu_start.c"
  16. "crosscore_int.c"
  17. "dport_access.c"
  18. "hw_random.c"
  19. "intr_alloc.c"
  20. "pm_esp32s2.c"
  21. "pm_trace.c"
  22. "sleep_modes.c"
  23. "spiram.c"
  24. "spiram_psram.c"
  25. "system_api_esp32s2.c"
  26. "esp_crypto_lock.c"
  27. "esp_hmac.c"
  28. "esp_ds.c")
  29. set(include_dirs "include")
  30. set(requires driver efuse soc) #unfortunately rom/uart uses SOC registers directly
  31. # driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
  32. # app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
  33. # esp_timer is added here because cpu_start.c uses esp_timer
  34. set(priv_requires
  35. app_trace app_update bootloader_support log mbedtls nvs_flash
  36. pthread spi_flash vfs espcoredump esp_common esp_timer)
  37. set(fragments linker.lf ld/esp32s2_fragments.lf)
  38. idf_component_register(SRCS "${srcs}"
  39. INCLUDE_DIRS "${include_dirs}"
  40. LDFRAGMENTS "${fragments}"
  41. REQUIRES "${requires}"
  42. PRIV_REQUIRES "${priv_requires}"
  43. REQUIRED_IDF_TARGETS esp32s2)
  44. target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld")
  45. # Rely on user code to define app_main
  46. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
  47. # Process the template file through the linker script generation mechanism, and use the output for linking the
  48. # final binary
  49. target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32s2.project.ld.in" PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32s2.project.ld")
  50. target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
  51. target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
  52. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
  53. #ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
  54. #linker will ignore panic_highint_hdl.S as it has no other files depending on any
  55. #symbols in it.
  56. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_panic_highint_hdl")
  57. idf_build_get_property(config_dir CONFIG_DIR)
  58. # Preprocess esp32s2.ld linker script to include configuration, becomes esp32s2_out.ld
  59. set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
  60. add_custom_command(
  61. OUTPUT esp32s2_out.ld
  62. COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32s2_out.ld -I ${config_dir} ${LD_DIR}/esp32s2.ld
  63. MAIN_DEPENDENCY ${LD_DIR}/esp32s2.ld ${sdkconfig_header}
  64. COMMENT "Generating linker script..."
  65. VERBATIM)
  66. add_custom_target(esp32s2_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld)
  67. add_dependencies(${COMPONENT_LIB} esp32s2_linker_script)
  68. # disable stack protection in files which are involved in initialization of that feature
  69. set_source_files_properties(
  70. cpu_start.c
  71. PROPERTIES COMPILE_FLAGS
  72. -fno-stack-protector)
  73. endif()
  74. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  75. set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/sleep_modes.c" PROPERTIES
  76. COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion")
  77. endif()