mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-15 19:34:03 +00:00
cmake: use new signature form of target_link_library to link components
!4452 used setting LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES to link components built under ESP-IDF build system. However, LINK_LIBRARIES does not produce behavior same as linking PRIVATE. This MR uses the new signature for target_link_libraries directly instead. This also moves setting dependencies during component registration rather than after all components have been processed. The consequence is that internally, components have to use the new signature form as well. This does not affect linking the components to external targets, such as with idf_as_lib example. This only affects linking additional libraries to ESP-IDF libraries outside component processing (after idf_build_process), which is not even possible for CMake<v3.13 as target_link_libraries is not valid for targets not created in current directory. See https://cmake.org/cmake/help/v3.13/policy/CMP0079.html#policy:CMP0079
This commit is contained in:
@@ -4,7 +4,7 @@ if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32 is headers
|
||||
set(COMPONENT_ADD_INCLUDEDIRS include)
|
||||
register_component()
|
||||
target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
|
||||
@@ -46,29 +46,29 @@ else()
|
||||
|
||||
register_component()
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
|
||||
|
||||
# Rely on user code to define app_main
|
||||
target_link_libraries(${COMPONENT_LIB} "-u app_main")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
|
||||
|
||||
if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY)
|
||||
# This has to be linked before esp32.project.ld
|
||||
target_linker_script(${COMPONENT_LIB} "ld/esp32.extram.bss.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld")
|
||||
endif()
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld")
|
||||
target_link_libraries(${COMPONENT_LIB} gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} "-u call_user_start_cpu0")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
|
||||
#linker will ignore panic_highint_hdl.S as it has no other files depending on any
|
||||
#symbols in it.
|
||||
target_link_libraries(${COMPONENT_LIB} "-u ld_include_panic_highint_hdl")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_panic_highint_hdl")
|
||||
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
get_filename_component(config_dir ${sdkconfig_header} DIRECTORY)
|
||||
@@ -96,6 +96,6 @@ else()
|
||||
# To handle some corner cases, the same flag is set in project_include.cmake
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
# also, make sure we link with this option so correct toolchain libs are pulled in
|
||||
target_link_libraries(${COMPONENT_LIB} -mfix-esp32-psram-cache-issue)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user