CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.21)
  4. project (iwasm)
  5. set (WAMR_BUILD_PLATFORM "darwin")
  6. set (WAMR_BUILD_TYPE Release)
  7. set (WAMR_BUILD_INTERP 1)
  8. set (WAMR_BUILD_AOT 0)
  9. set (WAMR_BUILD_LIBC_BUILTIN 1)
  10. set (WAMR_BUILD_LIBC_WASI 1)
  11. # Reset default linker flags
  12. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  13. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  14. # Set WAMR_BUILD_TARGET, currently values supported:
  15. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  16. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  17. if (NOT DEFINED WAMR_BUILD_TARGET)
  18. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  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. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  26. # Build as X86_32 by default in 32-bit platform
  27. set (WAMR_BUILD_TARGET "X86_32")
  28. else ()
  29. message(SEND_ERROR "Unsupported build target platform!")
  30. endif ()
  31. endif ()
  32. if (NOT CMAKE_BUILD_TYPE)
  33. set(CMAKE_BUILD_TYPE Release)
  34. endif ()
  35. set(CMAKE_CXX_STANDARD 17)
  36. if (NOT DEFINED WAMR_BUILD_INTERP)
  37. # Enable Interpreter by default
  38. set (WAMR_BUILD_INTERP 1)
  39. endif ()
  40. if (NOT DEFINED WAMR_BUILD_AOT)
  41. # Enable AOT by default.
  42. set (WAMR_BUILD_AOT 1)
  43. endif ()
  44. if (NOT DEFINED WAMR_BUILD_JIT)
  45. # Disable JIT by default.
  46. set (WAMR_BUILD_JIT 0)
  47. endif ()
  48. if (NOT DEFINED WAMR_BUILD_FAST_JIT)
  49. # Disable Fast JIT by default
  50. set (WAMR_BUILD_FAST_JIT 0)
  51. endif ()
  52. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  53. # Enable libc builtin support by default
  54. set (WAMR_BUILD_LIBC_BUILTIN 1)
  55. endif ()
  56. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  57. # Enable libc wasi support by default
  58. set (WAMR_BUILD_LIBC_WASI 1)
  59. endif ()
  60. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  61. # Enable fast interpreter
  62. set (WAMR_BUILD_FAST_INTERP 1)
  63. endif ()
  64. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  65. # Disable multiple module by default
  66. set (WAMR_BUILD_MULTI_MODULE 0)
  67. endif ()
  68. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  69. # Disable pthread library by default
  70. set (WAMR_BUILD_LIB_PTHREAD 1)
  71. endif ()
  72. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  73. # Disable wasm mini loader by default
  74. set (WAMR_BUILD_MINI_LOADER 0)
  75. endif ()
  76. if (NOT DEFINED WAMR_BUILD_SIMD)
  77. # Enable SIMD by default
  78. set (WAMR_BUILD_SIMD 1)
  79. endif ()
  80. if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
  81. # Disable Debug feature by default
  82. set (WAMR_BUILD_DEBUG_INTERP 0)
  83. endif ()
  84. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  85. set (WAMR_BUILD_FAST_INTERP 0)
  86. set (WAMR_BUILD_MINI_LOADER 0)
  87. set (WAMR_BUILD_SIMD 0)
  88. endif ()
  89. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  90. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  91. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
  92. # The following flags are to enhance security, but it may impact performance,
  93. # we disable them by default.
  94. #if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  95. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
  96. #endif ()
  97. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
  98. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
  99. add_library (iwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
  100. if (CMAKE_BUILD_TYPE STREQUAL Release)
  101. target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -s)
  102. else()
  103. target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl)
  104. endif()
  105. set (distribution_DIR ${CMAKE_BINARY_DIR}/distribution)
  106. set_target_properties (iwasm PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/wasm/lib")
  107. set_version_info (iwasm)
  108. add_custom_command (TARGET iwasm POST_BUILD
  109. COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/iwasm/include" "${distribution_DIR}/wasm/include/"
  110. COMMENT "Copying iwasm to output directory")