CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required (VERSION 2.8)
  4. if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
  5. project (basic)
  6. else()
  7. project (basic C ASM)
  8. enable_language (ASM_MASM)
  9. endif()
  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. # Reset default linker flags
  16. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  17. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  18. # WAMR features switch
  19. set (WAMR_BUILD_TARGET "X86_64")
  20. set(CMAKE_BUILD_TYPE Debug)
  21. set (WAMR_BUILD_INTERP 1)
  22. set (WAMR_BUILD_AOT 1)
  23. set (WAMR_BUILD_JIT 0)
  24. set (WAMR_BUILD_LIBC_BUILTIN 1)
  25. if (NOT MSVC)
  26. set (WAMR_BUILD_LIBC_WASI 1)
  27. endif ()
  28. set (WAMR_BUILD_FAST_INTERP 0)
  29. if (NOT MSVC)
  30. # linker flags
  31. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
  32. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  33. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  34. endif ()
  35. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
  36. if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  37. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  38. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
  39. endif ()
  40. endif ()
  41. endif ()
  42. # build out vmlib
  43. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  44. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  45. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  46. ################ application related ################
  47. include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
  48. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  49. add_executable (basic src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE})
  50. if (APPLE)
  51. target_link_libraries (basic vmlib -lm -ldl -lpthread)
  52. else ()
  53. target_link_libraries (basic vmlib -lm -ldl -lpthread -lrt)
  54. endif ()