-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
212 lines (200 loc) · 4.44 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
cmake_minimum_required(VERSION 3.21)
project(subsetfa
VERSION 0.5
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()
#
# Tests with Catch2
#
option(BUILD_TESTS
"Build tests"
OFF
)
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTS)
Include(FetchContent)
set (FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
GIT_PROGRESS TRUE
SYSTEM # to disable Catch2 warnings
)
FetchContent_MakeAvailable(Catch2)
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()
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_SHARED_LINKER_FLAGS_RELEASE
"-O3 -DNDEBUG"
)
set(CMAKE_CXX_STATIC_LINKER_FLAGS_RELEASE
"-O3 -DNDEBUG"
)
set(CMAKE_CXX_FLAGS_PROFILE
"-g -p -O3 -DNDEBUG"
)
set(CMAKE_CXX_SHARED_LINKER_FLAGS_PROFILE
"-g -p -O3 -DNDEBUG"
)
set(CMAKE_CXX_STATIC_LINKER_FLAGS_PROFILE
"-g -p -O3 -DNDEBUG"
)
set(CMAKE_CXX_FLAGS_DEBUG
"-g -O1 -fsanitize=${SANITIZER_LIST}"
)
set(CMAKE_CXX_SHARED_LINKER_FLAGS_DEBUG
"-g -O1 -fsanitize=${SANITIZER_LIST}"
)
set(CMAKE_CXX_STATIC_LINKER_FLAGS_DEBUG
"-g -O1 -fsanitize=${SANITIZER_LIST}"
)
set(CMAKE_CXX_FLAGS_TEST
"-g -O3 -fsanitize=${SANITIZER_LIST}"
)
set(CMAKE_CXX_SHARED_LINKER_FLAGS_TEST
"-g -O3 -fsanitize=${SANITIZER_LIST}"
)
set(CMAKE_CXX_STATIC_LINKER_FLAGS_TEST
"-g -O3 -fsanitize=${SANITIZER_LIST}"
)
include(GNUInstallDirs)
# executable
add_executable(subsetfa
apps/subsetfa.cpp
)
target_include_directories(subsetfa
PRIVATE include
)
target_link_libraries(subsetfa
PRIVATE fasta
)
target_compile_options(subsetfa
PRIVATE ${PROJECT_WARNINGS_CXX}
)
set_target_properties(subsetfa PROPERTIES
CXX_STANDARD_REQUIRED ON
)
install(TARGETS subsetfa
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# library
add_library(fasta
src/fastaObj.cpp
src/utilities.cpp
)
target_include_directories(fasta
PRIVATE include
)
set_target_properties(fasta PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_compile_options(fasta
PRIVATE ${PROJECT_WARNINGS_CXX}
)
set_target_properties(fasta PROPERTIES
CXX_STANDARD_REQUIRED ON
)
# no install
# tests
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTS)
add_executable(tests
tests/tests.cpp
)
target_link_libraries(tests
PRIVATE fasta
PRIVATE Catch2::Catch2WithMain
)
target_include_directories(tests
PRIVATE include
)
include(CTest)
include(Catch)
catch_discover_tests(tests)
endif()