|
| 1 | +cmake_minimum_required(VERSION 3.12) |
| 2 | +project(cache_patterns VERSION 1.0.0 LANGUAGES CXX) |
| 3 | + |
| 4 | +# Set C++ standard |
| 5 | +set(CMAKE_CXX_STANDARD 17) |
| 6 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 | + |
| 8 | +# Use RelWithDebInfo for debug symbols (important for CodSpeed profiling) |
| 9 | +if(NOT CMAKE_BUILD_TYPE) |
| 10 | + set(CMAKE_BUILD_TYPE RelWithDebInfo) |
| 11 | +endif() |
| 12 | + |
| 13 | +# Include FetchContent for downloading dependencies |
| 14 | +include(FetchContent) |
| 15 | + |
| 16 | +# Enable downloading dependencies for benchmark |
| 17 | +set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON) |
| 18 | + |
| 19 | +# Disable specific warnings for CodSpeed/Google Benchmark |
| 20 | +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") |
| 21 | + add_compile_options(-Wno-sign-conversion -Wno-error) |
| 22 | +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 23 | + add_compile_options(-Wno-sign-conversion -Wno-error) |
| 24 | +endif() |
| 25 | + |
| 26 | +# Fetch CodSpeed's Google Benchmark compatibility layer |
| 27 | +FetchContent_Declare( |
| 28 | + google_benchmark |
| 29 | + GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp |
| 30 | + GIT_TAG main |
| 31 | + SOURCE_SUBDIR google_benchmark |
| 32 | +) |
| 33 | + |
| 34 | +FetchContent_MakeAvailable(google_benchmark) |
| 35 | + |
| 36 | +# Create library for particle simulation code |
| 37 | +add_library(cache_patterns_lib |
| 38 | + src/aos.cpp |
| 39 | + src/soa.cpp |
| 40 | +) |
| 41 | + |
| 42 | +target_include_directories(cache_patterns_lib PUBLIC |
| 43 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 44 | +) |
| 45 | + |
| 46 | +# Create benchmark executable |
| 47 | +add_executable(particle_simulation_bench |
| 48 | + benchmarks/particle_simulation.cpp |
| 49 | +) |
| 50 | + |
| 51 | +target_link_libraries(particle_simulation_bench |
| 52 | + cache_patterns_lib |
| 53 | + benchmark::benchmark |
| 54 | +) |
| 55 | + |
| 56 | +target_include_directories(particle_simulation_bench PRIVATE |
| 57 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 58 | +) |
0 commit comments