unit_common.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. # Yes. To solve the compatibility issue with CMAKE (>= 4.0), we need to update
  4. # our `cmake_minimum_required()` to 3.5. However, there are CMakeLists.txt
  5. # from 3rd parties that we should not alter. Therefore, in addition to
  6. # changing the `cmake_minimum_required()`, we should also add a configuration
  7. # here that is compatible with earlier versions.
  8. set(CMAKE_POLICY_VERSION_MINIMUM 3.5 FORCE)
  9. if (NOT DEFINED WAMR_BUILD_PLATFORM)
  10. set (WAMR_BUILD_PLATFORM "linux")
  11. endif ()
  12. set (UNIT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
  13. include_directories(${UNIT_ROOT_DIR})
  14. enable_language (ASM)
  15. # Reset default linker flags
  16. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  17. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  18. # Set WAMR_BUILD_TARGET, currently values supported:
  19. # "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
  20. if (NOT DEFINED WAMR_BUILD_TARGET)
  21. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  22. # Build as X86_64 by default in 64-bit platform
  23. set (WAMR_BUILD_TARGET "X86_64")
  24. else ()
  25. # Build as X86_32 by default in 32-bit platform
  26. set (WAMR_BUILD_TARGET "X86_32")
  27. endif ()
  28. endif ()
  29. if (NOT CMAKE_BUILD_TYPE)
  30. set (CMAKE_BUILD_TYPE Debug)
  31. endif ()
  32. if (NOT DEFINED WAMR_BUILD_INTERP)
  33. # Enable Interpreter by default
  34. set (WAMR_BUILD_INTERP 1)
  35. endif ()
  36. if (NOT DEFINED WAMR_BUILD_AOT)
  37. # Enable AOT by default.
  38. set (WAMR_BUILD_AOT 1)
  39. endif ()
  40. if (NOT DEFINED WAMR_BUILD_JIT)
  41. # Disable JIT by default.
  42. set (WAMR_BUILD_JIT 0)
  43. endif ()
  44. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  45. # Enable libc builtin support by default
  46. set (WAMR_BUILD_LIBC_BUILTIN 1)
  47. endif ()
  48. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  49. # Enable libc wasi support by default
  50. set (WAMR_BUILD_LIBC_WASI 1)
  51. endif ()
  52. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  53. set (WAMR_BUILD_MULTI_MODULE 1)
  54. endif()
  55. if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
  56. set (WAMR_BUILD_APP_FRAMEWORK 1)
  57. endif ()
  58. if (COLLECT_CODE_COVERAGE EQUAL 1)
  59. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  60. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  61. endif ()
  62. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  63. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
  64. -Wall -Wno-unused-parameter -Wno-pedantic")
  65. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  66. # include the build config template file
  67. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  68. include_directories (${SHARED_DIR}/include
  69. ${IWASM_DIR}/include)
  70. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  71. if (NOT (GOOGLETEST_INCLUDED EQUAL 1))
  72. # Prevent overriding the parent project's compiler/linker
  73. # settings on Windows
  74. set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  75. # Fetch Google test
  76. include (FetchContent)
  77. FetchContent_Declare (
  78. googletest
  79. URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  80. )
  81. FetchContent_MakeAvailable (googletest)
  82. endif()
  83. # Add helper classes
  84. include_directories(${CMAKE_CURRENT_LIST_DIR}/common)
  85. message ("unit_common.cmake included")