-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
124 lines (103 loc) · 4.28 KB
/
Copy pathCMakeLists.txt
File metadata and controls
124 lines (103 loc) · 4.28 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
cmake_minimum_required(VERSION 3.21)
project(bitvector)
set(CMAKE_CXX_STANDARD 17)
# Allow configuring how long tests may run and how long benchmarks
# should execute. The timeout for GoogleTest-based unit tests is set via
# `BITVECTOR_TEST_TIMEOUT`. The minimum runtime for Google Benchmark
# benchmarks is configured with `BITVECTOR_BENCHMARK_MIN_TIME`.
set(BITVECTOR_TEST_TIMEOUT 10 CACHE STRING "Timeout in seconds for each unit test")
set(BITVECTOR_BENCHMARK_MIN_TIME 0.5 CACHE STRING "Minimum time in seconds for benchmark runs")
option(BITVECTOR_NO_BOUND_CHECK "Disable bounds checking in bitvector" ON)
if(BITVECTOR_NO_BOUND_CHECK)
add_compile_definitions(BITVECTOR_NO_BOUND_CHECK)
endif()
if(MSVC)
# Set compiler flags for all configurations
#add_compile_options("/O2" "/Zi" "/DEBUG")
# Or, specify flags based on the build type
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Zi /DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi /DEBUG")
endif()
# Optionally enable AVX-512 instructions. Most CI runners do not support
# AVX-512, so leave it disabled by default to avoid illegal instruction
# failures at runtime.
option(ENABLE_AVX512 "Enable AVX-512 instructions" OFF)
if(ENABLE_AVX512)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-mavx512f)
elseif(MSVC)
message(WARNING "AVX-512 support is not available for MSVC in this configuration.")
endif()
endif()
# Enable BMI1 support
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-mbmi)
elseif(MSVC)
message(WARNING "BMI1 support is not available for MSVC in this configuration.")
endif()
# Detect AVX2 or native CPU optimizations and enable them if available
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
add_compile_options(-march=native)
else()
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
add_compile_options(-mavx2)
endif()
endif()
elseif(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
add_compile_options(/arch:AVX2)
endif()
endif()
# Optionally disable bounds checking in the bitvector implementation
# Enable testing
enable_testing()
# FetchContent for Google Test (GTest)
include(FetchContent)
FetchContent_Declare(
gtest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0 # or use 'master' for latest version
)
FetchContent_Declare(
simde
GIT_REPOSITORY https://github.com/simd-everywhere/simde.git
GIT_TAG master
)
FetchContent_MakeAvailable(simde)
include_directories(${simde_SOURCE_DIR})
add_compile_definitions(SIMDE_ENABLE_NATIVE_ALIASES)
# Google Benchmark
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.3
)
set(BENCHMARK_ENABLE_TESTING OFF)
FetchContent_MakeAvailable(benchmark)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Download and build Google Test
FetchContent_MakeAvailable(gtest)
add_executable(bitvector main.cpp)
# Unit tests
add_executable(bitvector_tests bitvector_test.cpp)
target_link_libraries(bitvector_tests GTest::gtest_main)
# Benchmark target
add_executable(bitvector_benchmark bitvector_benchmark.cpp)
target_link_libraries(bitvector_benchmark benchmark::benchmark)
target_compile_definitions(bitvector_benchmark PRIVATE BITVECTOR_BENCHMARK_MIN_TIME=${BITVECTOR_BENCHMARK_MIN_TIME})
# Link your project with Google Test (only for test purposes)
#add_executable(PrimeIteratorTests test_prime_iterator.cpp)
# Link the Google Test libraries with your test executable
#target_link_libraries(PrimeIteratorTests GTest::gtest_main)
# Optionally: Add your own project dependencies or source files
# target_sources(MyProjectTests PRIVATE test_main.cpp)
# Enable test discovery
include(GoogleTest)
gtest_discover_tests(bitvector_tests PROPERTIES TIMEOUT ${BITVECTOR_TEST_TIMEOUT})