From 2795092a462a7c6e87d121bc1e62d79855157d1c Mon Sep 17 00:00:00 2001 From: Scott Todd Date: Mon, 8 Mar 2021 14:46:26 -0800 Subject: [PATCH] Add CMake configuration for WAMR's runtime "iwasm VM core". --- CMakeLists.txt | 1 + .../wasm-micro-runtime/CMakeLists.txt | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 build_tools/third_party/wasm-micro-runtime/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 742f55154fa8..117328fd66dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,6 +384,7 @@ add_subdirectory(build_tools/third_party/half EXCLUDE_FROM_ALL) add_subdirectory(build_tools/third_party/pffft EXCLUDE_FROM_ALL) add_subdirectory(build_tools/third_party/renderdoc_api EXCLUDE_FROM_ALL) add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) +add_subdirectory(build_tools/third_party/wasm-micro-runtime EXCLUDE_FROM_ALL) add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) diff --git a/build_tools/third_party/wasm-micro-runtime/CMakeLists.txt b/build_tools/third_party/wasm-micro-runtime/CMakeLists.txt new file mode 100644 index 000000000000..21a2c7f5b245 --- /dev/null +++ b/build_tools/third_party/wasm-micro-runtime/CMakeLists.txt @@ -0,0 +1,59 @@ +# Copyright 2021 Google LLC +# +# Licensed 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 +# +# https://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 modeled after the instructions at +# https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/build_wamr.md + +set(WAMR_SOURCE_DIR "${IREE_SOURCE_DIR}/third_party/wasm-micro-runtime") + +# Runtime build target -> platform in wasm-micro-runtime/core/shared/platform/ +if(ANDROID) + set(WAMR_BUILD_PLATFORM "android") +elseif(APPLE) + set(WAMR_BUILD_PLATFORM "darwin") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(WAMR_BUILD_PLATFORM "linux") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + set(WAMR_BUILD_PLATFORM "windows") + # Enable MASM (Microsoft Macro Assembler) for compiling .asm files. + enable_language(ASM_MASM) +endif() + +# Pick the features we want. Most default to disabled. +set(WAMR_BUILD_INTERP 1) + +include(${WAMR_SOURCE_DIR}/build-scripts/runtime_lib.cmake) + +# WAMR unconditionally adds a global compiler flag for 64 bit targets, which +# is not handled or needed by MSVC. +# TODO(scotttodd): Omit the flag upstream rather than work around it here. +if(MSVC) + string(REGEX REPLACE " -fPIC" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) +endif() + +set(_WAMR_LIBRARY_NAME "wasm_micro_runtime_vmlib") +add_library(${_WAMR_LIBRARY_NAME} STATIC "") +target_sources(${_WAMR_LIBRARY_NAME} + PRIVATE + ${WAMR_RUNTIME_LIB_SOURCE}) +target_include_directories(${_WAMR_LIBRARY_NAME} SYSTEM + PUBLIC + "$") + +# Suppress all warnings for this third party code. +if(MSVC) + target_compile_options(${_WAMR_LIBRARY_NAME} PRIVATE "/W0") +else() + target_compile_options(${_WAMR_LIBRARY_NAME} PRIVATE "-w") +endif()