cmake:reuse OpenAMP own CMake script for CMake build

Check whether 64-bit atomic is supported

Co-authored-by: xuxin19 <xuxin19@xiaomi.com>
Co-authored-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
xuxin19 2024-04-26 09:42:58 +08:00 committed by Xiang Xiao
parent 1b2ad4ff7d
commit 0e8aecfe64
4 changed files with 56 additions and 85 deletions

1
openamp/.gitignore vendored
View file

@ -4,3 +4,4 @@
/open-amp /open-amp
/*.zip /*.zip
/.openamp_patch /.openamp_patch
/detect_64_atomic*

View file

@ -60,80 +60,37 @@ else()
set(LIBMETAL_ARCH ${CONFIG_ARCH}) set(LIBMETAL_ARCH ${CONFIG_ARCH})
endif() 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_SYSTEM nuttx)
set(PROJECT_PROCESSOR ${LIBMETAL_ARCH}) set(CMAKE_SYSTEM_PROCESSOR ${LIBMETAL_ARCH})
set(PROJECT_MACHINE ${CONFIG_ARCH_CHIP}) set(MACHINE ${CONFIG_ARCH})
set(PROJECT_SYSTEM_UPPER nuttx) set(CMAKE_SYSTEM_NAME NuttX)
set(PROJECT_PROCESSOR_UPPER ${LIBMETAL_ARCH}) set(WITH_DOC OFF)
set(PROJECT_MACHINE_UPPER ${CONFIG_ARCH_CHIP})
set(headers) # cmake-format: off
file( set(ATOMIC_TEST_CODE
GLOB headers [-[
LIST_DIRECTORIES false #include <stdatomic.h>
RELATIVE ${CMAKE_CURRENT_LIST_DIR}/libmetal/lib int main() {
${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/*.h) _Atomic long long x = 0;
foreach(header ${headers}) return x;
configure_file(${CMAKE_CURRENT_LIST_DIR}/libmetal/lib/${header} }
${CMAKE_BINARY_DIR}/include/metal/${header}) ]-]
endforeach() )
# cmake-format: on
set(headers) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_atomic.c ${ATOMIC_TEST_CODE})
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()
set(headers) try_compile(HAS_64BIT_ATOMIC_SUPPORT ${CMAKE_CURRENT_BINARY_DIR}
file( ${CMAKE_CURRENT_BINARY_DIR}/test_atomic.c)
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()
set(headers) if(NOT HAS_64BIT_ATOMIC_SUPPORT)
file( add_compile_options(-DNO_ATOMIC_64_SUPPORT)
GLOB headers endif()
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()
nuttx_add_kernel_library(lib_metal) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libmetal
${CMAKE_CURRENT_BINARY_DIR}/libmetal EXCLUDE_FROM_ALL)
target_sources( nuttx_create_symlink(${CMAKE_CURRENT_BINARY_DIR}/libmetal/lib/include/metal
lib_metal ${CMAKE_BINARY_DIR}/include/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)
target_compile_definitions(lib_metal PRIVATE METAL_INTERNAL) nuttx_add_external_library(metal-static MODE KERNEL)

View file

@ -56,6 +56,20 @@ CSRCS += libmetal/lib/version.c
CFLAGS += -DMETAL_INTERNAL 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 := \ LIBMETAL_HDRS_SEDEXP := \
"s/@PROJECT_VERSION_MAJOR@/0/g; \ "s/@PROJECT_VERSION_MAJOR@/0/g; \
s/@PROJECT_VERSION_MINOR@/1/g; \ s/@PROJECT_VERSION_MINOR@/1/g; \
@ -105,5 +119,7 @@ ifeq ($(wildcard libmetal/.git),)
$(call DELFILE, libmetal.zip) $(call DELFILE, libmetal.zip)
endif endif
$(call DELFILE, .libmetal_headers) $(call DELFILE, .libmetal_headers)
$(call DELFILE, $(ATOMIC_DETECT_CODE))
$(call DELFILE, $(ATOMIC_DETECT_BIN))
endif endif

View file

@ -86,28 +86,25 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
endif() endif()
endif() endif()
nuttx_add_kernel_library(openamp)
if(CONFIG_OPENAMP_CACHE) if(CONFIG_OPENAMP_CACHE)
target_compile_options(openamp PRIVATE -DVIRTIO_CACHED_BUFFERS) set(WITH_DCACHE_VRINGS ON)
target_compile_options(openamp PRIVATE -DVIRTIO_CACHED_VRINGS)
endif() endif()
if(CONFIG_OPENAMP_RPMSG_DEBUG) if(CONFIG_OPENAMP_RPMSG_DEBUG)
target_compile_options(openamp PRIVATE -DRPMSG_DEBUG) add_compile_definitions(RPMSG_DEBUG)
endif() endif()
if(CONFIG_OPENAMP_VQUEUE_DEBUG) if(CONFIG_OPENAMP_VQUEUE_DEBUG)
target_compile_options(openamp PRIVATE -DVQUEUE_DEBUG) add_compile_definitions(VQUEUE_DEBUG)
endif() endif()
target_sources( set(WITH_LIBMETAL_FIND OFF)
openamp
PRIVATE open-amp/lib/remoteproc/elf_loader.c if(NOT CMAKE_SYSTEM_PROCESSOR)
open-amp/lib/remoteproc/remoteproc.c set(CMAKE_SYSTEM_PROCESSOR ${CONFIG_ARCH})
open-amp/lib/remoteproc/remoteproc_virtio.c endif()
open-amp/lib/remoteproc/rsc_table_parser.c
open-amp/lib/rpmsg/rpmsg.c add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/open-amp
open-amp/lib/rpmsg/rpmsg_virtio.c ${CMAKE_CURRENT_BINARY_DIR}/open-amp EXCLUDE_FROM_ALL)
open-amp/lib/virtio/virtio.c
open-amp/lib/virtio/virtqueue.c) nuttx_add_external_library(open_amp-static MODE KERNEL)