c138651300
Introduce a new CMake based build system for Wasm. And target the Wasm ABI to wasm32-wasi, it should be a more commnly used and standard ABI for Wasm. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
101 lines
3.8 KiB
CMake
101 lines
3.8 KiB
CMake
# ##############################################################################
|
|
# apps/tools/Wasm/CMakeLists.txt
|
|
#
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
|
# license agreements. See the NOTICE file distributed with this work for
|
|
# additional information regarding copyright ownership. The ASF licenses this
|
|
# file to you under the Apache License, Version 2.0 (the "License"); you may not
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
# the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations under
|
|
# the License.
|
|
#
|
|
# ##############################################################################
|
|
|
|
# ~~~
|
|
# This file is used to manage the WebAssembly (Wasm) build process as entry
|
|
# point. All the wasm apps are built using this file as a sub target.
|
|
#
|
|
# Necessary input for this file is the APPDIR, TOPDIR and KCONFIG_FILE_PATH.
|
|
# The APPDIR is the directory where the Wasm apps are located.
|
|
# The TOPDIR is the root directory of the NuttX source code.
|
|
# The KCONFIG_FILE_PATH is the path to the .config file of the NuttX build.
|
|
# ~~~
|
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
include(WASI-SDK.cmake)
|
|
|
|
project(WasmApps)
|
|
|
|
# Check whether the APPDIR is defined or not. If not, then set it to the parent
|
|
# directory of the current CMakeLists.txt file.
|
|
if(NOT DEFINED APPDIR)
|
|
message(FATAL_ERROR "APPDIR is not defined")
|
|
endif()
|
|
|
|
# Check wether the TOPDIR is defined or not. If not, then raise an error.
|
|
if(NOT DEFINED TOPDIR)
|
|
message(FATAL_ERROR "TOPDIR is not defined")
|
|
endif()
|
|
|
|
# Check wether the KCONFIG_FILE_PATH is defined or not. If not, then raise an
|
|
# error.
|
|
if(NOT DEFINED KCONFIG_FILE_PATH)
|
|
message(FATAL_ERROR "KCONFIG_FILE_PATH is not defined")
|
|
endif()
|
|
|
|
# Include the NuttX kconfig parser to shared the configuration between the NuttX
|
|
# build and the Wasm build. And then parse the input KCONFIG_FILE_PATH to get
|
|
# the configuration.
|
|
include(${TOPDIR}/cmake/nuttx_kconfig.cmake)
|
|
nuttx_export_kconfig(${KCONFIG_FILE_PATH})
|
|
|
|
# Provide FAR macro from command line since it is not supported in wasi-sdk, but
|
|
# it is used in NuttX code.
|
|
# ~~~
|
|
# #define FAR
|
|
# ~~~
|
|
# It usually defined in nuttx/compiler.h.
|
|
set(NUTTX_MACRO_FAR "")
|
|
add_definitions(-DFAR=${NUTTX_MACRO_FAR})
|
|
|
|
# Fake nuttx_add_application to avoid error in the Wasm build process.
|
|
function(nuttx_add_application)
|
|
|
|
endfunction()
|
|
|
|
# Fake nuttx_add_library to avoid error in the Wasm build process.
|
|
function(nuttx_add_library)
|
|
|
|
endfunction()
|
|
|
|
# Recursively find all the CMakeLists.txt files in the ${APPDIR} and add it by
|
|
# add_subdirectory, but exclude the CMakeLists.txt file in the ${APPDIR}/tools
|
|
# directory.
|
|
file(GLOB_RECURSE WASM_APPS ${APPDIR}/*/CMakeLists.txt)
|
|
list(FILTER WASM_APPS EXCLUDE REGEX ".*/tools/.*")
|
|
|
|
# Read and check if wasm_add_application is called in the CMakeLists.txt file in
|
|
# WASM_APPS If true, then add the directory to the build process
|
|
foreach(WASM_APP ${WASM_APPS})
|
|
file(READ ${WASM_APP} WASM_APP_CONTENTS)
|
|
string(FIND "${WASM_APP_CONTENTS}" "wasm_add_application" WASM_APP_FOUND)
|
|
string(FIND "${WASM_APP_CONTENTS}" "wasm_add_library" WASM_LIB_FOUND)
|
|
if(WASM_APP_FOUND GREATER -1 OR WASM_LIB_FOUND GREATER -1)
|
|
get_filename_component(WASM_APP_DIR ${WASM_APP} DIRECTORY)
|
|
# Add subdirectory to the build process and put the build directory in the
|
|
# current build directory with the name same as the relative path of the
|
|
# ${APPDIR}
|
|
string(REPLACE ${APPDIR} "" WASM_APP_BUILD_DIR ${WASM_APP_DIR})
|
|
add_subdirectory(${WASM_APP_DIR}
|
|
${CMAKE_CURRENT_BINARY_DIR}/Wasm/${WASM_APP_BUILD_DIR})
|
|
endif()
|
|
endforeach()
|