1cmake_minimum_required(VERSION 3.11) 2project(JSON_Benchmarks LANGUAGES CXX) 3 4# set compiler flags 5if((CMAKE_CXX_COMPILER_ID MATCHES GNU) OR (CMAKE_CXX_COMPILER_ID MATCHES Clang)) 6 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -DNDEBUG -O3") 7endif() 8 9# configure Google Benchmarks 10include(FetchContent) 11FetchContent_Declare( 12 benchmark 13 GIT_REPOSITORY https://github.com/google/benchmark.git 14 GIT_TAG origin/main 15 GIT_SHALLOW TRUE 16) 17 18FetchContent_GetProperties(benchmark) 19if(NOT benchmark_POPULATED) 20 FetchContent_Populate(benchmark) 21 set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "" FORCE) 22 add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR}) 23endif() 24 25# download test data 26set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake ${CMAKE_MODULE_PATH}) 27include(download_test_data) 28 29# benchmark binary 30add_executable(json_benchmarks src/benchmarks.cpp) 31target_compile_features(json_benchmarks PRIVATE cxx_std_11) 32target_link_libraries(json_benchmarks benchmark ${CMAKE_THREAD_LIBS_INIT}) 33add_dependencies(json_benchmarks download_test_data) 34target_include_directories(json_benchmarks PRIVATE ${CMAKE_SOURCE_DIR}/../../single_include ${CMAKE_BINARY_DIR}/include) 35