CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. idf_build_get_property(target IDF_TARGET)
  2. if(NOT "${target}" STREQUAL "esp32")
  3. return()
  4. endif()
  5. idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
  6. if(BOOTLOADER_BUILD)
  7. # For bootloader, all we need from esp32 is headers
  8. idf_component_register(INCLUDE_DIRS include)
  9. target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
  10. else()
  11. # Regular app build
  12. set(srcs
  13. "cache_err_int.c"
  14. "cache_sram_mmu.c"
  15. "clk.c"
  16. "cpu_start.c"
  17. "crosscore_int.c"
  18. "dport_access.c"
  19. "esp_himem.c"
  20. "hw_random.c"
  21. "intr_alloc.c"
  22. "pm_esp32.c"
  23. "pm_trace.c"
  24. "sleep_modes.c"
  25. "spiram.c"
  26. "spiram_psram.c"
  27. "system_api_esp32.c")
  28. set(include_dirs "include")
  29. set(requires driver efuse soc) #unfortunately rom/uart uses SOC registers directly
  30. # driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
  31. # app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
  32. # esp_timer is added here because cpu_start.c uses esp_timer
  33. set(priv_requires app_trace app_update bootloader_support log mbedtls nvs_flash pthread
  34. spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc)
  35. set(fragments linker.lf ld/esp32_fragments.lf)
  36. idf_component_register(SRCS "${srcs}"
  37. INCLUDE_DIRS "${include_dirs}"
  38. LDFRAGMENTS "${fragments}"
  39. REQUIRES "${requires}"
  40. PRIV_REQUIRES "${priv_requires}"
  41. REQUIRED_IDF_TARGETS esp32)
  42. target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
  43. # Rely on user code to define app_main
  44. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
  45. if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY)
  46. # This has to be linked before esp32.project.ld
  47. target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld")
  48. endif()
  49. # Process the template file through the linker script generation mechanism, and use the output for linking the
  50. # final binary
  51. target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
  52. PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
  53. target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
  54. target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
  55. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
  56. #ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
  57. #linker will ignore panic_highint_hdl.S as it has no other files depending on any
  58. #symbols in it.
  59. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_panic_highint_hdl")
  60. idf_build_get_property(config_dir CONFIG_DIR)
  61. # Preprocess esp32.ld linker script to include configuration, becomes esp32_out.ld
  62. set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
  63. add_custom_command(
  64. OUTPUT esp32_out.ld
  65. COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32_out.ld -I ${config_dir} ${LD_DIR}/esp32.ld
  66. MAIN_DEPENDENCY ${LD_DIR}/esp32.ld ${sdkconfig_header}
  67. COMMENT "Generating linker script..."
  68. VERBATIM)
  69. add_custom_target(esp32_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld)
  70. add_dependencies(${COMPONENT_LIB} esp32_linker_script)
  71. # disable stack protection in files which are involved in initialization of that feature
  72. set_source_files_properties(
  73. cpu_start.c
  74. PROPERTIES COMPILE_FLAGS
  75. -fno-stack-protector)
  76. if(CONFIG_SPIRAM_CACHE_WORKAROUND)
  77. # Note: Adding as a PUBLIC compile option here causes this option to propagate to all components that depend on esp32.
  78. #
  79. # To handle some corner cases, the same flag is set in project_include.cmake
  80. target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
  81. # also, make sure we link with this option so correct toolchain libs are pulled in
  82. target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
  83. # set strategy selected
  84. # note that we don't need to set link options as the library linked is independent of this
  85. if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST)
  86. target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
  87. target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
  88. endif()
  89. if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW)
  90. target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
  91. target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
  92. endif()
  93. if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS)
  94. target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
  95. target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
  96. endif()
  97. endif()
  98. endif()