CMakeLists.txt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 (wasm_c_api_test)
  5. ################ runtime settings ################
  6. set(CMAKE_BUILD_TYPE Debug)
  7. set(WAMR_BUILD_PLATFORM "linux")
  8. # Resetdefault linker flags
  9. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  10. set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  11. # WAMR features switch
  12. if (NOT DEFINED WAMR_BUILD_TARGET)
  13. set(WAMR_BUILD_TARGET "X86_64")
  14. endif()
  15. set(WAMR_BUILD_INTERP 1)
  16. set(WAMR_BUILD_AOT 0)
  17. set(WAMR_BUILD_JIT 0)
  18. set(WAMR_BUILD_LIBC_BUILTIN 1)
  19. set(WAMR_BUILD_LIBC_WASI 0)
  20. set(WAMR_BUILD_FAST_INTERP 0)
  21. # compiling and linking flags
  22. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
  23. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -mindirect-branch-register")
  24. # build out vmlib
  25. # hard code path here
  26. set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
  27. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  28. add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
  29. ################################################
  30. ################ unit test related ################
  31. # Yes. To solve the compatibility issue with CMAKE (>= 4.0), we need to update
  32. # our `cmake_minimum_required()` to 3.5. However, there are CMakeLists.txt
  33. # from 3rd parties that we should not alter. Therefore, in addition to
  34. # changing the `cmake_minimum_required()`, we should also add a configuration
  35. # here that is compatible with earlier versions.
  36. set(CMAKE_POLICY_VERSION_MINIMUM 3.5 FORCE)
  37. # Add googletest directly to our build. This defines
  38. # the gtest and gtest_main targets.
  39. if (NOT (GOOGLETEST_INCLUDED EQUAL 1))
  40. # Prevent overriding the parent project's compiler/linker
  41. # settings on Windows
  42. set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  43. # Fetch Google test
  44. include (FetchContent)
  45. FetchContent_Declare (
  46. googletest
  47. URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  48. )
  49. FetchContent_MakeAvailable (googletest)
  50. endif()
  51. enable_testing()
  52. add_executable(wasm_c_api_test
  53. basic.cc
  54. )
  55. target_link_libraries(wasm_c_api_test vmlib gtest_main)
  56. gtest_discover_tests(wasm_c_api_test)