CMakeLists.txt 4.5 KB

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