81 lines
3.3 KiB
CMake
81 lines
3.3 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
project(conflict_range_cpp LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
|
|
endif()
|
|
|
|
option(CR_BUILD_FUZZERS "Build libFuzzer differential/safety harnesses" ON)
|
|
option(CR_BUILD_BENCH "Build the nanobench comparison" ON)
|
|
|
|
enable_testing()
|
|
|
|
add_library(cr_literal STATIC src/literal.cpp)
|
|
target_include_directories(cr_literal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
|
|
add_library(cr_fast STATIC src/fast.cpp)
|
|
target_include_directories(cr_fast PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
|
|
# Golden-vector check: the literal translation against vectors produced by
|
|
# `lake env lean --run cpp/oracle/gen.lean`.
|
|
add_executable(golden_test tests/golden.cpp)
|
|
target_link_libraries(golden_test PRIVATE cr_literal)
|
|
|
|
# Literal vs. fast on Lean-generated cases that satisfy the readable sorting
|
|
# invariant.
|
|
add_executable(diff_corpus tests/diff_corpus.cpp)
|
|
target_link_libraries(diff_corpus PRIVATE cr_literal cr_fast)
|
|
|
|
# Regression test for offsets at the extremes of `Int`.
|
|
add_executable(extreme_test tests/extreme.cpp)
|
|
target_include_directories(extreme_test PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
target_link_libraries(extreme_test PRIVATE cr_literal cr_fast)
|
|
|
|
# Deterministic exhaustive sweep of small readable instances. This is the
|
|
# driver for the line-coverage check in `run-coverage.sh`.
|
|
add_executable(exhaustive_test tests/exhaustive.cpp)
|
|
target_include_directories(exhaustive_test PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
target_link_libraries(exhaustive_test PRIVATE cr_literal cr_fast)
|
|
|
|
set(CR_GOLDEN_VECTORS "${CMAKE_CURRENT_SOURCE_DIR}/oracle/golden.txt")
|
|
add_test(NAME golden COMMAND golden_test "${CR_GOLDEN_VECTORS}")
|
|
add_test(NAME diff_corpus COMMAND diff_corpus "${CR_GOLDEN_VECTORS}")
|
|
add_test(NAME extreme COMMAND extreme_test)
|
|
add_test(NAME exhaustive COMMAND exhaustive_test)
|
|
|
|
if(CR_BUILD_BENCH)
|
|
add_executable(cr_bench tests/bench.cpp)
|
|
target_include_directories(cr_bench PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/third_party
|
|
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
target_link_libraries(cr_bench PRIVATE cr_literal cr_fast)
|
|
target_compile_definitions(cr_bench PRIVATE NDEBUG)
|
|
endif()
|
|
|
|
if(CR_BUILD_FUZZERS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
set(CR_FUZZ_FLAGS -fsanitize=fuzzer,address,undefined
|
|
-fno-sanitize-recover=all -g -O1)
|
|
|
|
# Compile the implementations into each fuzz target directly, so that the
|
|
# library code itself is instrumented (linking a plain static library would
|
|
# only instrument the harness).
|
|
add_executable(fuzz_readable tests/fuzz_readable.cpp src/literal.cpp
|
|
src/fast.cpp)
|
|
target_include_directories(fuzz_readable PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
target_compile_options(fuzz_readable PRIVATE ${CR_FUZZ_FLAGS})
|
|
target_link_options(fuzz_readable PRIVATE -fsanitize=fuzzer,address,undefined)
|
|
|
|
add_executable(fuzz_raw tests/fuzz_raw.cpp src/literal.cpp src/fast.cpp)
|
|
target_include_directories(fuzz_raw PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
target_compile_options(fuzz_raw PRIVATE ${CR_FUZZ_FLAGS})
|
|
target_link_options(fuzz_raw PRIVATE -fsanitize=fuzzer,address,undefined)
|
|
endif()
|