-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
215 lines (176 loc) · 7.49 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
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.1)
# Project's name
project(xg)
# We build using c++14
set(CMAKE_CXX_STANDARD 14)
# Use all standard-compliant optimizations
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# 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)
# libhandlegraph (full build using its cmake config)
ExternalProject_Add(handlegraph
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/libhandlegraph"
CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
ExternalProject_Get_property(handlegraph INSTALL_DIR)
set(handlegraph_INCLUDE "${INSTALL_DIR}/include")
set(handlegraph_LIB "${INSTALL_DIR}/lib")
# 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")
# mmmulti (memory mapped multimap)
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")
# mio (headers used by mmmulti)
set(mio_INCLUDE "${CMAKE_SOURCE_DIR}/deps/mmmulti/deps/mio/include")
# 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}")
# 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")
# taywee's C++ args library, header only
ExternalProject_Add(tayweeargs
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/args"
UPDATE_COMMAND ""
INSTALL_COMMAND "")
ExternalProject_Get_property(tayweeargs SOURCE_DIR)
set(tayweeargs_INCLUDE "${SOURCE_DIR}")
# gfakluge (now header only)
ExternalProject_Add(gfakluge
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/gfakluge"
CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND "")
ExternalProject_Get_property(gfakluge SOURCE_DIR)
set(gfakluge_INCLUDE "${SOURCE_DIR}/src")
set(gfakluge_tinyFA_INCLUDE "${SOURCE_DIR}/src/tinyFA")
ExternalProject_Get_property(gfakluge INSTALL_DIR)
set(gfakluge_LIB "${INSTALL_DIR}/src/gfakluge")
#set(CMAKE_BUILD_TYPE Release)
add_library(xg_objs OBJECT src/xg.cpp)
add_dependencies(xg_objs handlegraph)
add_dependencies(xg_objs sdsl-lite)
add_dependencies(xg_objs mmmulti)
add_dependencies(xg_objs atomicqueue)
add_dependencies(xg_objs tayweeargs)
add_dependencies(xg_objs gfakluge)
add_dependencies(xg_objs ips4o)
set_target_properties(xg_objs PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
#set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
# The following folder will be included
include_directories("${PROJECT_SOURCE_DIR}")
# build a static library
#add_library(libxg STATIC ${CMAKE_SOURCE_DIR}/src/xg.cpp)
#add_library(libxg STATIC $<TARGET_OBJECTS:xg_objs>)
#set_target_properties(libxg PROPERTIES OUTPUT_NAME "xg")
set(xg_HEADERS
${CMAKE_SOURCE_DIR}/src/xg.hpp)
# set up our target executable and specify its dependencies and includes
#add_executable(xg
# $<TARGET_OBJECTS:xg_objs>
# ${CMAKE_SOURCE_DIR}/src/main.cpp
#)
#target_include_directories(xg PUBLIC
set(xg_INCLUDES
"${CMAKE_SOURCE_DIR}/src"
"${handlegraph_INCLUDE}"
"${sdsl-lite_INCLUDE}"
"${sdsl-lite-divsufsort_INCLUDE}"
"${tayweeargs_INCLUDE}"
"${ips4o_INCLUDE}"
"${mmmulti_INCLUDE}"
"${mio_INCLUDE}"
"${atomicqueue_INCLUDE}"
"${gfakluge_INCLUDE}"
"${gfakluge_tinyFA_INCLUDE}")
set(xg_LIBS
"${sdsl-lite_LIB}/libsdsl.a"
"${sdsl-lite-divsufsort_LIB}/libdivsufsort.a"
"${sdsl-lite-divsufsort_LIB}/libdivsufsort64.a"
"${handlegraph_LIB}/libhandlegraph.a"
"-latomic")
target_include_directories(xg_objs PUBLIC ${xg_INCLUDES})
add_executable(xg
$<TARGET_OBJECTS:xg_objs>
${CMAKE_SOURCE_DIR}/src/main.cpp)
target_link_libraries(xg ${xg_LIBS})
set_target_properties(xg PROPERTIES OUTPUT_NAME "xg")
target_include_directories(xg PUBLIC ${xg_INCLUDES})
add_library(libxg_static STATIC $<TARGET_OBJECTS:xg_objs>)
set_target_properties(libxg_static PROPERTIES OUTPUT_NAME "xg")
set_target_properties(libxg_static PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_library(libxg_shared SHARED $<TARGET_OBJECTS:xg_objs>)
set_target_properties(libxg_shared PROPERTIES OUTPUT_NAME "xg")
set_target_properties(libxg_shared PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set_target_properties(libxg_static PROPERTIES PUBLIC_HEADER "${xg_HEADERS}")
set_target_properties(libxg_shared PROPERTIES PUBLIC_HEADER "${xg_HEADERS}")
install(TARGETS xg DESTINATION bin)
install(TARGETS libxg_static ARCHIVE DESTINATION lib LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/xg)
install(TARGETS libxg_shared ARCHIVE DESTINATION lib LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/xg)
if (APPLE)
elseif (TRUE)
if (BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
endif()