CMakeLists.txt 6.6 KB

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