-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (240 loc) · 8.12 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
273
274
275
276
277
project(ksburden)
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
include(ExternalProject)
# 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)
include_directories(inc)
set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
message(${LIBRARY_OUTPUT_PATH})
# ==========
# Check compiler version
# ==========
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC version must be at least 4.8!")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
message(FATAL_ERROR "Clang version must be at least 3.2!")
endif()
else()
message(WARNING "You are using an unsupported compiler!
Compilation has only been tested with Clang and GCC.")
endif()
# ================
# External projects
# ================
# gflags
ExternalProject_Add(gflagsDown
GIT_REPOSITORY https://github.com/gflags/gflags.git
PREFIX ${LIBRARY_OUTPUT_PATH}/gflags
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND export CXXFLAGS="-fPIC" && cmake .
BUILD_COMMAND make
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
set(gflags_DIR ${LIBRARY_OUTPUT_PATH}/gflags/src/gflagsDown)
add_library(gflags STATIC IMPORTED)
add_dependencies(gflags gflagsDown)
set_property(TARGET gflags PROPERTY IMPORTED_LOCATION ${gflags_DIR}/lib/libgflags.a)
include_directories(${gflags_DIR}/include/)
#============
# LIBSTATGEN
#============
ExternalProject_Add(libStatGen
GIT_REPOSITORY https://github.com/statgen/libStatGen.git
PREFIX ${LIBRARY_OUTPUT_PATH}/libStatGen
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE 1
BUILD_COMMAND make CFLAGS='-fPIC'
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
add_library(libStatGenLib STATIC IMPORTED)
set_property(TARGET libStatGenLib PROPERTY IMPORTED_LOCATION ${LIBRARY_OUTPUT_PATH}/libStatGen/src/libStatGen/libStatGen.a)
add_dependencies(libStatGenLib libStatGen)
include_directories(${LIBRARY_OUTPUT_PATH}/libStatGen/src/libStatGen/include/)
#============
# easylogging
#============
ExternalProject_Add(easylogging
PREFIX ${LIBRARY_OUTPUT_PATH}/easylogging
DOWNLOAD_COMMAND wget https://github.com/easylogging/easyloggingpp/releases/download/v9.80/easyloggingpp_v9.80.tar.gz
CONFIGURE_COMMAND tar -zxvf ../easyloggingpp_v9.80.tar.gz
BUILD_IN_SOURCE 1
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
include_directories(${LIBRARY_OUTPUT_PATH}/easylogging/src/easylogging)
#============
# OpenMP
#============
FIND_PACKAGE(OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
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}")
endif()
#========
# Boost
#========
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ROOT "/home/rmporsch/software/boost_1_62_0")
find_package(Boost REQUIRED)
include_directories( ${Boost_INCLUDE_DIRS} )
#============
# Armadillo
#============
ExternalProject_Add(ArmadilloDownload
PREFIX ${LIBRARY_OUTPUT_PATH}/armadillo-8.100.0
DOWNLOAD_COMMAND wget http://sourceforge.net/projects/arma/files/armadillo-8.100.0.tar.xz
CONFIGURE_COMMAND tar -xf ../armadillo-8.100.0.tar.xz -C ../ArmadilloDownload --strip-components=1
BUILD_IN_SOURCE 1
BUILD_COMMAND cmake .
INSTALL_COMMAND make
UPDATE_COMMAND ""
)
set(Armadillo_DIR ${LIBRARY_OUTPUT_PATH}/armadillo-8.100.0/src/ArmadilloDownload)
set(ARMADILLO_LIBRARY ${Armadillo_DIR}/libarmadillo.so)
set(ARMADILLO_INCLUDE_DIR ${Armadillo_DIR}/include/)
include_directories(${ARMADILLO_INCLUDE_DIR})
#=============================
# BLAS LAPACK
#=============================
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
#=============================
# Zlib
#=============================
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
#=============================
# Library
#=============================
# loadVariantFile
add_library(variantFile SHARED "src/loadVarinatFile.cpp")
add_dependencies(variantFile easylogging)
target_compile_features(variantFile PRIVATE cxx_range_for)
# models
add_library(models SHARED "src/models.cpp")
add_dependencies(models ArmadilloDownload easylogging)
target_compile_features(models PRIVATE cxx_range_for)
# load_vcf
add_library(loadvcf SHARED "src/load_vcf.cpp")
add_dependencies(loadvcf ArmadilloDownload libStatGen easylogging variantFile)
target_link_libraries(loadvcf libStatGenLib)
target_compile_features(loadvcf PRIVATE cxx_range_for)
# load_plink
add_library(loadplink SHARED "src/load_plink.cpp")
add_dependencies(loadplink ArmadilloDownload libStatGen easylogging variantFile)
target_compile_features(loadplink PRIVATE cxx_range_for)
# liability_model
add_library(liabilitymodel SHARED "src/liability_model.cpp")
add_dependencies(liabilitymodel ArmadilloDownload loadvcf loadplink)
target_link_libraries(liabilitymodel ${Boost_LIBRARIES} loadvcf )
target_compile_features(liabilitymodel PRIVATE cxx_range_for)
# simulation_model
add_library(simulation SHARED "src/simulation.cpp")
add_dependencies(simulation ArmadilloDownload loadvcf models liabilitymodel)
target_link_libraries(simulation loadvcf models liabilitymodel)
target_compile_features(simulation PRIVATE cxx_range_for)
# analysis
add_library(analysis SHARED "src/data_analysis.cpp")
add_dependencies(analysis ArmadilloDownload loadvcf)
target_link_libraries(analysis loadvcf)
target_compile_features(analysis PRIVATE cxx_range_for)
# sim_flags
add_library(sim_flags SHARED "src/simulation_flags.cpp")
add_dependencies(sim_flags gflags)
target_link_libraries(sim_flags gflags pthread)
target_compile_features(sim_flags PRIVATE cxx_range_for)
# see https://github.com/halide/Halide/issues/175 why I added 'pthread'
# ksburden_flags
add_library(ksburden_flags SHARED "src/flags_ksburden.cpp")
add_dependencies(ksburden_flags gflags)
target_link_libraries(ksburden_flags gflags pthread)
target_compile_features(ksburden_flags PRIVATE cxx_range_for)
# see https://github.com/halide/Halide/issues/175 why I added 'pthread'
install(TARGETS models loadvcf liabilitymodel sim_flags analysis DESTINATION lib)
#=========
# programs
#=========
# simulation program
add_executable(sim ${CMAKE_SOURCE_DIR}/src/sim.cpp)
target_link_libraries(sim
simulation
models
liabilitymodel
loadvcf
loadplink
variantFile
${ARMADILLO_LIBRARIES}
${ZLIB_LIBRARIES}
sim_flags
-O2 ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
-DEBUG
)
target_compile_features(sim PRIVATE cxx_range_for)
add_executable(sim2 ${CMAKE_SOURCE_DIR}/src/sim_2.cpp)
target_link_libraries(sim2
simulation
models
liabilitymodel
loadvcf
loadplink
variantFile
${ARMADILLO_LIBRARIES}
sim_flags
-O2 ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${ZLIB_LIBRARIES} gflags
)
target_compile_features(sim2 PRIVATE cxx_range_for)
# analysis program
add_executable(ksburden ${CMAKE_SOURCE_DIR}/src/ksburden.cpp)
target_link_libraries(ksburden
models
analysis
loadvcf
variantFile
${ARMADILLO_LIBRARIES}
ksburden_flags
-O2 ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${ZLIB_LIBRARIES} gflags
)
target_compile_features(ksburden PRIVATE cxx_range_for)
#tests
add_executable(tests ${CMAKE_SOURCE_DIR}/src/tests/run_tests.cpp)
# gflags
ExternalProject_Add(googleTest_git
GIT_REPOSITORY https://github.com/google/googletest.git
PREFIX ${LIBRARY_OUTPUT_PATH}/googletest
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_SOURCE_DIR}
UPDATE_COMMAND ""
)
ExternalProject_Get_Property(googleTest_git install_dir)
include_directories(${install_dir}/include)
set(gtest_SOURCE_DIR ${LIBRARY_OUTPUT_PATH}/googletest/src/googleTest_git/googletest)
include_directories(
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
set(gtest_main ${LIBRARY_OUTPUT_PATH}/libgtest_main.a)
set(gtest ${LIBRARY_OUTPUT_PATH}/libgtest.a)
add_dependencies(tests googleTest_git)
target_link_libraries(tests
simulation
models
analysis
liabilitymodel
loadvcf
loadplink
variantFile
${ARMADILLO_LIBRARIES}
${gtest}
-O2 ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} -DEBUG ${ZLIB_LIBRARIES}
)
target_compile_features(tests PRIVATE cxx_range_for)