toolchain.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.0)
  4. if(DEFINED _WAMR_TOOLCHAIN_CMAKE_)
  5. return()
  6. else()
  7. set(_WAMR_TOOLCHAIN_CMAKE_ 1)
  8. endif()
  9. SET(CMAKE_SYSTEM_NAME Linux)
  10. ################ COMPILER ################
  11. find_program(CLANG_11 NAMES clang clang-11 REQUIRED)
  12. find_program(CLANG++_11 NAMES clang++ clang++-11 REQUIRED)
  13. if(NOT CLANG_11)
  14. message(FATAL_ERROR "clang not found")
  15. else()
  16. message(STATUS "use ${CLANG_11} as the c compiler")
  17. endif()
  18. if(NOT CLANG++_11)
  19. message(FATAL_ERROR "clang++ not found")
  20. else()
  21. message(STATUS "use ${CLANG++_11} as the c++ compiler")
  22. endif()
  23. set(CMAKE_C_COMPILER "${CLANG_11}" CACHE STRING "C compiler" FORCE)
  24. set(CMAKE_C_COMPILER_ID Clang CACHE STRING "C compiler ID" FORCE)
  25. set(CMAKE_CXX_COMPILER "${CLANG++_11}" CACHE STRING "C++ compiler" FORCE)
  26. set(CMAKE_CXX_COMPILER_ID Clang CACHE STRING "C++ compiler ID" FORCE)
  27. ################ WASI AS SYSROOT ################
  28. find_path(WASI_SYSROOT
  29. wasi-sysroot
  30. PATHS /opt/wasi-sdk-11.0/share /opt/wasi-sdk/share
  31. REQUIRED
  32. )
  33. if(NOT WASI_SYSROOT)
  34. message(FATAL_ERROR
  35. "can not find wasi sysroot. "
  36. "please download it from "
  37. "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-11/wasi-sdk-11.0-linux.tar.gz "
  38. "and install it under /opt"
  39. )
  40. endif()
  41. set(CMAKE_SYSROOT ${WASI_SYSROOT}/wasi-sysroot CACHE STRING "--sysroot to compiler" FORCE)
  42. add_compile_options(
  43. --target=wasm32-wasi
  44. -msimd128
  45. $<IF:$<CONFIG:Debug>,-O0,-O3>
  46. $<$<CONFIG:Debug>:-g>
  47. $<$<CONFIG:Debug>:-v>
  48. )
  49. # need users to create their own additional include files
  50. ################ AR ################
  51. find_program(LLVM_AR NAMES llvm-ar llvm-ar-11 REQUIRED)
  52. if(NOT LLVM_AR)
  53. message(FATAL_ERROR "llvm-ar not found")
  54. else()
  55. message(STATUS "use ${LLVM_AR} as the AR")
  56. endif()
  57. set(CMAKE_AR "${LLVM_AR}" CACHE STRING "AR" FORCE)
  58. ################ RANLIB ################
  59. find_program(LLVM_RANLIB NAMES llvm-ranlib llvm-ranlib-11 REQUIRED)
  60. if(NOT LLVM_RANLIB)
  61. message(FATAL_ERROR "llvm-ranlib not found")
  62. else()
  63. message(STATUS "use ${LLVM_RANLIB} as the ranlib")
  64. endif()
  65. set(CMAKE_RANLIB "${LLVM_RANLIB}" CACHE STRING "RANLIB" FORCE)
  66. ################ LD ################
  67. find_program(WASM_LD NAMES wasm-ld wasm-ld-11 REQUIRED)
  68. if(NOT WASM_LD)
  69. message(FATAL_ERROR "wasm-ld not found")
  70. else()
  71. message(STATUS "use ${WASM_LD} as the linker")
  72. endif()
  73. add_link_options(
  74. --target=wasm32-wasi
  75. -fuse-ld=${WASM_LD}
  76. LINKER:--allow-undefined
  77. $<IF:$<CONFIG:Debug>,-O0,-O3>
  78. $<$<CONFIG:Debug>:-g>
  79. $<$<CONFIG:Debug>:-v>
  80. )