CMakeLists.txt 2.6 KB

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