|
| 1 | +# Copyright (C) 2024 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(debug_tools_sample) |
| 9 | + |
| 10 | +################ runtime settings ################ |
| 11 | +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) |
| 12 | +if (APPLE) |
| 13 | + add_definitions(-DBH_PLATFORM_DARWIN) |
| 14 | +endif () |
| 15 | + |
| 16 | +# Resetdefault linker flags |
| 17 | +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") |
| 18 | +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") |
| 19 | + |
| 20 | +# WAMR features switch |
| 21 | + |
| 22 | +# Set WAMR_BUILD_TARGET, currently values supported: |
| 23 | +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", |
| 24 | +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" |
| 25 | +if (NOT DEFINED WAMR_BUILD_TARGET) |
| 26 | + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") |
| 27 | + set (WAMR_BUILD_TARGET "AARCH64") |
| 28 | + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") |
| 29 | + set (WAMR_BUILD_TARGET "RISCV64") |
| 30 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 31 | + # Build as X86_64 by default in 64-bit platform |
| 32 | + set (WAMR_BUILD_TARGET "X86_64") |
| 33 | + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 34 | + # Build as X86_32 by default in 32-bit platform |
| 35 | + set (WAMR_BUILD_TARGET "X86_32") |
| 36 | + else () |
| 37 | + message(SEND_ERROR "Unsupported build target platform!") |
| 38 | + endif () |
| 39 | +endif () |
| 40 | + |
| 41 | +if (NOT CMAKE_BUILD_TYPE) |
| 42 | + set (CMAKE_BUILD_TYPE Release) |
| 43 | +endif () |
| 44 | + |
| 45 | +set(WAMR_BUILD_INTERP 1) |
| 46 | +set(WAMR_BUILD_LIBC_WASI 1) |
| 47 | +set(WAMR_BUILD_FAST_INTERP 0) # Otherwise addresses don't match llvm-dwarfdump (addr2line) |
| 48 | +set(WAMR_BUILD_AOT 1) |
| 49 | +set(WAMR_BUILD_DUMP_CALL_STACK 1) # Otherwise stack trace is not printed (addr2line) |
| 50 | + |
| 51 | +# compiling and linking flags |
| 52 | +if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) |
| 53 | + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") |
| 54 | +endif () |
| 55 | +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") |
| 56 | + |
| 57 | +# build out vmlib |
| 58 | +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) |
| 59 | +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) |
| 60 | + |
| 61 | +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) |
| 62 | + |
| 63 | +################ wasm application ################ |
| 64 | +add_subdirectory(wasm-apps) |
| 65 | + |
| 66 | +################ wamr runtime ################ |
| 67 | +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) |
| 68 | + |
| 69 | +set (RUNTIME_SOURCE_ALL |
| 70 | + ${CMAKE_CURRENT_LIST_DIR}/../../product-mini/platforms/linux/main.c |
| 71 | + ${UNCOMMON_SHARED_SOURCE} |
| 72 | +) |
| 73 | +add_executable (iwasm ${RUNTIME_SOURCE_ALL}) |
| 74 | +check_pie_supported() |
| 75 | +set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 76 | +target_link_libraries(iwasm vmlib -lm -ldl) |
0 commit comments