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:
parent
1b2ad4ff7d
commit
0e8aecfe64
1
openamp/.gitignore
vendored
1
openamp/.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
/open-amp
|
||||
/*.zip
|
||||
/.openamp_patch
|
||||
/detect_64_atomic*
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user