-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
231 lines (204 loc) · 7.47 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
cmake_minimum_required (VERSION 3.13)
project(SBWT)
include(ExternalProject)
## Get version number from git tags
find_package(Git)
if(GIT_FOUND)
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY "${local_dir}"
OUTPUT_VARIABLE SBWT_BUILD_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "SBWT version: ${SBWT_BUILD_VERSION}")
else()
message(STATUS "GIT not found, version numbering disabled")
set(SBWT_BUILD_VERSION "unknown")
endif()
string(TIMESTAMP SBWT_BUILD_TIMESTAMP)
## Generate a version.h file containing build version and timestamp
configure_file(${PROJECT_SOURCE_DIR}/version.h.in ${PROJECT_BINARY_DIR}/include/version.h @ONLY)
## Require zlib
if(NOT ZLIB)
if(NOT CMAKE_BUILD_ZLIB)
find_library(ZLIB NAMES z REQUIRED)
endif()
if(CMAKE_BUILD_ZLIB OR ZLIB MATCHES NOTFOUND)
configure_file(CMakeLists_zlib.txt.in ${CMAKE_CURRENT_BINARY_DIR}/external/zlib-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/external/zlib-download )
if(result)
message(FATAL_ERROR "CMake step for zlib failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/zlib-download )
if(result)
message(FATAL_ERROR "Build step for zlib failed: ${result}")
endif()
set(ZLIB ${CMAKE_CURRENT_BINARY_DIR}/external/zlib/libz.a)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/zlib)
ExternalProject_Add(zlib
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/zlib"
BUILD_IN_SOURCE 1
BUILD_COMMAND $(MAKE) -f ${CMAKE_CURRENT_BINARY_DIR}/external/zlib/Makefile CFLAGS=${CMAKE_C_FLAGS} CXXFLAGS=${CMAKE_CXX_FLAGS}
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
UPDATE_COMMAND ""
)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/zlib)
endif()
endif()
## Set maximum k-mer length
if(NOT MAX_KMER_LENGTH)
set(MAX_KMER_LENGTH 32)
endif()
if(MAX_KMER_LENGTH GREATER 255)
message(${MAX_KMER_LENGTH})
message(FATAL_ERROR "Error: MAX_KMER_LENGTH can be at most 255")
endif()
add_definitions(-DMAX_KMER_LENGTH=${MAX_KMER_LENGTH}) # Define for compiler.
message(STATUS "Maximum k-mer length is: " ${MAX_KMER_LENGTH})
message(STATUS "To change the maximum k-mer length, use the option -DMAX_KMER_LENGTH=n")
message(STATUS "(n can be up to 255)")
## Determine build type and set flags accordingly
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) ## Build Release by default
endif()
if(CMAKE_BUILD_TYPE MATCHES Release)
add_compile_options(-O3)
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_options(-g -Wall -Wextra -Wno-sign-compare)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
## Require c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Fix for GCC (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90050 )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CXX_FILESYSTEM_LIBRARIES "stdc++fs")
endif()
find_package(Threads REQUIRED)
## Add local dependencies as targets
add_subdirectory(${PROJECT_SOURCE_DIR}/sdsl-lite
${PROJECT_BINARY_DIR}/external/sdsl-lite/build)
add_subdirectory(${PROJECT_SOURCE_DIR}/KMC
${PROJECT_BINARY_DIR}/external/KMC/build)
add_subdirectory(${PROJECT_SOURCE_DIR}/SeqIO
${PROJECT_BINARY_DIR}/external/SeqIO/build)
file(COPY ${PROJECT_SOURCE_DIR}/SeqIO/include/ DESTINATION ${PROJECT_BINARY_DIR}/external/SeqIO/include/)
# SeqIO is header-only so it does not need to be added
# Our sources, excluding the file with the main function
set(SBWT_SOURCES
src/globals.cpp
src/suffix_group_optimization.cpp
src/EM_sort/Block.cpp
src/EM_sort/EM_sort.cpp
src/run_kmc.cpp
src/kmc_construct_helper_classes.cpp)
add_executable(sbwt
src/CLI/sbwt.cpp
src/CLI/sbwt_build.cpp
src/CLI/sbwt_search.cpp
src/CLI/sbwt_build_from_plain_matrix.cpp
src/CLI/sbwt_ascii_export.cpp
${SBWT_SOURCES})
target_include_directories(sbwt PRIVATE
${PROJECT_SOURCE_DIR}/include/sbwt
${PROJECT_BINARY_DIR}/include # version.h is here
${PROJECT_BINARY_DIR}/external/SeqIO/include
${PROJECT_BINARY_DIR}/extenral/sdsl-lite/include
${PROJECT_BINARY_DIR}/external/sdsl-lite/build/external/libdivsufsort/include # Dependency of dependency
${PROJECT_SOURCE_DIR}/KMC)
target_link_libraries(sbwt PRIVATE
sdsl
${ZLIB}
Threads::Threads
${CXX_FILESYSTEM_LIBRARIES}
kmc_tools
kmc_core)
## Build tests if doing a Debug build
if (BUILD_TESTS)
add_subdirectory(${PROJECT_SOURCE_DIR}/googletest
${PROJECT_BINARY_DIR}/external/googletest/build)
find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(OpenMP REQUIRED)
find_library(GTEST NAMES gtest PATHS ${PROJECT_SOURCE_DIR}/external/googletest/build/lib/)
add_executable(sbwt_tests
tests/test_main.cpp
src/CLI/sbwt_build.cpp
src/CLI/sbwt_search.cpp
${SBWT_SOURCES})
target_include_directories(sbwt_tests PRIVATE
${PROJECT_SOURCE_DIR}/include/sbwt
${PROJECT_BINARY_DIR}/include # version.h is here
${PROJECT_BINARY_DIR}/external/SeqIO/include
${PROJECT_BINARY_DIR}/external/sdsl-lite/build/external/libdivsufsort/include # Dependency of dependency
${PROJECT_SOURCE_DIR}/googletest/googletest/include
${PROJECT_SOURCE_DIR}/KMC)
target_link_libraries(sbwt_tests PRIVATE
gtest
${ZLIB}
sdsl
Threads::Threads
OpenMP::OpenMP_CXX
${CXX_FILESYSTEM_LIBRARIES}
kmc_tools
kmc_core)
else()
# set_target_properties(gtest PROPERTIES EXCLUDE_FROM_ALL 1)
# set_target_properties(gtest_main PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
if (BUILD_SBWT_BENCHMARK)
find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(OpenMP REQUIRED)
add_executable(sbwt_query_benchmark
tests/query_benchmark.cpp
${SBWT_SOURCES})
target_include_directories(sbwt_query_benchmark PRIVATE
${PROJECT_SOURCE_DIR}/include/sbwt
${PROJECT_BINARY_DIR}/include # version.h is here
${PROJECT_BINARY_DIR}/external/SeqIO/include
${PROJECT_BINARY_DIR}/external/sdsl-lite/build/external/libdivsufsort/include # Dependency of dependency
${PROJECT_SOURCE_DIR}/googletest/googletest/include
${PROJECT_SOURCE_DIR}/KMC)
target_link_libraries(sbwt_query_benchmark PRIVATE
${ZLIB}
sdsl
Threads::Threads
OpenMP::OpenMP_CXX
${CXX_FILESYSTEM_LIBRARIES}
kmc_tools
kmc_core)
endif()
add_library(sbwt_static STATIC ${SBWT_SOURCES})
target_include_directories(sbwt_static PRIVATE
${PROJECT_SOURCE_DIR}/include/sbwt
${PROJECT_BINARY_DIR}/include # version.h is here
${PROJECT_BINARY_DIR}/external/SeqIO/include
${PROJECT_BINARY_DIR}/extenral/sdsl-lite/include
${PROJECT_BINARY_DIR}/external/sdsl-lite/build/external/libdivsufsort/include # Dependency of dependency
${PROJECT_SOURCE_DIR}/KMC)
target_link_libraries(sbwt_static PRIVATE
sdsl
${ZLIB}
Threads::Threads
${CXX_FILESYSTEM_LIBRARIES}
kmc_tools
kmc_core)