|
| 1 | +# ############################################################################## |
| 2 | +# apps/tools/Wasm/CMakeLists.txt |
| 3 | +# |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one or more contributor |
| 5 | +# license agreements. See the NOTICE file distributed with this work for |
| 6 | +# additional information regarding copyright ownership. The ASF licenses this |
| 7 | +# file to you under the Apache License, Version 2.0 (the "License"); you may not |
| 8 | +# use this file except in compliance with the License. You may obtain a copy of |
| 9 | +# the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | +# License for the specific language governing permissions and limitations under |
| 17 | +# the License. |
| 18 | +# |
| 19 | +# ############################################################################## |
| 20 | + |
| 21 | +# ~~~ |
| 22 | +# This file is used to manage the WebAssembly (Wasm) build process as entry |
| 23 | +# point. All the wasm apps are built using this file as a sub target. |
| 24 | +# |
| 25 | +# Necessary input for this file is the APPDIR, TOPDIR and KCONFIG_FILE_PATH. |
| 26 | +# The APPDIR is the directory where the Wasm apps are located. |
| 27 | +# The TOPDIR is the root directory of the NuttX source code. |
| 28 | +# The KCONFIG_FILE_PATH is the path to the .config file of the NuttX build. |
| 29 | +# ~~~ |
| 30 | + |
| 31 | +cmake_minimum_required(VERSION 3.5) |
| 32 | + |
| 33 | +include(WASI-SDK.cmake) |
| 34 | + |
| 35 | +project(WasmApps) |
| 36 | + |
| 37 | +# Check whether the APPDIR is defined or not. If not, then set it to the parent |
| 38 | +# directory of the current CMakeLists.txt file. |
| 39 | +if(NOT DEFINED APPDIR) |
| 40 | + message(FATAL_ERROR "APPDIR is not defined") |
| 41 | +endif() |
| 42 | + |
| 43 | +# Check wether the TOPDIR is defined or not. If not, then raise an error. |
| 44 | +if(NOT DEFINED TOPDIR) |
| 45 | + message(FATAL_ERROR "TOPDIR is not defined") |
| 46 | +endif() |
| 47 | + |
| 48 | +# Check wether the KCONFIG_FILE_PATH is defined or not. If not, then raise an |
| 49 | +# error. |
| 50 | +if(NOT DEFINED KCONFIG_FILE_PATH) |
| 51 | + message(FATAL_ERROR "KCONFIG_FILE_PATH is not defined") |
| 52 | +endif() |
| 53 | + |
| 54 | +# Include the NuttX kconfig parser to shared the configuration between the NuttX |
| 55 | +# build and the Wasm build. And then parse the input KCONFIG_FILE_PATH to get |
| 56 | +# the configuration. |
| 57 | +include(${TOPDIR}/cmake/nuttx_kconfig.cmake) |
| 58 | +nuttx_export_kconfig(${KCONFIG_FILE_PATH}) |
| 59 | + |
| 60 | +# Provide FAR macro from command line since it is not supported in wasi-sdk, but |
| 61 | +# it is used in NuttX code. |
| 62 | +# ~~~ |
| 63 | +# #define FAR |
| 64 | +# ~~~ |
| 65 | +# It usually defined in nuttx/compiler.h. |
| 66 | +set(NUTTX_MACRO_FAR "") |
| 67 | +add_definitions(-DFAR=${NUTTX_MACRO_FAR}) |
| 68 | + |
| 69 | +# Fake nuttx_add_application to avoid error in the Wasm build process. |
| 70 | +function(nuttx_add_application) |
| 71 | + |
| 72 | +endfunction() |
| 73 | + |
| 74 | +# Fake nuttx_add_library to avoid error in the Wasm build process. |
| 75 | +function(nuttx_add_library) |
| 76 | + |
| 77 | +endfunction() |
| 78 | + |
| 79 | +# Recursively find all the CMakeLists.txt files in the ${APPDIR} and add it by |
| 80 | +# add_subdirectory, but exclude the CMakeLists.txt file in the ${APPDIR}/tools |
| 81 | +# directory. |
| 82 | +file(GLOB_RECURSE WASM_APPS ${APPDIR}/*/CMakeLists.txt) |
| 83 | +list(FILTER WASM_APPS EXCLUDE REGEX ".*/tools/.*") |
| 84 | + |
| 85 | +# Read and check if wasm_add_application is called in the CMakeLists.txt file in |
| 86 | +# WASM_APPS If true, then add the directory to the build process |
| 87 | +foreach(WASM_APP ${WASM_APPS}) |
| 88 | + file(READ ${WASM_APP} WASM_APP_CONTENTS) |
| 89 | + string(FIND "${WASM_APP_CONTENTS}" "wasm_add_application" WASM_APP_FOUND) |
| 90 | + string(FIND "${WASM_APP_CONTENTS}" "wasm_add_library" WASM_LIB_FOUND) |
| 91 | + if(WASM_APP_FOUND GREATER -1 OR WASM_LIB_FOUND GREATER -1) |
| 92 | + get_filename_component(WASM_APP_DIR ${WASM_APP} DIRECTORY) |
| 93 | + # Add subdirectory to the build process and put the build directory in the |
| 94 | + # current build directory with the name same as the relative path of the |
| 95 | + # ${APPDIR} |
| 96 | + string(REPLACE ${APPDIR} "" WASM_APP_BUILD_DIR ${WASM_APP_DIR}) |
| 97 | + add_subdirectory(${WASM_APP_DIR} |
| 98 | + ${CMAKE_CURRENT_BINARY_DIR}/Wasm/${WASM_APP_BUILD_DIR}) |
| 99 | + endif() |
| 100 | +endforeach() |
0 commit comments