CMakeLists.txt 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. idf_build_get_property(target IDF_TARGET)
  2. if(${target} STREQUAL "linux")
  3. return() # This component is not necessary on the POSIX/Linux simulator
  4. endif()
  5. idf_component_register(SRCS "cxx_exception_stubs.cpp"
  6. "cxx_guards.cpp"
  7. # Make sure that pthread is in component list
  8. PRIV_REQUIRES pthread)
  9. if(NOT CONFIG_CXX_EXCEPTIONS)
  10. set(WRAP_FUNCTIONS
  11. _Unwind_SetEnableExceptionFdeSorting
  12. __register_frame_info_bases
  13. __register_frame_info
  14. __register_frame
  15. __register_frame_info_table_bases
  16. __register_frame_info_table
  17. __register_frame_table
  18. __deregister_frame_info_bases
  19. __deregister_frame_info
  20. _Unwind_Find_FDE
  21. _Unwind_GetGR
  22. _Unwind_GetCFA
  23. _Unwind_GetIP
  24. _Unwind_GetIPInfo
  25. _Unwind_GetRegionStart
  26. _Unwind_GetDataRelBase
  27. _Unwind_GetTextRelBase
  28. _Unwind_SetIP
  29. _Unwind_SetGR
  30. _Unwind_GetLanguageSpecificData
  31. _Unwind_FindEnclosingFunction
  32. _Unwind_Resume
  33. _Unwind_RaiseException
  34. _Unwind_DeleteException
  35. _Unwind_ForcedUnwind
  36. _Unwind_Resume_or_Rethrow
  37. _Unwind_Backtrace
  38. __cxa_call_unexpected
  39. __gxx_personality_v0)
  40. foreach(wrap ${WRAP_FUNCTIONS})
  41. target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
  42. endforeach()
  43. endif()
  44. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  45. # libstdc++ depends on C library, so it should appear later in link order.
  46. # Otherwise we get undefined references for esp-clang toolchain.
  47. target_link_libraries(${COMPONENT_LIB} PUBLIC stdc++ c ${CONFIG_COMPILER_RT_LIB_NAME})
  48. else()
  49. target_link_libraries(${COMPONENT_LIB} PUBLIC stdc++ gcc)
  50. endif()
  51. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxa_guard_dummy")
  52. # Force libpthread to appear later than libstdc++ in link line since libstdc++ depends on libpthread.
  53. # Furthermore, force libcxx to appear later than libgcc because some libgcc unwind code is wrapped, if C++
  54. # exceptions are disabled. libcxx (this component) provides the unwind code wrappers.
  55. # This is to prevent linking of libgcc's unwind code which considerably increases the binary size.
  56. # Also force libnewlib to appear later than libstdc++ in link line since libstdc++ depends on
  57. # some functions in libnewlib, e.g. getentropy().
  58. idf_component_get_property(pthread pthread COMPONENT_LIB)
  59. idf_component_get_property(newlib newlib COMPONENT_LIB)
  60. idf_component_get_property(cxx cxx COMPONENT_LIB)
  61. add_library(stdcpp_deps INTERFACE)
  62. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  63. target_link_libraries(stdcpp_deps INTERFACE stdc++ c $<TARGET_FILE:${pthread}> $<TARGET_FILE:${newlib}>)
  64. else()
  65. target_link_libraries(stdcpp_deps INTERFACE stdc++ $<TARGET_FILE:${pthread}> $<TARGET_FILE:${newlib}>)
  66. endif()
  67. target_link_libraries(${COMPONENT_LIB} PUBLIC stdcpp_deps)
  68. add_library(libgcc_cxx INTERFACE)
  69. target_link_libraries(libgcc_cxx INTERFACE ${CONFIG_COMPILER_RT_LIB_NAME} $<TARGET_FILE:${cxx}>)
  70. target_link_libraries(${COMPONENT_LIB} PUBLIC libgcc_cxx)
  71. if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)
  72. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_fatal_exception")
  73. endif()