CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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...3.16)
  4. project (iwasm)
  5. # set (CMAKE_VERBOSE_MAKEFILE 1)
  6. set (WAMR_BUILD_PLATFORM "linux")
  7. # Reset default linker flags
  8. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  9. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  10. set (CMAKE_C_STANDARD 99)
  11. # Set WAMR_BUILD_TARGET, currently values supported:
  12. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  13. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  14. if (NOT DEFINED WAMR_BUILD_TARGET)
  15. if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
  16. set (WAMR_BUILD_TARGET "AARCH64")
  17. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  18. set (WAMR_BUILD_TARGET "RISCV64")
  19. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  20. # Build as X86_64 by default in 64-bit platform
  21. set (WAMR_BUILD_TARGET "X86_64")
  22. else ()
  23. # Build as X86_32 by default in 32-bit platform
  24. set (WAMR_BUILD_TARGET "X86_32")
  25. endif ()
  26. endif ()
  27. if (NOT CMAKE_BUILD_TYPE)
  28. set(CMAKE_BUILD_TYPE Release)
  29. endif ()
  30. if (NOT DEFINED WAMR_BUILD_INTERP)
  31. # Enable Interpreter by default
  32. set (WAMR_BUILD_INTERP 1)
  33. endif ()
  34. if (NOT DEFINED WAMR_BUILD_AOT)
  35. # Enable AOT by default.
  36. set (WAMR_BUILD_AOT 1)
  37. endif ()
  38. if (NOT DEFINED WAMR_BUILD_JIT)
  39. # Disable JIT by default.
  40. set (WAMR_BUILD_JIT 0)
  41. endif ()
  42. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  43. # Enable libc builtin support by default
  44. set (WAMR_BUILD_LIBC_BUILTIN 1)
  45. endif ()
  46. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  47. # Enable libc wasi support by default
  48. set (WAMR_BUILD_LIBC_WASI 1)
  49. endif ()
  50. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  51. # Enable fast interpreter
  52. set (WAMR_BUILD_FAST_INTERP 1)
  53. endif ()
  54. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  55. # Enable multiple modules
  56. set (WAMR_BUILD_MULTI_MODULE 0)
  57. endif ()
  58. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  59. # Disable pthread library by default
  60. set (WAMR_BUILD_LIB_PTHREAD 0)
  61. endif ()
  62. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  63. # Disable wasm mini loader by default
  64. set (WAMR_BUILD_MINI_LOADER 0)
  65. endif ()
  66. if (NOT DEFINED WAMR_BUILD_SIMD)
  67. # Enable SIMD by default
  68. set (WAMR_BUILD_SIMD 1)
  69. endif ()
  70. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  71. # Disable reference types by default
  72. set (WAMR_BUILD_REF_TYPES 0)
  73. endif ()
  74. if (COLLECT_CODE_COVERAGE EQUAL 1)
  75. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  76. endif ()
  77. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  78. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  79. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
  80. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
  81. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
  82. if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  83. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  84. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
  85. endif ()
  86. endif ()
  87. # The following flags are to enhance security, but it may impact performance,
  88. # we disable them by default.
  89. #if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  90. # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
  91. #endif ()
  92. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
  93. #set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
  94. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  95. # STATIC LIBRARY
  96. add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
  97. set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
  98. install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
  99. # SHARED LIBRARY
  100. add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
  101. set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
  102. target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
  103. install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
  104. # HEADERS
  105. install (FILES
  106. ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h
  107. ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h
  108. DESTINATION include)