|
| 1 | +# Copyright (C) 2019 Intel Corporation. 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 | +if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") |
| 9 | + project (shared_heap_test) |
| 10 | +else() |
| 11 | + project (shared_heap_test C ASM) |
| 12 | +endif() |
| 13 | + |
| 14 | +################ runtime settings ################ |
| 15 | +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) |
| 16 | +if (APPLE) |
| 17 | + add_definitions(-DBH_PLATFORM_DARWIN) |
| 18 | +endif () |
| 19 | + |
| 20 | +# Reset default linker flags |
| 21 | +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") |
| 22 | +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") |
| 23 | + |
| 24 | +# WAMR features switch |
| 25 | + |
| 26 | +# Set WAMR_BUILD_TARGET, currently values supported: |
| 27 | +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", |
| 28 | +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" |
| 29 | + |
| 30 | +if (NOT DEFINED WAMR_BUILD_TARGET) |
| 31 | + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") |
| 32 | + set (WAMR_BUILD_TARGET "AARCH64") |
| 33 | + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") |
| 34 | + set (WAMR_BUILD_TARGET "RISCV64") |
| 35 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 36 | + # Build as X86_64 by default in 64-bit platform |
| 37 | + set (WAMR_BUILD_TARGET "X86_64") |
| 38 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 39 | + # Build as X86_32 by default in 32-bit platform |
| 40 | + set (WAMR_BUILD_TARGET "X86_32") |
| 41 | + else () |
| 42 | + message(SEND_ERROR "Unsupported build target platform!") |
| 43 | + endif () |
| 44 | +endif () |
| 45 | + |
| 46 | +if (NOT CMAKE_BUILD_TYPE) |
| 47 | + set (CMAKE_BUILD_TYPE Debug) |
| 48 | +endif () |
| 49 | + |
| 50 | +set (WAMR_BUILD_INTERP 1) |
| 51 | +set (WAMR_BUILD_AOT 1) |
| 52 | +set (WAMR_BUILD_JIT 0) |
| 53 | +set (WAMR_BUILD_LIBC_BUILTIN 1) |
| 54 | +set (WAMR_BUILD_LIBC_WASI 0) |
| 55 | +set (WAMR_BUILD_SHARED_HEAP 1) |
| 56 | +set (WAMR_BUILD_GC_HEAP_VERIFY 1) |
| 57 | + |
| 58 | +if (NOT MSVC) |
| 59 | + # linker flags |
| 60 | + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) |
| 61 | + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") |
| 62 | + endif () |
| 63 | + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") |
| 64 | + if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") |
| 65 | + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) |
| 66 | + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") |
| 67 | + endif () |
| 68 | + endif () |
| 69 | +endif () |
| 70 | + |
| 71 | +# build out vmlib |
| 72 | +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) |
| 73 | +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) |
| 74 | + |
| 75 | +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) |
| 76 | + |
| 77 | +################ application related ################ |
| 78 | +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) |
| 79 | +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) |
| 80 | + |
| 81 | +add_executable (shared_heap_test src/main.c ${UNCOMMON_SHARED_SOURCE}) |
| 82 | + |
| 83 | +check_pie_supported() |
| 84 | +set_target_properties (shared_heap_test PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 85 | + |
| 86 | +if (APPLE) |
| 87 | + target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread) |
| 88 | +else () |
| 89 | + target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread -lrt) |
| 90 | +endif () |
| 91 | + |
| 92 | +add_subdirectory(wasm-apps) |
0 commit comments