|
| 1 | +# Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +cmake_minimum_required(VERSION 3.14) |
| 5 | + |
| 6 | +include(CheckPIESupported) |
| 7 | + |
| 8 | +project(wasi_threads_sample) |
| 9 | + |
| 10 | +if (NOT DEFINED WASI_SYSROOT) |
| 11 | + message (WARNING "Custom sysroot with threads enabled is required to build wasi threads samples. |
| 12 | +Please note that current wasi-sdk doesn't ship with threads enabled. |
| 13 | +Run cmake command with -DWASI_SYSROOT=/path/to/sysroot/with/threads to compile samples.") |
| 14 | + return () |
| 15 | +endif () |
| 16 | + |
| 17 | +################ runtime settings ################ |
| 18 | +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) |
| 19 | +if (APPLE) |
| 20 | + add_definitions(-DBH_PLATFORM_DARWIN) |
| 21 | +endif () |
| 22 | + |
| 23 | +# Resetdefault linker flags |
| 24 | +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") |
| 25 | +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") |
| 26 | + |
| 27 | +# WAMR features switch |
| 28 | + |
| 29 | +# Set WAMR_BUILD_TARGET, currently values supported: |
| 30 | +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", |
| 31 | +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" |
| 32 | +if (NOT DEFINED WAMR_BUILD_TARGET) |
| 33 | + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") |
| 34 | + set (WAMR_BUILD_TARGET "AARCH64") |
| 35 | + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") |
| 36 | + set (WAMR_BUILD_TARGET "RISCV64") |
| 37 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 38 | + # Build as X86_64 by default in 64-bit platform |
| 39 | + set (WAMR_BUILD_TARGET "X86_64") |
| 40 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 41 | + # Build as X86_32 by default in 32-bit platform |
| 42 | + set (WAMR_BUILD_TARGET "X86_32") |
| 43 | + else () |
| 44 | + message(SEND_ERROR "Unsupported build target platform!") |
| 45 | + endif () |
| 46 | +endif () |
| 47 | + |
| 48 | +if (NOT CMAKE_BUILD_TYPE) |
| 49 | + set (CMAKE_BUILD_TYPE Release) |
| 50 | +endif () |
| 51 | + |
| 52 | +set(WAMR_BUILD_INTERP 1) |
| 53 | +set(WAMR_BUILD_AOT 1) |
| 54 | +set(WAMR_BUILD_JIT 0) |
| 55 | +set(WAMR_BUILD_LIBC_BUILTIN 1) |
| 56 | +set(WAMR_BUILD_FAST_INTERP 1) |
| 57 | +set(WAMR_BUILD_LIBC_WASI 1) |
| 58 | +set(WAMR_BUILD_LIB_WASI_THREADS 1) |
| 59 | + |
| 60 | +# compiling and linking flags |
| 61 | +if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) |
| 62 | + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") |
| 63 | +endif () |
| 64 | +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") |
| 65 | + |
| 66 | +# build out vmlib |
| 67 | +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) |
| 68 | +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) |
| 69 | + |
| 70 | +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) |
| 71 | +################################################ |
| 72 | + |
| 73 | + |
| 74 | +################ wasm application ################ |
| 75 | +add_subdirectory(wasm-apps) |
| 76 | + |
| 77 | +################ wamr runtime ################ |
| 78 | +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) |
| 79 | + |
| 80 | +set (RUNTIME_SOURCE_ALL |
| 81 | + ${CMAKE_CURRENT_LIST_DIR}/../../product-mini/platforms/linux/main.c |
| 82 | + ${UNCOMMON_SHARED_SOURCE} |
| 83 | +) |
| 84 | +add_executable (iwasm ${RUNTIME_SOURCE_ALL}) |
| 85 | +check_pie_supported() |
| 86 | +set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 87 | +target_link_libraries(iwasm vmlib -lpthread -lm -ldl) |
0 commit comments