nuttx: Migrate NuttX CMake build for WAMR (#3256)

Add NuttX CMake build support for platforms.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
Xin Xu 2024-04-02 08:53:30 +08:00 committed by GitHub
parent 6ee71000f9
commit bad9a2a231
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 206 additions and 2 deletions

View File

@ -8,6 +8,10 @@ add_definitions(-DBH_PLATFORM_NUTTX)
include_directories(${PLATFORM_SHARED_DIR})
include_directories(${PLATFORM_SHARED_DIR}/../include)
include (${CMAKE_CURRENT_LIST_DIR}/../common/posix/platform_api_posix.cmake)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
@ -16,6 +20,7 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1)
set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE})
endif ()
include (${CMAKE_CURRENT_LIST_DIR}/../common/memory/platform_api_memory.cmake)
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE} ${PLATFORM_COMMON_MEMORY_SOURCE})
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE} ${PLATFORM_COMMON_POSIX_SOURCE} ${UNCOMMON_SHARED_SOURCE})
# remove posix_memmap.c for NuttX
list(REMOVE_ITEM ${PLATFORM_SHARED_SOURCE} ${PLATFORM_COMMON_POSIX_DIR}/posix_memmap.c)

View File

@ -0,0 +1,199 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# select platform configuration setting WAMR_BUILD_TARGET
set(WAMR_BUILD_PLATFORM nuttx)
if(CONFIG_ARCH_ARMV6M)
set(WAMR_BUILD_TARGET THUMBV6M)
elseif(CONFIG_ARCH_ARMV7A)
set(WAMR_BUILD_TARGET THUMBV7)
elseif(CONFIG_ARCH_ARMV7M)
set(WAMR_BUILD_TARGET THUMBV7EM)
elseif(CONFIG_ARCH_ARMV8M)
set(WAMR_BUILD_TARGET THUMBV8M)
elseif(CONFIG_ARCH_X86)
set(WAMR_BUILD_TARGET X86_32)
elseif(CONFIG_ARCH_X86_64)
set(WAMR_BUILD_TARGET X86_64)
elseif(CONFIG_ARCH_XTENSA)
set(WAMR_BUILD_TARGET XTENSA)
elseif(CONFIG_ARCH_RV64GC OR CONFIG_ARCH_RV64)
set(WAMR_BUILD_TARGET RISCV64)
elseif(CONFIG_ARCH_RV32IM OR CONFIG_ARCH_RV32)
set(WAMR_BUILD_TARGET RISCV32)
elseif(CONFIG_ARCH_SIM)
if(CONFIG_SIM_M32 OR CONFIG_HOST_X86)
set(WAMR_BUILD_TARGET X86_32)
elseif(CONFIG_HOST_ARM)
set(WAMR_BUILD_TARGET ARM)
elseif(CONFIG_HOST_ARM64)
set(WAMR_BUILD_TARGET AARCH64)
else()
set(WAMR_BUILD_TARGET X86_64)
endif()
if(CONFIG_HOST_MACOS)
add_definitions(-DBH_PLATFORM_DARWIN)
endif()
endif()
if(CONFIG_INTERPRETERS_WAMR_LOG)
add_definitions(-DWASM_ENABLE_LOG=1)
else()
add_definitions(-DWASM_ENABLE_LOG=0)
endif()
if(CONFIG_INTERPRETERS_WAMR_AOT_WORD_ALIGN_READ)
add_definitions(-DWASM_ENABLE_WORD_ALIGN_READ=1)
else()
add_definitions(-DWASM_ENABLE_WORD_ALIGN_READ=0)
endif()
if(CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE)
add_definitions(-DWASM_STACK_GUARD_SIZE=0)
else()
add_definitions(
-DWASM_STACK_GUARD_SIZE=${CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE})
endif()
if(CONFIG_INTERPRETERS_WAMR_MEMORY_TRACING)
add_definitions(-DWASM_ENABLE_MEMORY_TRACING=1)
else()
add_definitions(-DWASM_ENABLE_MEMORY_TRACING=0)
endif()
if(CONFIG_INTERPRETERS_WAMR_SHARED_MEMORY)
set(WAMR_BUILD_SHARED_MEMORY 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_BULK_MEMORY)
set(WAMR_BUILD_BULK_MEMORY 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_AOT_STACK_FRAME)
set(WAMR_BUILD_AOT_STACK_FRAME 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_PERF_PROFILING)
set(WAMR_BUILD_PERF_PROFILING 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_GC)
set(WAMR_BUILD_GC 1)
set(WAMR_BUILD_STRINGREF 1)
set(WAMR_BUILD_REF_TYPES 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_GC_MANUALLY)
add_definitions(-DWASM_GC_MANUALLY=1)
else()
add_definitions(-DWASM_GC_MANUALLY=0)
endif()
if(CONFIG_INTERPRETERS_WAMR_GC_PERF_PROFILING)
set(WAMR_BUILD_GC_PERF_PROFILING 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_ENABLE_EXCE_HANDLING)
set(WAMR_BUILD_EXCE_HANDLING 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_TAIL_CALL)
set(WAMR_BUILD_TAIL_CALL 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_MEMORY_PROFILING)
set(WAMR_BUILD_MEMORY_PROFILING 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_MULTI_MODULE)
set(WAMR_BUILD_MULTI_MODULE 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_LIB_PTHREAD_SEMAPHORE)
set(WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_DISABLE_HW_BOUND_CHECK)
set(WAMR_DISABLE_HW_BOUND_CHECK 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS)
set(WAMR_BUILD_CUSTOM_NAME_SECTION 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL)
set(WAMR_BUILD_GLOBAL_HEAP_POOL 1)
math(EXPR _HEAP_SIZE_
"${CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL_SIZE} * 1024")
set(WAMR_BUILD_GLOBAL_HEAP_SIZE ${_HEAP_SIZE_})
endif()
if(CONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST)
set(WAMR_BUILD_SPEC_TEST 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_REF_TYPES)
set(WAMR_BUILD_REF_TYPES 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_CLASSIC)
# include iwasm_interp.cmake
set(WAMR_BUILD_INTERP 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_FAST)
# enable iwasm_interp.cmake
set(WAMR_BUILD_FAST_INTERP 1)
endif()
if((CONFIG_INTERPRETERS_WAMR_FAST OR CONFIG_INTERPRETERS_WAMR_CLASSIC)
AND CONFIG_INTERPRETERS_WAMR_MINILOADER)
# enable iwasm_interp.cmake
set(WAMR_BUILD_MINI_LOADER 1)
else()
set(WAMR_BUILD_MINI_LOADER 0)
endif()
if(CONFIG_INTERPRETERS_WAMR_AOT)
# include iwasm_aot.cmake
set(WAMR_BUILD_AOT 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_DEBUG_INTERP)
# include debug_engine.cmake
set(WAMR_BUILD_DEBUG_INTERP 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN)
# include libc_builtin.cmake
set(WAMR_BUILD_LIBC_BUILTIN 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_LIBC_WASI)
# include libc_wasi.cmake
set(WAMR_BUILD_LIBC_WASI 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_THREAD_MGR)
# include thread_mgr.cmake
set(WAMR_BUILD_THREAD_MGR 1)
endif()
if(CONFIG_INTERPRETERS_WAMR_LIB_PTHREAD)
# include lib_pthread.cmake
set(WAMR_BUILD_LIB_PTHREAD 1)
endif()
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
# enable WAMR build system
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
# NuttX wamr lib complie required: `WAMR_SOURCES` `WAMR_CFLAGS` `WAMR_INCDIRS`
# `WAMR_DEFINITIONS`
set(WAMR_SOURCES ${WAMR_RUNTIME_LIB_SOURCE})
set(WAMR_CFLAGS -Wno-strict-prototypes -Wno-shadow -Wno-unused-variable
-Wno-int-conversion -Wno-implicit-function-declaration)
get_directory_property(WAMR_INCDIRS INCLUDE_DIRECTORIES)
get_directory_property(WAMR_DEFINITIONS COMPILE_DEFINITIONS)