-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
272 lines (243 loc) · 9.28 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.1)
# Project's name
project(seqwish)
# We build using c++14
set(CMAKE_CXX_STANDARD 14)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Release Debug Generic." FORCE)
endif()
# set(CMAKE_BUILD_TYPE Debug) -- don't uncomment this, instead run
# cmake -DCMAKE_BUILD_TYPE=Debug ..
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
if(NOT DEFINED EXTRA_FLAGS)
set(EXTRA_FLAGS "-march=native" CACHE STRING
"Extra compilation flags for C and CXX." FORCE)
endif()
if (${CMAKE_BUILD_TYPE} MATCHES Release)
set(EXTRA_FLAGS "-Ofast ${EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG") # reset CXX_FLAGS to replace -O3 with -Ofast
endif ()
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
# Debug use the defaults
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O -g -fsanitize=address")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O -g -fsanitize=address")
else()
# Use all standard-compliant optimizations - always add these:
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} ${PIC_FLAG} ${EXTRA_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} ${PIC_FLAG} ${EXTRA_FLAGS}")
endif ()
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # untested
# assumes clang build
# we can't reliably detect when we're using clang, so for the time being we assume
# TODO: can't we though?
# adapted from https://stackoverflow.com/questions/46414660/macos-cmake-and-openmp
# find_package(OpenMP) does not work reliably on macOS, so we do its work ourselves
set (OpenMP_C "${CMAKE_C_COMPILER}")
set (OpenMP_C_FLAGS " -Xpreprocessor -fopenmp -I/opt/local/include/libomp -I/usr/local/include -L/opt/local/lib/libomp -L/usr/local/lib")
set (OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
set (OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set (OpenMP_CXX_FLAGS " -Xpreprocessor -fopenmp -I/opt/local/include/libomp -I/usr/local/include -L/opt/local/lib/libomp -L/usr/local/lib")
set (OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
set (OpenMP_libomp_LIBRARY "omp")
set (OpenMP_libgomp_LIBRARY "gomp")
set (OpenMP_libiomp5_LIBRARY "iomp5")
# and now add the OpenMP parameters to the compile flags
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS} -lomp")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_package(OpenMP REQUIRED)
# add the flags it detects to the compile flags
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -fopenmp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -fopenmp")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
# The following folder will be included
include_directories("${PROJECT_SOURCE_DIR}")
# Add external projects
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
# sdsl-lite (full build using its cmake config)
ExternalProject_Add(sdsl-lite
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/sdsl-lite"
CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
UPDATE_COMMAND ""
INSTALL_COMMAND "")
ExternalProject_Get_property(sdsl-lite INSTALL_DIR)
set(sdsl-lite_INCLUDE "${INSTALL_DIR}/src/sdsl-lite-build/include")
set(sdsl-lite-divsufsort_INCLUDE "${INSTALL_DIR}/src/sdsl-lite-build/external/libdivsufsort/include")
set(sdsl-lite_LIB "${INSTALL_DIR}/src/sdsl-lite-build/lib")
set(sdsl-lite-divsufsort_LIB "${INSTALL_DIR}/src/sdsl-lite-build/external/libdivsufsort/lib")
# taywee's C++ args library, header only
ExternalProject_Add(tayweeargs
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/args"
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(tayweeargs SOURCE_DIR)
set(tayweeargs_INCLUDE "${SOURCE_DIR}")
# gzip file reader, header only
ExternalProject_Add(gzipreader
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/gzip_reader"
UPDATE_COMMAND ""
INSTALL_COMMAND "")
ExternalProject_Get_property(gzipreader SOURCE_DIR)
set(gzipreader_INCLUDE "${SOURCE_DIR}")
# mmmulti (memory mapped multimap, multiset, and interval tree)
ExternalProject_Add(mmmulti
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/mmmulti"
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(mmmulti SOURCE_DIR)
set(mmmulti_INCLUDE "${SOURCE_DIR}/src")
# iitii, like cgranges but with interpolation and memory mapping
ExternalProject_Add(iitii
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/iitii"
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(iitii SOURCE_DIR)
set(iitii_INCLUDE "${SOURCE_DIR}/src")
# In-place Parallel Super Scalar Samplesort (IPS⁴o), header only
ExternalProject_Add(ips4o
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/ips4o"
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(ips4o SOURCE_DIR)
set(ips4o_INCLUDE "${SOURCE_DIR}")
# BBHash perfect hasher
ExternalProject_Add(bbhash
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/BBHash"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(bbhash SOURCE_DIR)
set(bbhash_INCLUDE "${SOURCE_DIR}")
# atomic bitvector class
ExternalProject_Add(atomicbitvector
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/atomicbitvector"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(atomicbitvector SOURCE_DIR)
set(atomicbitvector_INCLUDE "${SOURCE_DIR}/include")
# atomic queue library
ExternalProject_Add(atomicqueue
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/atomic_queue"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(atomicqueue SOURCE_DIR)
set(atomicqueue_INCLUDE "${SOURCE_DIR}/include/atomic_queue")
# ska
ExternalProject_Add(ska
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/flat_hash_map"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(ska SOURCE_DIR)
set(ska_INCLUDE "${SOURCE_DIR}")
# paryfor parallel_for
ExternalProject_Add(paryfor
#GIT_REPOSITORY "https://github.com/ekg/paryfor"
#GIT_TAG "509b28a092f732a068e2908bb9e359a8562cd32f"
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/paryfor"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(paryfor SOURCE_DIR)
set(paryfor_INCLUDE "${SOURCE_DIR}")
#add_subdirectory(deps/mmmulti/deps/mio)
ExternalProject_Add(mio
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/mmmulti/deps/mio"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(mio SOURCE_DIR)
set(mio_INCLUDE "${SOURCE_DIR}/include")
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
# set up our target executable and specify its dependencies and includes
add_executable(seqwish
${CMAKE_SOURCE_DIR}/src/utils.cpp
${CMAKE_SOURCE_DIR}/src/tempfile.cpp
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/seqindex.cpp
${CMAKE_SOURCE_DIR}/src/paf.cpp
${CMAKE_SOURCE_DIR}/src/sxs.cpp
${CMAKE_SOURCE_DIR}/src/cigar.cpp
${CMAKE_SOURCE_DIR}/src/alignments.cpp
${CMAKE_SOURCE_DIR}/src/pos.cpp
${CMAKE_SOURCE_DIR}/src/match.cpp
${CMAKE_SOURCE_DIR}/src/transclosure.cpp
${CMAKE_SOURCE_DIR}/src/links.cpp
${CMAKE_SOURCE_DIR}/src/compact.cpp
${CMAKE_SOURCE_DIR}/src/dna.cpp
${CMAKE_SOURCE_DIR}/src/gfa.cpp
${CMAKE_SOURCE_DIR}/src/vgp.cpp
${CMAKE_SOURCE_DIR}/src/exists.cpp
${CMAKE_SOURCE_DIR}/src/time.cpp
${CMAKE_SOURCE_DIR}/src/mmap.cpp
${CMAKE_SOURCE_DIR}/src/version.cpp
)
add_dependencies(seqwish tayweeargs)
add_dependencies(seqwish sdsl-lite)
add_dependencies(seqwish gzipreader)
add_dependencies(seqwish mmmulti)
add_dependencies(seqwish iitii)
add_dependencies(seqwish ips4o)
add_dependencies(seqwish bbhash)
add_dependencies(seqwish atomicbitvector)
add_dependencies(seqwish atomicqueue)
add_dependencies(seqwish ska)
add_dependencies(seqwish paryfor)
add_dependencies(seqwish mio)
target_include_directories(seqwish PUBLIC
"${sdsl-lite_INCLUDE}"
"${sdsl-lite-divsufsort_INCLUDE}"
"${tayweeargs_INCLUDE}"
"${gzipreader_INCLUDE}"
"${ips4o_INCLUDE}"
"${mmmulti_INCLUDE}"
"${iitii_INCLUDE}"
"${bbhash_INCLUDE}"
"${atomicbitvector_INCLUDE}"
"${atomicqueue_INCLUDE}"
"${ska_INCLUDE}"
"${paryfor_INCLUDE}"
"${mio_INCLUDE}")
target_link_libraries(seqwish
"${sdsl-lite_LIB}/libsdsl.a"
"${sdsl-lite-divsufsort_LIB}/libdivsufsort.a"
"${sdsl-lite-divsufsort_LIB}/libdivsufsort64.a"
"-latomic"
Threads::Threads
jemalloc
z)
if (BUILD_STATIC)
#set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
endif()
# version stuff
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/include)
execute_process(COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/generate_git_version.sh ${CMAKE_SOURCE_DIR}/include)
install(TARGETS seqwish DESTINATION bin)