CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. include(CheckPIESupported)
  5. project (iwasm)
  6. set (CMAKE_VERBOSE_MAKEFILE OFF)
  7. set (WAMR_BUILD_PLATFORM "linux")
  8. # Reset default linker flags
  9. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  10. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  11. set (CMAKE_C_STANDARD 99)
  12. set (CMAKE_CXX_STANDARD 17)
  13. # Set WAMR_BUILD_TARGET, currently values supported:
  14. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  15. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  16. if (NOT DEFINED WAMR_BUILD_TARGET)
  17. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  18. set (WAMR_BUILD_TARGET "AARCH64")
  19. if (NOT DEFINED WAMR_BUILD_SIMD)
  20. set (WAMR_BUILD_SIMD 1)
  21. endif ()
  22. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  23. set (WAMR_BUILD_TARGET "RISCV64")
  24. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  25. # Build as X86_64 by default in 64-bit platform
  26. set (WAMR_BUILD_TARGET "X86_64")
  27. if (NOT DEFINED WAMR_BUILD_SIMD)
  28. set (WAMR_BUILD_SIMD 1)
  29. endif ()
  30. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  31. # Build as X86_32 by default in 32-bit platform
  32. set (WAMR_BUILD_TARGET "X86_32")
  33. else ()
  34. message(SEND_ERROR "Unsupported build target platform!")
  35. endif ()
  36. endif ()
  37. if (NOT CMAKE_BUILD_TYPE)
  38. set(CMAKE_BUILD_TYPE Release)
  39. endif ()
  40. if (NOT DEFINED WAMR_BUILD_INTERP)
  41. # Enable Interpreter by default
  42. set (WAMR_BUILD_INTERP 1)
  43. endif ()
  44. if (NOT DEFINED WAMR_BUILD_AOT)
  45. # Enable AOT by default.
  46. set (WAMR_BUILD_AOT 1)
  47. endif ()
  48. if (NOT DEFINED WAMR_BUILD_JIT)
  49. # Disable JIT by default.
  50. set (WAMR_BUILD_JIT 0)
  51. endif ()
  52. if (NOT DEFINED WAMR_BUILD_FAST_JIT)
  53. # Disable Fast JIT by default
  54. set (WAMR_BUILD_FAST_JIT 0)
  55. endif ()
  56. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  57. # Enable libc builtin support by default
  58. set (WAMR_BUILD_LIBC_BUILTIN 1)
  59. endif ()
  60. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  61. # Enable libc wasi support by default
  62. set (WAMR_BUILD_LIBC_WASI 1)
  63. endif ()
  64. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  65. # Enable fast interpreter
  66. set (WAMR_BUILD_FAST_INTERP 1)
  67. endif ()
  68. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  69. # Disable multiple modules by default
  70. set (WAMR_BUILD_MULTI_MODULE 0)
  71. endif ()
  72. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  73. # Disable pthread library by default
  74. set (WAMR_BUILD_LIB_PTHREAD 0)
  75. endif ()
  76. if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
  77. # Disable wasi threads library by default
  78. set (WAMR_BUILD_LIB_WASI_THREADS 0)
  79. endif()
  80. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  81. # Disable wasm mini loader by default
  82. set (WAMR_BUILD_MINI_LOADER 0)
  83. endif ()
  84. if (NOT DEFINED WAMR_BUILD_SIMD)
  85. # Enable SIMD by default
  86. set (WAMR_BUILD_SIMD 1)
  87. endif ()
  88. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  89. # Disable reference types by default
  90. set (WAMR_BUILD_REF_TYPES 0)
  91. endif ()
  92. if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
  93. # Disable Debug feature by default
  94. set (WAMR_BUILD_DEBUG_INTERP 0)
  95. endif ()
  96. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  97. set (WAMR_BUILD_FAST_INTERP 0)
  98. set (WAMR_BUILD_MINI_LOADER 0)
  99. set (WAMR_BUILD_SIMD 0)
  100. endif ()
  101. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  102. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  103. check_pie_supported()
  104. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  105. set_target_properties (vmlib PROPERTIES POSITION_INDEPENDENT_CODE ON)
  106. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  107. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow")
  108. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
  109. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
  110. if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  111. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  112. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
  113. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register")
  114. # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub
  115. endif ()
  116. endif ()
  117. # The following flags are to enhance security, but it may impact performance,
  118. # we disable them by default.
  119. #if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  120. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
  121. #endif ()
  122. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
  123. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
  124. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  125. add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
  126. set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON)
  127. install (TARGETS iwasm DESTINATION bin)
  128. target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread)
  129. add_library (libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
  130. install (TARGETS libiwasm DESTINATION lib)
  131. set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
  132. target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread)