esp-idf/components/newlib/CMakeLists.txt

112 lines
3.8 KiB
CMake
Raw Normal View History

idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)
if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()
set(include_dirs "platform_include")
if(non_os_build)
# Bootloader builds need the platform_include directory (for assert.h), but nothing else
idf_component_register(INCLUDE_DIRS platform_include)
return()
endif()
set(srcs
2024-09-26 13:13:20 +07:00
"src/init.c"
"src/abort.c"
"src/assert.c"
"src/heap.c"
"src/locks.c"
"src/poll.c"
"src/pthread.c"
"src/random.c"
"src/getentropy.c"
"src/termios.c"
"src/stdatomic.c"
"src/time.c"
"src/sysconf.c"
"src/realpath.c"
"src/scandir.c"
"src/syscalls.c"
"src/reent_syscalls.c"
"src/port/esp_time_impl.c")
if(CONFIG_STDATOMIC_S32C1I_SPIRAM_WORKAROUND)
2024-09-26 13:13:20 +07:00
list(APPEND srcs "src/port/xtensa/stdatomic_s32c1i.c")
endif()
2024-09-26 13:13:20 +07:00
if(CONFIG_LIBC_NEWLIB)
list(APPEND srcs
"src/flockfile.c"
"src/reent_init.c"
"src/newlib_init.c")
else()
list(APPEND srcs
"src/picolibc/picolibc_init.c"
"src/picolibc/rand.c"
"src/picolibc/open_memstream.c")
endif()
2024-09-26 13:13:20 +07:00
list(APPEND ldfragments "src/newlib.lf" "src/system_libs.lf")
if(CONFIG_SPIRAM_CACHE_WORKAROUND)
if(CONFIG_LIBC_NEWLIB)
list(APPEND ldfragments src/esp32-spiram-rom-functions-c.lf)
else()
list(APPEND ldfragments src/picolibc/esp32-spiram-rom-functions-c.lf)
endif()
endif()
idf_component_register(SRCS "${srcs}"
2024-09-26 13:13:20 +07:00
INCLUDE_DIRS platform_include
PRIV_INCLUDE_DIRS priv_include
PRIV_REQUIRES soc spi_flash
LDFRAGMENTS "${ldfragments}")
2019-11-05 12:20:26 +01:00
# Toolchain libraries require code defined in this component
idf_component_get_property(newlib newlib COMPONENT_LIB)
target_link_libraries(${COMPONENT_LIB} INTERFACE c m ${CONFIG_COMPILER_RT_LIB_NAME} "$<TARGET_FILE:${newlib}>")
set_source_files_properties(heap.c PROPERTIES COMPILE_FLAGS -fno-builtin)
if(CONFIG_STDATOMIC_S32C1I_SPIRAM_WORKAROUND)
2024-09-26 13:13:20 +07:00
set_source_files_properties("src/port/xtensa/stdatomic_s32c1i.c"
PROPERTIES COMPILE_FLAGS "-mno-disable-hardware-atomics")
endif()
# Forces the linker to include heap, syscall, pthread, assert, and retargetable locks from this component,
2019-11-05 12:20:26 +01:00
# instead of the implementations provided by newlib.
2024-09-26 13:13:20 +07:00
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_heap_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_reent_syscalls_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_syscalls_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_pthread_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_assert_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_getentropy_impl")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_include_init_funcs")
list(APPEND EXTRA_LINK_FLAGS "-u esp_libc_init_funcs")
2019-11-05 12:20:26 +01:00
target_link_libraries(${COMPONENT_LIB} INTERFACE "${EXTRA_LINK_FLAGS}")
if(CONFIG_NEWLIB_NANO_FORMAT)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(libc_dir_cmd ${CMAKE_C_COMPILER})
string(REPLACE " " ";" cflags_list ${CMAKE_C_FLAGS})
list(APPEND libc_dir_cmd ${cflags_list} "-print-file-name=libc.a")
execute_process(
COMMAND ${libc_dir_cmd}
OUTPUT_VARIABLE libc_dir
)
get_filename_component(libc_dir ${libc_dir} DIRECTORY)
target_link_directories(${COMPONENT_LIB} INTERFACE "${libc_dir}/nano")
else()
target_link_libraries(${COMPONENT_LIB} INTERFACE "--specs=nano.specs")
endif()
endif()
2024-09-26 13:13:20 +07:00
add_subdirectory(src/port)
build system: remove lwip from common requirements lwip was added to common requirements list to provide "sys/socket.h" header to all components without additional requirements specified. However, lwip pulls in a lot of dependencies on other components. This commit removes lwip from common requirements to reduce the number of components in G1-only apps. To compensate for this removal, the following changes are made: - newlib (which is a common requirement) has a public dependency on lwip if lwip is present in the build. This ensures that sys/socket.h is available as long as lwip component is included into the build. - lwip is now a public requirement of esp-tls since esp_tls.h includes sys/socket.h header. - lwip is now a public requirement o esp_http_client because sys/socket.h is included from esp_http_client.h - lwip is now a private requirement of esp_wifi for "smartconfig_ack" - lwip is now a private requirement of mqtt for socket functions - lwip is now a public requirement of tcp_transport because esp_transport_tcp.h includes sys/socket.h header. - mbedtls checks if lwip component is present in the build. If yes, net_sockets.c is added to the build, along with the dependency on lwip. Previously lwip was a public requirement of mbedtls unconditionally. system/g1_components test app is updated to reflect the changes Default public dependencies of a component before and after this change, except common requirements: - esp_timer (public dependency of freertos) - bootloader_support (public dependency of esp_hw_support) - vfs (public dependency of lwip) - esp_wifi (public dependency of lwip) - esp_event (public dependency of esp_wifi) - esp_netif (public dependency of esp_event) - esp_eth (public dependency of esp_netif) - esp_phy (public dependency of esp_wifi) After: - esp_timer (public dependency of freertos) - bootloader_support (public dependency of esp_hw_support) Altogether, the following components have been always added as public requirements to all other components, and are not added now ([breaking-change]): - lwip - vfs - esp_wifi - esp_event - esp_netif - esp_eth - esp_phy Application components now need to explicitly declare dependencies on these components.
2022-04-14 20:03:56 +02:00
# if lwip is included in the build, add it as a public requirement so that
# #include <sys/socket.h> works without any special provisions.
idf_component_optional_requires(PUBLIC lwip)