Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
48 lines (48 loc) · 2.56 KB
/
Copy pathCMakeLists.txt
File metadata and controls
48 lines (48 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
cmake_minimum_required(VERSION 3.25)
project(tcpbench LANGUAGES CXX)
if(NOT WIN32 OR NOT MSVC)
message(FATAL_ERROR "This benchmark requires Windows and an MSVC-compatible x64 compiler")
endif()
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(BENCH_ASAN "Diagnostic AddressSanitizer build (never performance results)" OFF)
# Instruction set for the whole program, including simdjson's compile-time On-Demand kernel.
set(BENCH_ARCH "" CACHE STRING "MSVC /arch value (empty, AVX2 or AVX512)")
foreach(file IN ITEMS simdjson.h simdjson.cpp)
file(SHA256 "${CMAKE_CURRENT_SOURCE_DIR}/vendor/${file}" actual)
if(file STREQUAL "simdjson.h")
set(expected d930dbc24ecba8fb7fcba534e1932375964bb2fab82a396d3b810b42968c1863)
else()
set(expected 17a1e9b70a8cc0a5be3b3e95ddb26838bcebdc8bb6cb93980a9628b065cbaf72)
endif()
if(NOT actual STREQUAL expected)
message(FATAL_ERROR "Pinned simdjson v3.12.3 ${file} hash mismatch")
endif()
endforeach()
add_library(simdjson STATIC vendor/simdjson.cpp)
target_include_directories(simdjson SYSTEM PUBLIC vendor)
add_executable(tcpbench main.cpp processing.cpp fastjson.cpp selftest_fuzz.cpp server.cpp client.cpp)
if(BENCH_ARCH)
target_compile_options(tcpbench PRIVATE /arch:${BENCH_ARCH})
target_compile_options(simdjson PRIVATE /arch:${BENCH_ARCH})
endif()
target_compile_definitions(tcpbench PRIVATE BENCH_ARCH_FLAG="${BENCH_ARCH}")
target_link_libraries(tcpbench PRIVATE simdjson ws2_32 psapi)
target_compile_definitions(tcpbench PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX _WIN32_WINNT=0x0A00 _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(tcpbench PRIVATE BENCH_CONFIG="$<CONFIG>" BENCH_WINDOWS_SDK="${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
target_compile_options(tcpbench PRIVATE /W4 /EHsc /utf-8 /permissive- /Zc:__cplusplus)
# No /GL or /LTCG: measured about 30% slower JSON processing with simdjson on MSVC 19.51.
if(BENCH_ASAN)
target_compile_options(tcpbench PRIVATE /fsanitize=address /Zi)
target_compile_options(simdjson PRIVATE /fsanitize=address /Zi)
target_link_options(tcpbench PRIVATE /INCREMENTAL:NO /DEBUG)
target_compile_definitions(tcpbench PRIVATE BENCH_ASAN=1)
get_filename_component(compiler_dir "${CMAKE_CXX_COMPILER}" DIRECTORY)
if(EXISTS "${compiler_dir}/clang_rt.asan_dynamic-x86_64.dll")
add_custom_command(TARGET tcpbench POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${compiler_dir}/clang_rt.asan_dynamic-x86_64.dll" "$<TARGET_FILE_DIR:tcpbench>")
endif()
endif()
enable_testing()
add_test(NAME native_selftest COMMAND tcpbench selftest)