-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
72 lines (59 loc) · 2.2 KB
/
CMakeLists.txt
File metadata and controls
72 lines (59 loc) · 2.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 3.14)
project(he_accel_extended VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Optionally enable benchmarks
option(ENABLE_BENCH "Enable benchmark targets" ON)
include(FetchContent)
# Fetch Catch2 for unit tests (only if needed)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(catch2)
# Fetch GoogleBenchmark optionally
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.7.1
)
FetchContent_MakeAvailable(benchmark)
# Main library
add_library(he_core STATIC
src/mod_arith.cpp
src/poly.cpp
src/ntt.cpp
src/ntt_simd.cpp
)
target_include_directories(he_core PUBLIC include)
target_compile_options(he_core PRIVATE -O3)
# Simple test runner (lightweight) for local quick tests
add_executable(test_runner tests/test_runner.cpp src/ntt.cpp src/mod_arith.cpp src/poly.cpp)
target_include_directories(test_runner PRIVATE include)
# Unit tests with Catch2
add_executable(unit_tests tests/test_ntt.cpp src/ntt.cpp src/mod_arith.cpp src/poly.cpp)
target_include_directories(unit_tests PRIVATE include)
target_link_libraries(unit_tests PRIVATE Catch2::Catch2WithMain)
# Simple chrono benchmark (works without GoogleBenchmark)
add_executable(bench_ntt bench/bench_ntt.cpp src/ntt.cpp src/mod_arith.cpp src/poly.cpp)
target_include_directories(bench_ntt PRIVATE include)
# GoogleBenchmark-based target (optional; requires FetchContent success)
if(ENABLE_BENCH)
add_executable(gbench_ntt bench/bench_gbench.cpp src/ntt.cpp src/mod_arith.cpp src/poly.cpp)
target_include_directories(gbench_ntt PRIVATE include)
target_link_libraries(gbench_ntt PRIVATE benchmark::benchmark)
endif()
# Install rules
install(TARGETS he_core DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
message(STATUS "CMake configuration complete")
# Optionally compile with AVX2 if available
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-mavx2" COMPILER_SUPPORTS_MAVX2)
if(COMPILER_SUPPORTS_MAVX2)
add_compile_options(-mavx2 -mfma)
endif()
endif()