You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/06/25 16:22:09 UTC

(nuttx) branch master updated: cmake:reuse OpenAMP own CMake script for CMake build

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e8aecfe64 cmake:reuse OpenAMP own CMake script for CMake build
0e8aecfe64 is described below

commit 0e8aecfe647b0d6cb573b40edaa1eb8bedac3807
Author: xuxin19 <xu...@xiaomi.com>
AuthorDate: Fri Apr 26 09:42:58 2024 +0800

    cmake:reuse OpenAMP own CMake script for CMake build
    
    Check whether 64-bit atomic is supported
    
    Co-authored-by: xuxin19 <xu...@xiaomi.com>
    Co-authored-by: Bowen Wang <wa...@xiaomi.com>
---
 openamp/.gitignore     |  1 +
 openamp/libmetal.cmake | 95 ++++++++++++++------------------------------------
 openamp/libmetal.defs  | 16 +++++++++
 openamp/open-amp.cmake | 29 +++++++--------
 4 files changed, 56 insertions(+), 85 deletions(-)

diff --git a/openamp/.gitignore b/openamp/.gitignore
index fe119e1d71..e135ba23dc 100644
--- a/openamp/.gitignore
+++ b/openamp/.gitignore
@@ -4,3 +4,4 @@
 /open-amp
 /*.zip
 /.openamp_patch
+/detect_64_atomic*
diff --git a/openamp/libmetal.cmake b/openamp/libmetal.cmake
index 0f150c5bcf..8a7dc7966c 100644
--- a/openamp/libmetal.cmake
+++ b/openamp/libmetal.cmake
@@ -60,80 +60,37 @@ else()
   set(LIBMETAL_ARCH ${CONFIG_ARCH})
 endif()
 
-set(PROJECT_VERSION_MAJOR 0)
-set(PROJECT_VERSION_MINOR 1)
-set(PROJECT_VERSION_PATCH 0)
-set(PROJECT_VERSION 0.1.0)
 set(PROJECT_SYSTEM nuttx)
-set(PROJECT_PROCESSOR ${LIBMETAL_ARCH})
-set(PROJECT_MACHINE ${CONFIG_ARCH_CHIP})
-set(PROJECT_SYSTEM_UPPER nuttx)
-set(PROJECT_PROCESSOR_UPPER ${LIBMETAL_ARCH})
-set(PROJECT_MACHINE_UPPER ${CONFIG_ARCH_CHIP})
+set(CMAKE_SYSTEM_PROCESSOR ${LIBMETAL_ARCH})
+set(MACHINE ${CONFIG_ARCH})
+set(CMAKE_SYSTEM_NAME NuttX)
+set(WITH_DOC OFF)
 
-set(headers)
-file(
-  GLOB headers
-  LIST_DIRECTORIES false
-  RELATIVE ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib
-  ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/*.h)
-foreach(header ${headers})
-  configure_file(${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/${header}
-                 ${CMAKE_BINARY_DIR}/include/metal/${header})
-endforeach()
+# cmake-format: off
+set(ATOMIC_TEST_CODE
+  [-[
+    #include <stdatomic.h>
+    int main() {
+        _Atomic long long x = 0;
+        return x;
+    }
+  ]-]
+)
+# cmake-format: on
 
-set(headers)
-file(
-  GLOB headers
-  LIST_DIRECTORIES false
-  RELATIVE ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/system/nuttx
-  ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/system/nuttx/*.h)
-foreach(header ${headers})
-  configure_file(${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/system/nuttx/${header}
-                 ${CMAKE_BINARY_DIR}/include/metal/system/nuttx/${header})
-endforeach()
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_atomic.c ${ATOMIC_TEST_CODE})
 
-set(headers)
-file(
-  GLOB headers
-  LIST_DIRECTORIES false
-  RELATIVE ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/processor/${LIBMETAL_ARCH}
-  ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/processor/${LIBMETAL_ARCH}/*.h)
-foreach(header ${headers})
-  configure_file(
-    ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/processor/${LIBMETAL_ARCH}/${header}
-    ${CMAKE_BINARY_DIR}/include/metal/processor/${LIBMETAL_ARCH}/${header})
-endforeach()
+try_compile(HAS_64BIT_ATOMIC_SUPPORT ${CMAKE_CURRENT_BINARY_DIR}
+            ${CMAKE_CURRENT_BINARY_DIR}/test_atomic.c)
 
-set(headers)
-file(
-  GLOB headers
-  LIST_DIRECTORIES false
-  RELATIVE ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/compiler/gcc
-  ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/compiler/gcc/*.h)
-foreach(header ${headers})
-  configure_file(${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/compiler/gcc/${header}
-                 ${CMAKE_BINARY_DIR}/include/metal/compiler/gcc/${header})
-endforeach()
+if(NOT HAS_64BIT_ATOMIC_SUPPORT)
+  add_compile_options(-DNO_ATOMIC_64_SUPPORT)
+endif()
 
-nuttx_add_kernel_library(lib_metal)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libmetal
+                 ${CMAKE_CURRENT_BINARY_DIR}/libmetal EXCLUDE_FROM_ALL)
 
-target_sources(
-  lib_metal
-  PRIVATE libmetal/lib/system/nuttx/condition.c
-          libmetal/lib/system/nuttx/device.c
-          libmetal/lib/system/nuttx/init.c
-          libmetal/lib/system/nuttx/io.c
-          libmetal/lib/system/nuttx/irq.c
-          libmetal/lib/system/nuttx/shmem.c
-          libmetal/lib/system/nuttx/time.c
-          libmetal/lib/device.c
-          libmetal/lib/dma.c
-          libmetal/lib/init.c
-          libmetal/lib/io.c
-          libmetal/lib/irq.c
-          libmetal/lib/log.c
-          libmetal/lib/shmem.c
-          libmetal/lib/version.c)
+nuttx_create_symlink(${CMAKE_CURRENT_BINARY_DIR}/libmetal/lib/include/metal
+                     ${CMAKE_BINARY_DIR}/include/metal)
 
-target_compile_definitions(lib_metal PRIVATE METAL_INTERNAL)
+nuttx_add_external_library(metal-static MODE KERNEL)
diff --git a/openamp/libmetal.defs b/openamp/libmetal.defs
index 90e8a690be..f307da1ff0 100644
--- a/openamp/libmetal.defs
+++ b/openamp/libmetal.defs
@@ -56,6 +56,20 @@ CSRCS += libmetal/lib/version.c
 
 CFLAGS += -DMETAL_INTERNAL
 
+# Check whether the current toolchain supports 64-bit atomic
+ATOMIC_DETECT_CODE := detect_64_atomic.c
+ATOMIC_DETECT_BIN := detect_64_atomic_bin
+DETECT_ATOMIC_SUPPORT = \
+    echo '\#include <stdatomic.h>' > $(ATOMIC_DETECT_CODE); \
+    echo 'int main() { _Atomic long long x = 0; return x; }' >> $(ATOMIC_DETECT_CODE); \
+    if $(CC) -o $(ATOMIC_DETECT_BIN) $(ATOMIC_DETECT_CODE) 2>/dev/null; then \
+        echo ""; \
+    else \
+        echo "-DNO_ATOMIC_64_SUPPORT"; \
+    fi; \
+
+CFLAGS += $(shell $(DETECT_ATOMIC_SUPPORT))
+
 LIBMETAL_HDRS_SEDEXP := \
 	"s/@PROJECT_VERSION_MAJOR@/0/g; \
 	 s/@PROJECT_VERSION_MINOR@/1/g; \
@@ -105,5 +119,7 @@ ifeq ($(wildcard libmetal/.git),)
 	$(call DELFILE, libmetal.zip)
 endif
 	$(call DELFILE, .libmetal_headers)
+	$(call DELFILE, $(ATOMIC_DETECT_CODE))
+	$(call DELFILE, $(ATOMIC_DETECT_BIN))
 
 endif
diff --git a/openamp/open-amp.cmake b/openamp/open-amp.cmake
index 1c7b7d3edb..99c75184ea 100644
--- a/openamp/open-amp.cmake
+++ b/openamp/open-amp.cmake
@@ -86,28 +86,25 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
   endif()
 endif()
 
-nuttx_add_kernel_library(openamp)
-
 if(CONFIG_OPENAMP_CACHE)
-  target_compile_options(openamp PRIVATE -DVIRTIO_CACHED_BUFFERS)
-  target_compile_options(openamp PRIVATE -DVIRTIO_CACHED_VRINGS)
+  set(WITH_DCACHE_VRINGS ON)
 endif()
 
 if(CONFIG_OPENAMP_RPMSG_DEBUG)
-  target_compile_options(openamp PRIVATE -DRPMSG_DEBUG)
+  add_compile_definitions(RPMSG_DEBUG)
 endif()
 
 if(CONFIG_OPENAMP_VQUEUE_DEBUG)
-  target_compile_options(openamp PRIVATE -DVQUEUE_DEBUG)
+  add_compile_definitions(VQUEUE_DEBUG)
 endif()
 
-target_sources(
-  openamp
-  PRIVATE open-amp/lib/remoteproc/elf_loader.c
-          open-amp/lib/remoteproc/remoteproc.c
-          open-amp/lib/remoteproc/remoteproc_virtio.c
-          open-amp/lib/remoteproc/rsc_table_parser.c
-          open-amp/lib/rpmsg/rpmsg.c
-          open-amp/lib/rpmsg/rpmsg_virtio.c
-          open-amp/lib/virtio/virtio.c
-          open-amp/lib/virtio/virtqueue.c)
+set(WITH_LIBMETAL_FIND OFF)
+
+if(NOT CMAKE_SYSTEM_PROCESSOR)
+  set(CMAKE_SYSTEM_PROCESSOR ${CONFIG_ARCH})
+endif()
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/open-amp
+                 ${CMAKE_CURRENT_BINARY_DIR}/open-amp EXCLUDE_FROM_ALL)
+
+nuttx_add_external_library(open_amp-static MODE KERNEL)