-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
262 lines (243 loc) · 9.39 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
cmake_minimum_required (VERSION 3.11)
project (mGEMS)
include(FetchContent)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
## Determine build type and set flags accordingly
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) ## Build Release by default
elseif(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpedantic")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -Wall -Wextra -Wpedantic")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g -Wall -Wextra -Wpedantic")
endif()
## Set C++17 support depending on cmake version
if (${CMAKE_MAJOR_VERSION} GREATER 2 AND ${CMAKE_MINOR_VERSION} GREATER 0)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
else()
add_compile_options(-std=c++17)
endif()
## mGEMS executable
add_executable(mGEMS ${CMAKE_CURRENT_SOURCE_DIR}/src/mGEMS.cpp)
## mGEMS library
add_library(libmgems
${CMAKE_CURRENT_SOURCE_DIR}/src/bin_reads.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/extract_bin.cpp
)
set_target_properties(libmgems PROPERTIES OUTPUT_NAME mgems)
## Dependencies
### OpenMP
## Check dependencies
find_package(OpenMP)
if (OPENMP_FOUND)
set(MGEMS_OPENMP_SUPPORT 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_PARALLEL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -D_GLIBCXX_PARALLEL")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -D_GLIBCXX_PARALLEL")
else()
set(MGEMS_OPENMP_SUPPORT 0)
endif()
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
## Configure OpenMP if it supported on the system.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/mGEMS_openmp_config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/mGEMS_openmp_config.hpp @ONLY)
### Check supported compression types
#### zlib
if ((DEFINED ZLIB_LIBRARY AND DEFINED ZLIB_INCLUDE_DIR) AND (NOT DEFINED ZLIB_FOUND))
message(STATUS "zlib library provided in: " ${ZLIB_LIBRARY})
message(STATUS "zlib headers provided in: " ${ZLIB_INCLUDE_DIR})
include_directories(${ZLIB_INCLUDE_DIR})
target_link_libraries(mGEMS ${ZLIB_LIBRARY})
target_link_libraries(libmgems ${ZLIB_LIBRARY})
set(MGEMS_HAVE_ZLIB 1)
else()
find_package(ZLIB)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIR})
target_link_libraries(mGEMS ${ZLIB_LIBRARY})
target_link_libraries(libmgems ${ZLIB_LIBRARY})
set(MGEMS_HAVE_ZLIB 1)
else()
set(MGEMS_HAVE_ZLIB 0)
endif()
endif()
#### bzip2
if (DEFINED BZIP2_LIBRARIES AND DEFINED BZIP2_INCLUDE_DIR AND (NOT DEFINED BZIP2_FOUND))
message(STATUS "bzip2 library provided in: " ${BZIP2_LIBRARIES})
message(STATUS "bzip2 headers provided in: " ${BZIP2_INCLUDE_DIR})
include_directories(${BZIP2_INCLUDE_DIR})
target_link_libraries(mGEMS ${BZIP2_LIBRARIES})
target_link_libraries(libmgems ${BZIP2_LIBRARIES})
set(MGEMS_HAVE_BZIP2 1)
else()
find_package(BZip2)
if (BZIP2_FOUND)
include_directories(${BZIP2_INCLUDE_DIR})
target_link_libraries(mGEMS ${BZIP2_LIBRARIES})
target_link_libraries(libmgems ${BZIP2_LIBRARIES})
set(MGEMS_HAVE_BZIP2 1)
else()
set(MGEMS_HAVE_BZIP2 0)
endif()
endif()
#### lzma
if (DEFINED LIBLZMA_LIBRARY AND DEFINED LIBLZMA_INCLUDE_DIR AND (NOT DEFINED LIBLZMA_FOUND))
message(STATUS "liblzma library provided in: " ${LIBLZMA_LIBRARY})
message(STATUS "liblzma headers provided in: " ${LIBLZMA_INCLUDE_DIR})
include_directories(${LIBLZMA_INCLUDE_DIR})
target_link_libraries(mGEMS ${LIBLZMA_LIBRARY})
target_link_libraries(libmgems ${LIBLZMA_LIBRARY})
set(MGEMS_HAVE_LIBLZMA 1)
else()
find_package(LibLZMA)
if (LIBLZMA_FOUND)
include_directories(${LIBLZMA_INCLUDE_DIR})
target_link_libraries(mGEMS ${LIBLZMA_LIBRARY})
target_link_libraries(libmgems ${LIBLZMA_LIBRARY})
set(MGEMS_HAVE_LIBLZMA 1)
else()
set(MGEMS_HAVE_LIBLZMA 0)
endif()
endif()
## bxzstr
if (DEFINED CMAKE_BXZSTR_HEADERS)
message(STATUS "bxzstr headers provided in: ${CMAKE_BXZSTR_HEADERS}")
else()
FetchContent_Declare(bxzstr
GIT_REPOSITORY https://github.com/tmaklin/bxzstr.git
GIT_TAG v1.1.0
PREFIX "external"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/bxzstr"
BUILD_IN_SOURCE 0
CMAKE_ARGS -D ZSTD_FOUND=0
-D ZLIB_FOUND=${MGEMS_HAVE_ZLIB}
-D BZIP2_FOUND=${MGEMS_HAVE_BZIP2}
-D LIBLZMA_FOUND=${MGEMS_HAVE_LIBLZMA}
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
)
FetchContent_MakeAvailable(bxzstr)
set(CMAKE_BXZSTR_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/bxzstr/include)
endif()
include_directories(${CMAKE_BXZSTR_HEADERS})
## cxxargs
if (DEFINED CMAKE_CXXARGS_HEADERS)
message(STATUS "cxxargs headers provided in: ${CMAKE_CXXARGS_HEADERS}")
else()
FetchContent_Declare(cxxargs
GIT_REPOSITORY https://github.com/tmaklin/cxxargs.git
GIT_TAG v1.1.4
PREFIX "external"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/cxxargs"
BUILD_IN_SOURCE 0
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
)
FetchContent_MakeAvailable(cxxargs)
set(CMAKE_CXXARGS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/cxxargs/include)
endif()
include_directories("${CMAKE_CXXARGS_HEADERS}")
## Check dependencies and download them if not given
## cxxio
if (DEFINED CMAKE_CXXIO_HEADERS)
message(STATUS "cxxio headers provided in: ${CMAKE_CXXIO_HEADERS}")
else()
FetchContent_Declare(cxxio
GIT_REPOSITORY https://github.com/tmaklin/cxxio.git
GIT_TAG v0.1.0
PREFIX "external"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/cxxio"
BUILD_IN_SOURCE 0
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
)
FetchContent_MakeAvailable(cxxio)
set(CMAKE_CXXIO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/cxxio/include)
endif()
include_directories("${CMAKE_CXXIO_HEADERS}")
## alignment-writer
if (DEFINED CMAKE_ALIGNMENT_WRITER_HEADERS AND DEFINED CMAKE_ALIGNMENT_WRITER_LIBRARY)
message(STATUS "alignment-writer headers provided in: ${CMAKE_ALIGNMENT_WRITER_HEADERS}")
message(STATUS "alignment-writer library provided in: ${CMAKE_ALIGNMENT_WRITER_LIBRARY}")
else()
FetchContent_Declare(alignment-writer
GIT_REPOSITORY https://github.com/tmaklin/alignment-writer.git
GIT_TAG v0.5.0
PREFIX "external"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/alignment-writer"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/alignment-writer"
BUILD_IN_SOURCE 0
CMAKE_ARGS -D CMAKE_BXZSTR_HEADERS=${CMAKE_BXZSTR_HEADERS}
-D CMAKE_CXXARGS_HEADERS=${CMAKE_CXXARGS_HEADERS}
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D "CMAKE_C_FLAGS=${CMAKE_C_FLAGS}"
-D "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
-D "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
-D "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
INSTALL_COMMAND ""
)
FetchContent_MakeAvailable(alignment-writer)
add_dependencies(mGEMS libalignmentwriter)
set_target_properties(alignment-writer PROPERTIES EXCLUDE_FROM_ALL 1)
set(CMAKE_ALIGNMENT_WRITER_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/alignment-writer/include)
set(CMAKE_ALIGNMENT_WRITER_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/lib/libalignment-writer.a)
set(CMAKE_BITMAGIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/alignment-writer/external/BitMagic-7.12.3/src)
endif()
include_directories(${CMAKE_ALIGNMENT_WRITER_HEADERS})
target_link_libraries(mGEMS ${CMAKE_ALIGNMENT_WRITER_LIBRARY})
target_link_libraries(libmgems ${CMAKE_ALIGNMENT_WRITER_LIBRARY})
## BitMagic
if (DEFINED CMAKE_BITMAGIC_HEADERS)
message(STATUS "BitMagic headers provided in: ${CMAKE_BITMAGIC_HEADERS}")
else()
message(FATAL_ERROR "Provide BitMagic C++ headers with -DCMAKE_BITMAGIC_HEADERS")
endif()
include_directories(${CMAKE_BITMAGIC_HEADERS})
## seamat
if (DEFINED CMAKE_SEAMAT_HEADERS)
message(STATUS "seamat headers provided in: ${CMAKE_SEAMAT_HEADERS}")
else()
FetchContent_Declare(seamat
GIT_REPOSITORY https://github.com/tmaklin/seamat.git
GIT_TAG v0.2.2
PREFIX "external"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/seamat"
BUILD_IN_SOURCE 0
CMAKE_ARGS -D CMAKE_BUILD_TESTS=0
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
)
FetchContent_MakeAvailable(seamat)
set(CMAKE_SEAMAT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/external/seamat/include ${CMAKE_CURRENT_BINARY_DIR}/_deps/seamat-build/include)
endif()
include_directories(${CMAKE_SEAMAT_HEADERS})
## Get version number from git tags
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY "${local_dir}"
OUTPUT_VARIABLE _BUILD_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message( STATUS "mGEMS version: ${_BUILD_VERSION}")
else()
message(STATUS "GIT not found, version numbering disabled")
set(_BUILD_VERSION "unknown")
endif()
string(TIMESTAMP _BUILD_TIMESTAMP)
## Generate a version.h file containing build version and timestamp
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/mGEMS_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mGEMS_version.h @ONLY)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
# Link libraries
if (OPENMP_FOUND)
target_link_libraries(mGEMS libmgems OpenMP::OpenMP_CXX)
else()
target_link_libraries(mGEMS libmgems)
endif()