diff options
-rw-r--r-- | CMakeLists.txt | 28 | ||||
-rw-r--r-- | Makefile | 10 |
2 files changed, 29 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 729e7282..49ef1a7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,14 @@ cmake_minimum_required(VERSION 2.6) project(SEXPR_WASM) +option(BUILD_TESTS "Build GTest-based tests" ON) +option(RUN_BISON "Run bison" ON) +option(RUN_RE2C "Run re2c" ON) +option(USE_ASAN "Use address sanitizer" OFF) +option(USE_MSAN "Use memory sanitizer" OFF) +option(USE_LSAN "Use leak sanitizer" OFF) +option(USE_UBSAN "Use undefined behavior sanitizer" OFF) + if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang") set(COMPILER_IS_CLANG 1) set(COMPILER_IS_GNU 0) @@ -126,7 +134,23 @@ else () endif () endif () -option(RUN_BISON "run bison" ON) +set(USE_SANITIZER FALSE) +function(SANITIZER NAME FLAGS) + if (${NAME}) + message("HERE ${NAME} ${FLAGS}") + if (USE_SANITIZER) + message(FATAL_ERROR "Only one sanitizer allowed") + endif() + set(USE_SANITIZER TRUE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}" PARENT_SCOPE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}" PARENT_SCOPE) + endif () +endfunction() +SANITIZER(USE_ASAN "-fsanitize=address") +SANITIZER(USE_MSAN "-fsanitize=memory") +SANITIZER(USE_LSAN "-fsanitize=leak") +SANITIZER(USE_UBSAN "-fsanitize=undefined -fno-sanitize-recover") + find_package(BISON 3.0) if (RUN_BISON AND BISON_FOUND) set(WASM_AST_PARSER_GEN_C ${SEXPR_WASM_BINARY_DIR}/wasm-ast-parser-gen.c) @@ -151,7 +175,6 @@ endif () set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SEXPR_WASM_SOURCE_DIR}/third_party/CMakeXFind) -option(RUN_RE2C "run re2c" ON) find_package(RE2C 0.13) if (RUN_RE2C AND RE2C_EXECUTABLE) set(WASM_AST_LEXER_C ${SEXPR_WASM_SOURCE_DIR}/src/wasm-ast-lexer.c) @@ -314,7 +337,6 @@ endif () # hexfloat-test -option(BUILD_TESTS "Build GTest-based tests" ON) find_package(Threads) if (BUILD_TESTS AND CMAKE_USE_PTHREADS_INIT) if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gtest/googletest) @@ -34,8 +34,6 @@ SANITIZERS := ASAN MSAN LSAN UBSAN CONFIGS := NORMAL $(SANITIZERS) NO_RE2C_BISON NO_TESTS EXECUTABLES := sexpr-wasm wasm-wast wasm-interp wasm-interp-sq hexfloat_test -UBSAN_C_FLAGS := -fsanitize=undefined -fno-sanitize-recover - # directory names GCC_DIR := gcc/ GCC_I686_DIR := gcc-i686/ @@ -62,10 +60,10 @@ EMSCRIPTEN_FLAG := -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN_DIR}/cmake/Modules/Platfo DEBUG_FLAG := -DCMAKE_BUILD_TYPE=Debug RELEASE_FLAG := -DCMAKE_BUILD_TYPE=Release NORMAL_FLAG := -ASAN_FLAG := -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address -MSAN_FLAG := -DCMAKE_C_FLAGS=-fsanitize=memory -DCMAKE_CXX_FLAGS=-fsanitize=memory -LSAN_FLAG := -DCMAKE_C_FLAGS=-fsanitize=leak -DCMAKE_CXX_FLAGS=-fsanitize=leak -UBSAN_FLAG := -DCMAKE_C_FLAGS="${UBSAN_C_FLAGS}" -DCMAKE_CXX_FLAGS="${UBSAN_C_FLAGS}" +ASAN_FLAG := -DUSE_ASAN=ON +MSAN_FLAG := -DUSE_MSAN=ON +LSAN_FLAG := -DUSE_LSAN=ON +UBSAN_FLAG := -DUSE_UBSAN=ON NO_RE2C_BISON_FLAG := -DRUN_BISON=OFF -DRUN_RE2C=OFF NO_TESTS_FLAG := -DBUILD_TESTS=OFF |