-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
241 lines (198 loc) · 5.95 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
cmake_minimum_required(VERSION 3.21)
project(
AWFMIndex
HOMEPAGE_URL https://github.com/TravisWheelerLab/AvxWindowFmIndex
LANGUAGES C # Specify C language explicitly
)
set(CMAKE_C_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#add support for OpenMP
find_package(OpenMP REQUIRED)
if(OpenMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
#PUBLIC_H_FILES is missing divsufsort64.h, because it doesn't exist until after divsufsort is built
set(
PUBLIC_H_FILES
src/AwFmIndex.h
lib/FastaVector/src/FastaVector.h
lib/FastaVector/src/FastaVectorMetadataVector.h
lib/FastaVector/src/FastaVectorString.h
)
set(
H_FILES
src/AwFmCreate.h
src/AwFmFile.h
src/AwFmIndex.h
src/AwFmIndexStruct.h
src/AwFmKmerTable.h
src/AwFmLetter.h
src/AwFmOccurrence.h
src/AwFmParallelSearch.h
src/AwFmSearch.h
src/AwFmSimdConfig.h
src/AwFmSuffixArray.h
)
set(
C_FILES
src/AwFmCreate.c
src/AwFmFile.c
src/AwFmIndexStruct.c
src/AwFmKmerTable.c
src/AwFmLetter.c
src/AwFmOccurrence.c
src/AwFmParallelSearch.c
src/AwFmSearch.c
src/AwFmSimdConfig.c
src/AwFmSuffixArray.c
)
add_library(
awfmindex_static STATIC
${C_FILES}
)
add_library(
awfmindex SHARED
${C_FILES}
)
# Set public headers for awfmindex_static
set_target_properties(
awfmindex_static
PROPERTIES
PUBLIC_HEADER "${PUBLIC_H_FILES}"
)
# Set public headers for awfmindex
set_target_properties(
awfmindex
PROPERTIES
PUBLIC_HEADER "${PUBLIC_H_FILES}"
)
add_custom_target(
copy_headers
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/include/AWFMIndex
)
#copy the libdivsufsort and fastavector static libs to the build director
add_custom_command(
TARGET awfmindex_static
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:divsufsort64>
$<TARGET_FILE_DIR:awfmindex_static>
)
add_custom_command(
TARGET awfmindex_static
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:divsufsort64>
$<TARGET_FILE:fastavector_static>
$<TARGET_FILE_DIR:awfmindex_static>
)
# Set common compiler options
target_compile_options(
awfmindex_static
PRIVATE
-mtune=native
-march=native
-Wall
-Wextra
-O3
-fPIC
-lgomp
${OpenMP_C_FLAGS}
)
target_compile_options(
awfmindex
PRIVATE
-mtune=native
-march=native
-Wall
-Wextra
-O3
-fPIC
-lgomp
${OpenMP_C_FLAGS}
)
# Check if the target architecture is x86_64 (Intel) or aarch64 (ARM)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
# Check if the compiler supports AVX2
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-mavx2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
# Set AVX2 flags for x86_64 (Intel)
target_compile_options(awfmindex_static PRIVATE -mavx2)
target_compile_options(awfmindex PRIVATE -mavx2)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
# Set NEON flags for ARM
target_compile_options(awfmindex_static PRIVATE -march=armv8-a+simd)
target_compile_options(awfmindex PRIVATE -march=armv8-a+simd)
endif()
install(
TARGETS awfmindex awfmindex_static
)
# ------------
# Dependencies
# ------------
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
set(CMAKE_BUILD_TYPE "Release")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/)
# Custom target for building submodules
add_custom_target(build_submodule
COMMENT "Building submodules"
)
# Custom command to copy public headers after building submodules
foreach(HEADER ${PUBLIC_H_FILES})
add_custom_command(
TARGET build_submodule # Add dependency on build_submodule
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}
${CMAKE_CURRENT_BINARY_DIR}/build
)
endforeach()
add_dependencies(awfmindex_static build_submodule)
add_dependencies(awfmindex_static copy_headers)
# FastaVector
target_include_directories(
awfmindex_static PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/FastaVector/src/
)
target_include_directories(
awfmindex PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/FastaVector/src/
)
target_link_libraries(awfmindex_static PRIVATE fastavector_static)
target_link_libraries(awfmindex PRIVATE fastavector)
# libdivsufsort
target_include_directories(
awfmindex PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/libdivsufsort/include/
)
target_include_directories(
awfmindex_static PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/libdivsufsort/include/
)
target_link_libraries(awfmindex_static PRIVATE divsufsort64)
target_link_libraries(awfmindex PRIVATE divsufsort64)
# Custom target for building submodules
add_custom_target(build_divsufsort
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/lib/
COMMENT "Building submodule"
)
set_target_properties(build_divsufsort PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Custom command to move the divsufsort64.h file after the end of the build
add_custom_command(
TARGET awfmindex_static POST_BUILD # Add dependency on build_submodule
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/lib/libdivsufsort/include/divsufsort64.h
${CMAKE_CURRENT_BINARY_DIR}/build/
)
add_custom_command(
TARGET awfmindex_static POST_BUILD # Add dependency on build_submodule
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/lib/libdivsufsort/lib/build/libdivsufsort64.a
${CMAKE_CURRENT_BINARY_DIR}/build/
)
# Add a dependency on build_submodule
add_dependencies(awfmindex_static build_divsufsort)