Skip to content

Commit

Permalink
libcxx: fix build error.
Browse files Browse the repository at this point in the history
Signed-off-by: zhanghongyu <[email protected]>
  • Loading branch information
zhhyu7 committed Nov 30, 2023
1 parent b4d9496 commit b16b1dd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions arch/sim/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ else()
endif()
endif()

if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=${CONFIG_CXX_STANDARD}>)
endif()

set(ARCHCFLAGS "-Wstrict-prototypes")
set(ARCHCXXFLAGS "-nostdinc++")

Expand Down
13 changes: 13 additions & 0 deletions libs/libxx/0001_fix_stdatomic_h_miss_typedef.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- libcxx_old/include/stdatomic.h 2023-11-27 12:44:27.143768194 +0800
+++ libcxx/include/stdatomic.h 2023-11-27 12:31:46.498517673 +0800
@@ -232,4 +232,10 @@ using std::atomic_thread_fence _LIBCPP_U

#endif // defined(__cplusplus) && _LIBCPP_STD_VER > 20

+#ifndef atomic_int
+# if __has_include_next(<stdatomic.h>)
+# include_next <stdatomic.h>
+# endif
+#endif
+
#endif // _LIBCPP_STDATOMIC_H
32 changes: 16 additions & 16 deletions libs/libxx/libcxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libcxx)

# cmake-format: off
set(LIBCXX_PATCH_COMMAND
patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0001-Remove-the-locale-fallback-for-NuttX.patch
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0001-libc-avoid-the-waring-__EXCEPTIONS-is-not-defined-ev.patch
&& patch -p1 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0001-libcxx-Rename-PS-macro-to-avoid-clashing-with-Xtensa.patch
)

if(CONFIG_LIBC_ARCH_ATOMIC)
list(
APPEND
LIBCXX_PATCH_COMMAND
&& patch -p1 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0002-Omit-atomic_-un-signed_lock_free-if-unsupported.patch
)
endif()
patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libcxx < ${CMAKE_CURRENT_LIST_DIR}/0001_fix_stdatomic_h_miss_typedef.patch)
# cmake-format: on
FetchContent_Declare(
libcxx
Expand Down Expand Up @@ -68,13 +53,28 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libcxx)
FetchContent_Populate(libcxx)
endif()

execute_process(
COMMAND
sh -c
"ln -s ${CMAKE_CURRENT_LIST_DIR}/libcxx/include ${NUTTX_DIR}/include/libcxx}"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
execute_process(
COMMAND
sh -c
"cp ${CMAKE_CURRENT_LIST_DIR}/__config_site ${NUTTX_DIR}/include/libcxx/__config_site"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif()

set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/libcxx/include)

set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/libcxx/src)

add_compile_definitions(_LIBCPP_BUILDING_LIBRARY)
if(CONFIG_LIBSUPCXX)
add_compile_definitions(__GLIBCXX__)
Expand Down

0 comments on commit b16b1dd

Please sign in to comment.