1if(BOOTLOADER_BUILD)
2    # Bootloader builds need the platform_include directory (for assert.h), but nothing else
3    idf_component_register(INCLUDE_DIRS platform_include)
4    return()
5endif()
6
7set(srcs
8    "abort.c"
9    "assert.c"
10    "heap.c"
11    "locks.c"
12    "poll.c"
13    "pthread.c"
14    "random.c"
15    "reent_init.c"
16    "newlib_init.c"
17    "syscalls.c"
18    "termios.c"
19    "stdatomic.c"
20    "time.c"
21    "sysconf.c"
22    "realpath.c")
23set(include_dirs platform_include)
24
25if(CONFIG_SPIRAM_CACHE_WORKAROUND)
26    set(ldfragments "esp32-spiram-rom-functions-c.lf")
27endif()
28
29list(APPEND ldfragments "newlib.lf" "system_libs.lf")
30
31idf_component_register(SRCS "${srcs}"
32                    INCLUDE_DIRS "${include_dirs}"
33                    PRIV_INCLUDE_DIRS priv_include
34                    PRIV_REQUIRES soc spi_flash
35                    LDFRAGMENTS "${ldfragments}")
36
37# Toolchain libraries require code defined in this component
38idf_component_get_property(newlib newlib COMPONENT_LIB)
39target_link_libraries(${COMPONENT_LIB} INTERFACE c m gcc "$<TARGET_FILE:${newlib}>")
40
41set_source_files_properties(heap.c PROPERTIES COMPILE_FLAGS -fno-builtin)
42
43# Forces the linker to include heap, syscall, pthread, assert, and retargetable locks from this component,
44# instead of the implementations provided by newlib.
45list(APPEND EXTRA_LINK_FLAGS "-u newlib_include_heap_impl")
46list(APPEND EXTRA_LINK_FLAGS "-u newlib_include_syscalls_impl")
47list(APPEND EXTRA_LINK_FLAGS "-u newlib_include_pthread_impl")
48list(APPEND EXTRA_LINK_FLAGS "-u newlib_include_assert_impl")
49target_link_libraries(${COMPONENT_LIB} INTERFACE "${EXTRA_LINK_FLAGS}")
50
51if(CONFIG_NEWLIB_NANO_FORMAT)
52    if(CMAKE_C_COMPILER_ID MATCHES "Clang")
53        set(libc_dir_cmd ${CMAKE_C_COMPILER})
54        string(REPLACE " " ";" cflags_list ${CMAKE_C_FLAGS})
55        list(APPEND libc_dir_cmd ${cflags_list} "-print-file-name=libc.a")
56        execute_process(
57            COMMAND ${libc_dir_cmd}
58            OUTPUT_VARIABLE libc_dir
59        )
60        get_filename_component(libc_dir ${libc_dir} DIRECTORY)
61        target_link_directories(${COMPONENT_LIB} INTERFACE "${libc_dir}/nano")
62    else()
63        target_link_libraries(${COMPONENT_LIB} INTERFACE "--specs=nano.specs")
64    endif()
65endif()
66
67add_subdirectory(port)
68
69# if lwip is included in the build, add it as a public requirement so that
70# #include <sys/socket.h> works without any special provisions.
71idf_component_optional_requires(PUBLIC lwip)
72