CMakeLists.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 (WAMR_BUILD_PLATFORM "linux-sgx")
  6. # Reset default linker flags
  7. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  8. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  9. # Set WAMR_BUILD_TARGET
  10. if (NOT DEFINED WAMR_BUILD_TARGET)
  11. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  12. # Build as X86_64 by default in 64-bit platform
  13. set (WAMR_BUILD_TARGET "X86_64")
  14. if (NOT DEFINED WAMR_BUILD_SIMD)
  15. # Enable SIMD by default in 64-bit platform
  16. set (WAMR_BUILD_SIMD 1)
  17. endif ()
  18. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  19. # Build as X86_32 by default in 32-bit platform
  20. set (WAMR_BUILD_TARGET "X86_32")
  21. else ()
  22. message(SEND_ERROR "Unsupported build target platform!")
  23. endif ()
  24. endif ()
  25. if (NOT CMAKE_BUILD_TYPE)
  26. set(CMAKE_BUILD_TYPE Release)
  27. endif ()
  28. if (NOT DEFINED WAMR_BUILD_INTERP)
  29. # Enable Interpreter by default
  30. set (WAMR_BUILD_INTERP 1)
  31. endif ()
  32. if (NOT DEFINED WAMR_BUILD_AOT)
  33. # Enable AOT by default
  34. # Please install Intel SGX SDKv2.8 or later.
  35. set (WAMR_BUILD_AOT 1)
  36. endif ()
  37. if (NOT DEFINED WAMR_BUILD_JIT)
  38. # Disable JIT by default.
  39. set (WAMR_BUILD_JIT 0)
  40. endif ()
  41. if (NOT DEFINED WAMR_BUILD_FAST_JIT)
  42. # Disable Fast JIT by default
  43. set (WAMR_BUILD_FAST_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_LIB_RATS)
  54. # Disable lib rats support by default
  55. set (WAMR_BUILD_LIB_RATS 0)
  56. endif()
  57. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  58. # Enable fast interpreter
  59. set (WAMR_BUILD_FAST_INTERP 1)
  60. endif ()
  61. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  62. # Enable multiple modules
  63. set (WAMR_BUILD_MULTI_MODULE 0)
  64. endif ()
  65. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  66. # Enable pthread library by default
  67. set (WAMR_BUILD_LIB_PTHREAD 1)
  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_SGX_IPFS)
  74. # Disable SGX IPFS by default
  75. set (WAMR_BUILD_SGX_IPFS 0)
  76. endif ()
  77. if (NOT DEFINED WAMR_BUILD_STATIC_PGO)
  78. # Disable static PGO by default
  79. set (WAMR_BUILD_STATIC_PGO 0)
  80. endif ()
  81. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  82. # Enable reference types by default
  83. set (WAMR_BUILD_REF_TYPES 1)
  84. endif ()
  85. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  86. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -ffunction-sections -fdata-sections \
  87. -Wall -Wno-unused-parameter -Wno-pedantic \
  88. -nostdinc -fvisibility=hidden -fpie" )
  89. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  90. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  91. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  92. set_version_info (vmlib)
  93. add_custom_command (
  94. OUTPUT libvmlib_untrusted.a
  95. COMMAND mkdir -p untrusted && cd untrusted &&
  96. ${CMAKE_C_COMPILER} -c ${PLATFORM_SHARED_SOURCE_UNTRUSTED}
  97. COMMAND ${CMAKE_AR} rc libvmlib_untrusted.a untrusted/*.o)
  98. add_custom_target (vmlib_untrusted ALL DEPENDS libvmlib_untrusted.a)
  99. if ((WAMR_BUILD_STATIC_PGO EQUAL 1) AND (WAMR_BUILD_AOT EQUAL 1))
  100. execute_process(
  101. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_STATIC_PGO = 0/WAMR_BUILD_STATIC_PGO = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  102. OUTPUT_VARIABLE cmdOutput
  103. )
  104. else()
  105. execute_process(
  106. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_STATIC_PGO = 1/WAMR_BUILD_STATIC_PGO = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  107. OUTPUT_VARIABLE cmdOutput
  108. )
  109. endif()
  110. if (DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL)
  111. execute_process(
  112. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_GLOBAL_HEAP_POOL = .*/WAMR_BUILD_GLOBAL_HEAP_POOL = ${WAMR_BUILD_GLOBAL_HEAP_POOL}/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  113. OUTPUT_VARIABLE cmdOutput
  114. )
  115. if (DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE)
  116. execute_process(
  117. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_GLOBAL_HEAP_SIZE = .*/WAMR_BUILD_GLOBAL_HEAP_SIZE = ${WAMR_BUILD_GLOBAL_HEAP_SIZE}/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  118. OUTPUT_VARIABLE cmdOutput
  119. )
  120. endif()
  121. endif()
  122. if (WAMR_BUILD_LIB_RATS EQUAL 1)
  123. execute_process(
  124. COMMAND bash -c "sed -i -E 's/^#define WASM_ENABLE_LIB_RATS 0/#define WASM_ENABLE_LIB_RATS 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  125. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIB_RATS = 0/WAMR_BUILD_LIB_RATS = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  126. OUTPUT_VARIABLE cmdOutput
  127. )
  128. else()
  129. execute_process(
  130. COMMAND bash -c "sed -i -E 's/^#define WASM_ENABLE_LIB_RATS 1/#define WASM_ENABLE_LIB_RATS 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  131. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIB_RATS = 1/WAMR_BUILD_LIB_RATS = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  132. OUTPUT_VARIABLE cmdOutput
  133. )
  134. endif()
  135. if (WAMR_BUILD_SGX_IPFS EQUAL 1)
  136. execute_process(
  137. COMMAND bash -c "sed -i -E 's/^#define WASM_ENABLE_SGX_IPFS 0/#define WASM_ENABLE_SGX_IPFS 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  138. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_SGX_IPFS = 0/WAMR_BUILD_SGX_IPFS = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  139. OUTPUT_VARIABLE cmdOutput
  140. )
  141. else()
  142. execute_process(
  143. COMMAND bash -c "sed -i -E 's/^#define WASM_ENABLE_SGX_IPFS 1/#define WASM_ENABLE_SGX_IPFS 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  144. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_SGX_IPFS = 1/WAMR_BUILD_SGX_IPFS = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  145. OUTPUT_VARIABLE cmdOutput
  146. )
  147. endif()
  148. if (WAMR_BUILD_LIBC_WASI EQUAL 1)
  149. execute_process(
  150. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIBC_WASI = 0/WAMR_BUILD_LIBC_WASI = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  151. OUTPUT_VARIABLE cmdOutput
  152. )
  153. else()
  154. execute_process(
  155. COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIBC_WASI = 1/WAMR_BUILD_LIBC_WASI = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  156. OUTPUT_VARIABLE cmdOutput
  157. )
  158. endif()
  159. if (WAMR_BUILD_SPEC_TEST EQUAL 1)
  160. execute_process(
  161. COMMAND bash -c "sed -i -E 's/<ReservedMemMaxSize>0x1000000<\\/ReservedMemMaxSize>/<ReservedMemMaxSize>0x8000000<\\/ReservedMemMaxSize>/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.config.xml"
  162. OUTPUT_VARIABLE cmdOutput
  163. )
  164. endif()