CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.9)
  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. # Enable 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 (COLLECT_CODE_COVERAGE EQUAL 1)
  74. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  75. endif ()
  76. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  77. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -ffunction-sections -fdata-sections \
  78. -Wall -Wno-unused-parameter -Wno-pedantic \
  79. -nostdinc -fvisibility=hidden -fpie" )
  80. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  81. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  82. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  83. add_custom_command (
  84. OUTPUT libvmlib_untrusted.a
  85. COMMAND mkdir -p untrusted && cd untrusted &&
  86. ${CMAKE_C_COMPILER} -c ${PLATFORM_SHARED_SOURCE_UNTRUSTED}
  87. COMMAND ${CMAKE_AR} rc libvmlib_untrusted.a untrusted/*.o)
  88. add_custom_target (vmlib_untrusted ALL DEPENDS libvmlib_untrusted.a)
  89. if (WAMR_BUILD_LIB_RATS EQUAL 1)
  90. execute_process(
  91. COMMAND bash -c "sed -i -E 's/^#define LIB_RATS 0 /#define LIB_RATS 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  92. OUTPUT_VARIABLE cmdOutput
  93. )
  94. else()
  95. execute_process(
  96. COMMAND bash -c "sed -i -E 's/^#define LIB_RATS 1/#define LIB_RATS 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  97. OUTPUT_VARIABLE cmdOutput
  98. )
  99. endif()
  100. if (WAMR_BUILD_SGX_IPFS EQUAL 1)
  101. execute_process(
  102. COMMAND bash -c "sed -i -E 's/^#define SGX_IPFS 0/#define SGX_IPFS 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  103. OUTPUT_VARIABLE cmdOutput
  104. )
  105. execute_process(
  106. COMMAND bash -c "sed -i -E 's/^SGX_IPFS = 0/SGX_IPFS = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  107. OUTPUT_VARIABLE cmdOutput
  108. )
  109. else()
  110. execute_process(
  111. COMMAND bash -c "sed -i -E 's/^#define SGX_IPFS 1/#define SGX_IPFS 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
  112. OUTPUT_VARIABLE cmdOutput
  113. )
  114. execute_process(
  115. COMMAND bash -c "sed -i -E 's/^SGX_IPFS = 1/SGX_IPFS = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
  116. OUTPUT_VARIABLE cmdOutput
  117. )
  118. endif()