-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
223 lines (211 loc) · 4.79 KB
/
CMakeLists.txt
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
cmake_minimum_required(VERSION 3.21)
project(vash
VERSION 0.1
LANGUAGES CXX
)
include(CheckCXXCompilerFlag)
set(CMAKE_CXX_EXTENSIONS OFF)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
# Adding a Profile build type
get_property(isMultiConfig GLOBAL
PROPERTY GENERATOR_IS_MULTICONFIG
)
if(isMultiConfig)
if(NOT "Profile" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Profile)
endif()
if(NOT "Test" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Test)
endif()
else()
set(allowedBuildTypes Debug Release Profile Test)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "${allowedBuildTypes}"
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE) # default build type is Release
elseif(NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR
"Unknown build type ${CMAKE_BUILD_TYPE}"
)
endif()
endif()
#
# Set warnings
#
set(CLANG_WARNINGS
-Wall
-Wextra
-Wconversion
-Wpedantic
-Wshadow
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Woverloaded-virtual
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
-Wimplicit-fallthrough
)
set(GCC_WARNINGS
${CLANG_WARNINGS}
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
)
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PROJECT_WARNINGS_CXX ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PROJECT_WARNINGS_CXX ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for CXX compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
Include(FetchContent)
set (FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
brutilities
GIT_REPOSITORY https://github.com/tonymugen/bayesicUtilities
GIT_TAG main
GIT_PROGRESS TRUE
SYSTEM # to disable warnings
)
FetchContent_MakeAvailable(brutilities)
#
# Tests with Catch2
#
option(BUILD_TESTS
"Build tests"
OFF
)
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2 # or a later release
GIT_PROGRESS TRUE
SYSTEM # to disable Catch2 warnings
)
FetchContent_MakeAvailable(Catch2)
endif()
#
# Documentation
#
option(BUILD_DOCS
"Build docs"
OFF
)
if(PROJECT_IS_TOP_LEVEL AND BUILD_DOCS)
add_subdirectory(docs)
endif()
#
# Find active available sanitizers
#
set(SANITIZER_LIST "")
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(SANITIZERS "")
check_cxx_compiler_flag(-fsanitize=address HAS_ADDRESS_SANITIZER)
check_cxx_compiler_flag(-fsanitize=leak HAS_LEAK_SANITIZER)
#check_cxx_compiler_flag(-fsanitize=undefined HAS_UNDEFINED_SANITIZER)
if(${HAS_ADDRESS_SANITIZER})
list(APPEND SANITIZERS "address")
endif()
if(${HAS_LEAK_SANITIZER})
list(APPEND SANITIZERS "leak")
endif()
# weird linking errors wiht UBSAN
#if(${HAS_UNDEFINED_SANITIZER})
# list(APPEND SANITIZERS "undefined")
#endif()
list(JOIN
SANITIZERS
","
SANITIZER_LIST)
endif()
set(CMAKE_CXX_FLAGS_RELEASE
"-O3 -DNDEBUG"
)
set(CMAKE_CXX_FLAGS_PROFILE
"-g -p -O3 -DNDEBUG"
)
set(CMAKE_CXX_FLAGS_DEBUG
"-g -O1"
)
set(CMAKE_CXX_FLAGS_TEST
"-g -O3"
)
include(GNUInstallDirs)
# executable
add_executable(ldblocks
${CMAKE_CURRENT_LIST_DIR}/apps/ldblocks.cpp
)
target_include_directories(ldblocks
PRIVATE ${brutilities_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include
)
target_link_libraries(ldblocks
PRIVATE vash
)
target_compile_options(ldblocks
PRIVATE ${PROJECT_WARNINGS_CXX}
)
if(BUILD_TESTS)
target_compile_options(ldblocks
PRIVATE -fsanitize=${SANITIZER_LIST}
)
endif()
set_target_properties(ldblocks PROPERTIES
CXX_STANDARD_REQUIRED ON
)
install(TARGETS ldblocks
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# library
add_library(vash
${CMAKE_CURRENT_LIST_DIR}/src/gvarHash.cpp
${CMAKE_CURRENT_LIST_DIR}/src/vashFunctions.cpp
${CMAKE_CURRENT_LIST_DIR}/src/similarityMatrix.cpp
${brutilities_SOURCE_DIR}/src/random.cpp
)
target_include_directories(vash
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include
PRIVATE ${brutilities_SOURCE_DIR}/include
)
set_target_properties(vash PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD_REQUIRED ON
)
target_compile_options(vash
PRIVATE ${PROJECT_WARNINGS_CXX} -mbmi -mbmi2 -mpopcnt -lpthread
)
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTS)
target_compile_options(vash
PRIVATE -fsanitize=${SANITIZER_LIST}
)
endif()
# no install for now
# tests
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTS)
add_executable(tests
tests/tests.cpp
)
target_link_libraries(tests
PRIVATE vash
PRIVATE Catch2::Catch2WithMain
)
target_include_directories(tests
PRIVATE include
PRIVATE ${brutilities_SOURCE_DIR}/include
)
target_compile_options(tests
PRIVATE -mpopcnt
)
include(CTest)
include(Catch)
catch_discover_tests(tests)
endif()