CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.8)
  4. if (NOT DEFINED CMAKE_C_COMPILER)
  5. set (CMAKE_C_COMPILER "clang")
  6. endif ()
  7. if (NOT DEFINED CMAKE_CXX_COMPILER)
  8. set (CMAKE_CXX_COMPILER "clang++")
  9. endif ()
  10. project(wasm_mutator)
  11. set (CMAKE_BUILD_TYPE Debug)
  12. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  13. # Reset default linker flags
  14. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  15. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  16. set (CMAKE_C_STANDARD 11)
  17. set (CMAKE_CXX_STANDARD 17)
  18. # Set WAMR_BUILD_TARGET, currently values supported:
  19. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  20. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  21. if (NOT DEFINED WAMR_BUILD_TARGET)
  22. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  23. set (WAMR_BUILD_TARGET "AARCH64")
  24. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  25. set (WAMR_BUILD_TARGET "RISCV64")
  26. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  27. # Build as X86_64 by default in 64-bit platform
  28. set (WAMR_BUILD_TARGET "X86_64")
  29. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  30. # Build as X86_32 by default in 32-bit platform
  31. set (WAMR_BUILD_TARGET "X86_32")
  32. else ()
  33. message(SEND_ERROR "Unsupported build target platform!")
  34. endif ()
  35. endif ()
  36. if (APPLE)
  37. add_definitions(-DBH_PLATFORM_DARWIN)
  38. endif ()
  39. if(CUSTOM_MUTATOR EQUAL 1)
  40. add_compile_definitions(CUSTOM_MUTATOR)
  41. endif()
  42. if (NOT DEFINED WAMR_BUILD_INTERP)
  43. # Enable Interpreter by default
  44. set (WAMR_BUILD_INTERP 1)
  45. endif ()
  46. if (NOT DEFINED WAMR_BUILD_AOT)
  47. # Enable AOT by default.
  48. set (WAMR_BUILD_AOT 1)
  49. endif ()
  50. if (NOT DEFINED WAMR_BUILD_JIT)
  51. # Disable JIT by default.
  52. set (WAMR_BUILD_JIT 0)
  53. endif ()
  54. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  55. # Enable libc builtin support by default
  56. set (WAMR_BUILD_LIBC_BUILTIN 0)
  57. endif ()
  58. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  59. # Enable libc wasi support by default
  60. set (WAMR_BUILD_LIBC_WASI 0)
  61. endif ()
  62. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  63. # Enable fast interpreter
  64. set (WAMR_BUILD_FAST_INTERP 1)
  65. endif ()
  66. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  67. # Enable multiple modules
  68. set (WAMR_BUILD_MULTI_MODULE 0)
  69. endif ()
  70. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  71. # Disable pthread library by default
  72. set (WAMR_BUILD_LIB_PTHREAD 0)
  73. endif ()
  74. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  75. # Disable wasm mini loader by default
  76. set (WAMR_BUILD_MINI_LOADER 0)
  77. endif ()
  78. if (NOT DEFINED WAMR_BUILD_SIMD)
  79. # Enable SIMD by default
  80. set (WAMR_BUILD_SIMD 1)
  81. endif ()
  82. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  83. # Enable reference type by default
  84. set (WAMR_BUILD_REF_TYPES 1)
  85. endif ()
  86. if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
  87. # Disable Debug feature by default
  88. set (WAMR_BUILD_DEBUG_INTERP 0)
  89. endif ()
  90. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  91. set (WAMR_BUILD_FAST_INTERP 0)
  92. set (WAMR_BUILD_MINI_LOADER 0)
  93. set (WAMR_BUILD_SIMD 0)
  94. endif ()
  95. set (REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
  96. message([ceith]:REPO_ROOT_DIR, ${REPO_ROOT_DIR})
  97. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  98. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  99. add_definitions(-DWAMR_USE_MEM_POOL=0 -DWASM_ENABLE_FUZZ_TEST=1)
  100. # Enable fuzzer
  101. add_compile_options(-fsanitize=fuzzer)
  102. add_link_options(-fsanitize=fuzzer)
  103. # if not calling from oss-fuzz helper, enable all support sanitizers
  104. # oss-fuzz will define FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION in CFLAGS and CXXFLAGS
  105. set(CFLAGS_ENV $ENV{CFLAGS})
  106. string(FIND "${CFLAGS_ENV}" "-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" IN_OSS_FUZZ)
  107. if (IN_OSS_FUZZ EQUAL -1)
  108. message("[ceith]:Enable ASan and UBSan in non-oss-fuzz environment")
  109. add_compile_options(
  110. -fprofile-instr-generate -fcoverage-mapping
  111. -fno-sanitize-recover=all
  112. -fsanitize=address,undefined
  113. # reference: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
  114. # -fsanitize=undefined: All of the checks listed above other than float-divide-by-zero,
  115. # unsigned-integer-overflow, implicit-conversion, local-bounds and
  116. # the nullability-* group of checks.
  117. #
  118. # for now, we disable below from UBSan
  119. # -alignment
  120. # -implicit-conversion
  121. #
  122. -fsanitize=float-divide-by-zero,unsigned-integer-overflow,local-bounds,nullability
  123. -fno-sanitize=alignment
  124. )
  125. add_link_options(-fsanitize=address -fprofile-instr-generate)
  126. endif ()
  127. include(${REPO_ROOT_DIR}/core/shared/utils/uncommon/shared_uncommon.cmake)
  128. include(${REPO_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  129. add_library(vmlib
  130. ${WAMR_RUNTIME_LIB_SOURCE}
  131. )
  132. add_executable(wasm_mutator_fuzz wasm_mutator_fuzz.cc)
  133. target_link_libraries(wasm_mutator_fuzz vmlib -lm)