CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required (VERSION 3.14)
  4. project (iwasm)
  5. # set (CMAKE_VERBOSE_MAKEFILE 1)
  6. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  7. if (APPLE)
  8. add_definitions(-DBH_PLATFORM_DARWIN)
  9. endif ()
  10. # Reset default linker flags
  11. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  12. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  13. set (CMAKE_C_STANDARD 99)
  14. set (CMAKE_CXX_STANDARD 17)
  15. # Set WAMR_BUILD_TARGET, currently values supported:
  16. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
  17. if (NOT DEFINED WAMR_BUILD_TARGET)
  18. if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
  19. set (WAMR_BUILD_TARGET "AARCH64")
  20. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  21. set (WAMR_BUILD_TARGET "RISCV64")
  22. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  23. # Build as X86_64 by default in 64-bit platform
  24. set (WAMR_BUILD_TARGET "X86_64")
  25. else ()
  26. # Build as X86_32 by default in 32-bit platform
  27. set (WAMR_BUILD_TARGET "X86_32")
  28. endif ()
  29. endif ()
  30. if (NOT CMAKE_BUILD_TYPE)
  31. set(CMAKE_BUILD_TYPE Release)
  32. endif ()
  33. if (NOT DEFINED WAMR_BUILD_INTERP)
  34. # Enable Interpreter by default
  35. set (WAMR_BUILD_INTERP 1)
  36. endif ()
  37. if (NOT DEFINED WAMR_BUILD_AOT)
  38. # Enable AOT by default.
  39. set (WAMR_BUILD_AOT 1)
  40. endif ()
  41. if (NOT DEFINED WAMR_BUILD_JIT)
  42. # Disable JIT by default.
  43. set (WAMR_BUILD_JIT 0)
  44. endif ()
  45. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  46. # Enable libc builtin support by default
  47. set (WAMR_BUILD_LIBC_BUILTIN 1)
  48. endif ()
  49. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  50. # Enable libc wasi support by default
  51. set (WAMR_BUILD_LIBC_WASI 1)
  52. endif ()
  53. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  54. # Enable fast interpreter
  55. set (WAMR_BUILD_FAST_INTERP 1)
  56. endif ()
  57. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  58. # Enable multiple modules
  59. set (WAMR_BUILD_MULTI_MODULE 0)
  60. endif ()
  61. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  62. # Disable pthread library by default
  63. set (WAMR_BUILD_LIB_PTHREAD 0)
  64. endif ()
  65. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  66. # Disable wasm mini loader by default
  67. set (WAMR_BUILD_MINI_LOADER 0)
  68. endif ()
  69. if (NOT DEFINED WAMR_BUILD_SIMD)
  70. # Disable SIMD by default
  71. set (WAMR_BUILD_SIMD 0)
  72. endif ()
  73. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  74. # Enable reference types by default
  75. set (WAMR_BUILD_REF_TYPES 1)
  76. endif ()
  77. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  78. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  79. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  80. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  81. if (NOT WAMR_BUILD_PLATFORM STREQUAL "darwin")
  82. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
  83. endif ()
  84. # The following flags are to enhance security, but it may impact performance,
  85. # we disable them by default.
  86. #if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  87. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
  88. #endif ()
  89. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
  90. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
  91. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  92. add_executable (test_invoke_native main.c test_invoke_native.c ${UNCOMMON_SHARED_SOURCE})
  93. install (TARGETS test_invoke_native DESTINATION bin)
  94. target_link_libraries (test_invoke_native vmlib ${LLVM_AVAILABLE_LIBS} -lm -ldl -lpthread)