-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
371 lines (324 loc) · 15.4 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#
# Kmernator/CMakeLists.txt
#
#
# Kmernator Copyright (c) 2012, The Regents of the University of California,
# through Lawrence Berkeley National Laboratory (subject to receipt of any
# required approvals from the U.S. Dept. of Energy). All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the University of California, Lawrence Berkeley
# National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# You are under no obligation whatsoever to provide any bug fixes, patches, or
# upgrades to the features, functionality or performance of the source code
# ("Enhancements") to anyone; however, if you choose to make your Enhancements
# available either publicly, or directly to Lawrence Berkeley National
# Laboratory, without imposing a separate written license agreement for such
# Enhancements, then you hereby grant the following license: a non-exclusive,
# royalty-free perpetual license to install, use, modify, prepare derivative
# works, incorporate into other computer software, distribute, and sublicense
# such enhancements or derivative works thereof, in binary and source code form.
#
set(CMAKE_USER_MAKE_RULES_OVERRIDE override.cmake)
# by default, build the RELEASE version
if(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release.")
else()
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Building the default, release version")
endif()
project( Kmernator CXX C)
set(CMAKE_SKIP_RPATH true)
cmake_minimum_required(VERSION 2.8)
enable_testing()
set(Kmernator_VERSION_MAJOR "1")
set(Kmernator_VERSION_MINOR "3")
set(Kmernator_VERSION_TAG "0")
set(Kmernator_VERSION_FILE_TEMPLATE ${CMAKE_SOURCE_DIR}/src/version.h.in)
set(Kmernator_VERSION_FILE ${CMAKE_SOURCE_DIR}/src/version.h)
set(Kmernator_GIT_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/git-version)
function(git_describe _var)
find_package(Git QUIET)
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message("Found Git version: ${out}")
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
if( EXISTS "${CMAKE_SOURCE_DIR}/.git" )
#git_describe(Kmernator_VERSION_TAG)
add_custom_target(GET_GIT_VERSION ALL
COMMAND git describe --tags > ${Kmernator_GIT_VERSION_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Retrieving git version")
# file(READ ${Kmernator_GIT_VERSION_FILE} Kmernator_VERSION_TAG)
else()
add_custom_target(GET_GIT_VERSION COMMAND /bin/true)
file(WRITE ${Kmernator_GIT_VERSION_FILE} "${Kmernator_VERSION_TAG}")
endif()
add_custom_target(REPLACE_VERSION_H ALL
COMMAND ${CMAKE_COMMAND}
-DKmernator_GIT_VERSION_FILE=${Kmernator_GIT_VERSION_FILE}
-DKmernator_VERSION_FILE_TEMPLATE=${Kmernator_VERSION_FILE_TEMPLATE}
-DKmernator_VERSION_FILE=${Kmernator_VERSION_FILE}
-DKmernator_VERSION_MAJOR=${Kmernator_VERSION_MAJOR}
-DKmernator_VERSION_MINOR=${Kmernator_VERSION_MINOR}
-DKmernator_VERSION_TAG=${Kmernator_VERSION_TAG}
-P ${CMAKE_SOURCE_DIR}/makeVersionFile.cmake
COMMENT "re-building version.h")
add_dependencies(REPLACE_VERSION_H GET_GIT_VERSION)
#configure_file(${Kmernator_VERSION_FILE_TEMPLATE} ${Kmernator_VERSION_FILE})
#set(Kmernator_VERSION "${Kmernator_VERSION_MAJOR}.${Kmernator_VERSION_MINOR}.${Kmernator_VERSION_TAG}")
#message("Building ${PROJECT_NAME} version ${Kmernator_VERSION}")
message("BuildType: ${CMAKE_BUILD_TYPE}")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BIT_CXX_FLAGS "-DIS_64_BIT")
endif()
# force static link libgcc and libstdc++, if possible
include( CheckCXXCompilerFlag )
check_cxx_compiler_flag(-static-libgcc CXX_HAS_STATIC_LIBGCC)
if (CXX_HAS_STATIC_LIBGCC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc" )
endif()
check_cxx_compiler_flag(-static-libstdc++ CXX_HAS_STATIC_LIBSTDCXX)
if (CXX_HAS_STATIC_LIBSTDCXX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++" )
endif()
#
# zlib
#
find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
include_directories(${ZLIB_INCLUDE_DIR})
#link_directories(${ZLIB_LIBRARIES})
else()
error("Can not compile without zlib")
endif()
#
# General flags
#
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${KMERNATOR_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${KMERNATOR_LINKER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KMERNATOR_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${KMERNATOR_C_FLAGS}")
#
# OpenMP
#
if(DISABLE_OPENMP)
set(OpenMP_CXX_FLAGS "-DDISABLE_OPENMP")
else()
find_package( OpenMP )
if(OPENMP_FOUND)
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -DENABLE_OPENMP")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
set(OpenMP_CXX_FLAGS "-DDISABLE_OPENMP")
endif()
endif()
#
# MPI
#
if (DISABLE_MPI)
set(KMERNATOR_MPI_CXX_FLAGS = "-DDISABLE_MPI")
else()
find_package( MPI )
if ( MPI_FOUND )
set(KMERNATOR_MPI_CXX_FLAGS "${KMERNATOR_MPI_CXX_FLAGS} ${MPI_COMPILE_FLAGS} -DENABLE_MPI")
set(KMERNATOR_MPI_LINK_FLAGS "${KMERNATOR_MPI_LINK_FLAGS} ${MPI_LINK_FLAGS}")
include_directories(${MPI_INCLUDE_PATH})
link_directories(${MPI_LINK_PATH})
set(KMERNATOR_P_LIBS boost_mpi boost_serialization ${MPI_LIBRARIES})
else()
set(DISABLE_MPI)
set(KMERNATOR_MPI_CXX_FLAGS "-DDISABLE_MPI")
endif()
endif()
# look for boost shared libs, use them if available
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_SHARED_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_SINGLETHREADED OFF)
set(BOOST_MAJOR_VER 1)
set(BOOST_MINOR_VER 53)
set(BOOST_MINOR_SUBVER 0)
find_package ( Boost ${BOOST_MAJOR_VER}.${BOOST_MINOR_VER}.${BOOST_SUBVER} COMPONENTS mpi program_options iostreams thread serialization system)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${BOOST_ROOT}/libs)
link_directories(${Boost_LIBRARY_DIRS})
else()
# if we are building our own boost, build and use static libs
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_SHARED_LIBS OFF)
set(BOOST_INSTALL_VER ${BOOST_MAJOR_VER}_${BOOST_MINOR_VER}_${BOOST_MINOR_SUBVER})
set(BOOST_FULL_VERSION ${BOOST_MAJOR_VER}.${BOOST_MINOR_VER}.${BOOST_MINOR_SUBVER})
set(BOOST_DOWNLOAD_URL http://sourceforge.net/projects/boost/files/boost/${BOOST_FULL_VERSION}/boost_${BOOST_INSTALL_VER}.tar.bz2)
set(BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/boost_${BOOST_INSTALL_VER})
if(NOT EXISTS ${BOOST_ROOT})
set(BOOST_LIBRARY_LIST iostreams,program_options,thread,test,system)
if(NOT DISABLE_MPI)
set(BOOST_LIBRARY_LIST mpi,serialization,${BOOST_LIBRARY_LIST})
endif()
set(BOOST_TBZ2 ${CMAKE_SOURCE_DIR}/opt/boost_${BOOST_INSTALL_VER}.tar.bz2)
if(NOT EXISTS ${BOOST_TBZ2})
message("Retrieving Boost from repository: ${BOOST_INSTALL_VER}")
file(DOWNLOAD ${BOOST_DOWNLOAD_URL} ${BOOST_TBZ2} STATUS DL_STATUS LOG DL_LOG)
list(GET STATUS_DL 0 STATUS_DL0)
if((NOT EXISTS ${BOOST_TBZ2}) OR (NOT STATUS_DL0 EQUAL 0))
execute_process(COMMAND wget -O ${BOOST_TBZ2} ${BOOST_DOWNLOAD_URL} RESULT_VARIABLE DL_STATUS0)
if((NOT EXISTS ${BOOST_TBZ2}) OR (NOT DL_STATUS0 EQUAL 0))
message(FATAL_ERROR "Could not download boost from ${BOOST_DOWNLOAD_URL} (${DL_STATUS0}) : ${DL_LOG}")
endif()
endif()
endif()
message("Unpacking Boost locally: ${BOOST_INSTALL_VER}")
execute_process(COMMAND tar -xjf ${BOOST_TBZ2} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not unpack boost")
endif()
if( EXISTS "$ENV{HOME}/user-config.jam")
message("renaming $ENV{HOME}/user-config.jam to $ENV{HOME}/user-config.jam-old as it will interfere with this build")
file(RENAME "$ENV{HOME}/user-config.jam" "$ENV{HOME}/user-config.jam-old")
endif()
if(NOT DISABLE_MPI)
if(NOT BOOST_MPI_USER_CONFIG)
file(APPEND ${BOOST_ROOT}/tools/build/v2/user-config.jam "using mpi ;\n")
else()
file(APPEND ${BOOST_ROOT}/tools/build/v2/user-config.jam "${BOOST_MPI_USER_CONFIG}\n")
endif()
endif()
file(APPEND ${BOOST_ROOT}/tools/build/v2/user-config.jam "using gcc : : ${CMAKE_CXX_COMPILER} ;\n")
execute_process(COMMAND ./bootstrap.sh --with-libraries=${BOOST_LIBRARY_LIST} WORKING_DIRECTORY ${BOOST_ROOT})
execute_process(COMMAND ./b2 variant=release link=static threading=multi runtime-link=static WORKING_DIRECTORY ${BOOST_ROOT})
endif()
message("Using local copy of boost: ${BOOST_ROOT}")
include_directories( ${BOOST_ROOT} )
link_directories( ${BOOST_ROOT}/stage/lib )
endif()
set(KMERNATOR_BOOST_LIBS boost_program_options
boost_iostreams
boost_thread
boost_system
)
set(KMERNATOR_BOOST_TEST_LIBS boost_test_exec_monitor
boost_unit_test_framework
)
set(SAMTOOLS_VERSION 0.1.19)
set(SAMTOOLS_DIR ${CMAKE_CURRENT_BINARY_DIR}/samtools-${SAMTOOLS_VERSION})
if(NOT EXISTS ${SAMTOOLS_DIR})
set(SAMTOOLS_TBZ2 ${CMAKE_SOURCE_DIR}/opt/samtools-${SAMTOOLS_VERSION}.tar.bz2)
if(NOT EXISTS ${SAMTOOLS_TBZ2})
set(SAMTOOLS_DOWNLOAD_URL http://sourceforge.net/projects/samtools/files/samtools/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2)
message("Retrieving samtools from repository: ${SAMTOOLS_DOWNLOAD_URL}")
file(DOWNLOAD ${SAMTOOLS_DOWNLOAD_URL} ${SAMTOOLS_TBZ2} STATUS DL_STATUS LOG DL_LOG)
list(GET STATUS_DL 0 STATUS_DL0)
if((NOT EXISTS ${SAMTOOLS_TBZ2}) OR (NOT STATUS_DL0 EQUAL 0))
execute_process(COMMAND wget -O ${SAMTOOLS_TBZ2} ${SAMTOOLS_DOWNLOAD_URL} RESULT_VARIABLE DL_STATUS0)
if((NOT EXISTS ${SAMTOOLS_TBZ2}) OR (NOT DL_STATUS0 EQUAL 0))
message(FATAL_ERROR "Could not download samtools from ${SAMTOOLS_DOWNLOAD_URL}: ${DL_LOG}")
endif()
endif()
endif()
message("Unpacking samtools: ${SAMTOOLS_VERSION}")
execute_process(COMMAND tar -xjf ${SAMTOOLS_TBZ2} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not unpack samtools")
endif()
endif()
file(COPY ${CMAKE_SOURCE_DIR}/samtools_CMakeLists.txt DESTINATION ${SAMTOOLS_DIR})
file(RENAME ${SAMTOOLS_DIR}/samtools_CMakeLists.txt ${SAMTOOLS_DIR}/CMakeLists.txt)
include_directories( ${SAMTOOLS_DIR} )
add_subdirectory( ${SAMTOOLS_DIR} binary_dir )
set(GSH_VERSION 2.0.2)
set(GSH_UNPACK_DIR ${CMAKE_CURRENT_BINARY_DIR}/sparsehash-${GSH_VERSION})
set(GSH_DIR ${CMAKE_CURRENT_BINARY_DIR}/sparsehash)
if(NOT EXISTS ${GSH_UNPACK_DIR})
set(GSH_TGZ ${CMAKE_SOURCE_DIR}/opt/sparsehash-${GSH_VERSION}.tar.gz)
if(NOT EXISTS ${GSH_TGZ})
set(GSH_DOWNLOAD_URL http://sparsehash.googlecode.com/files/sparsehash-${GSH_VERSION}.tar.gz)
message("Downloading google sparsehash: ${GSH_DOWNLOAD_URL}")
file(DOWNLOAD ${GSH_DOWNLOAD_URL} ${GSH_TGZ} STATUS DL_STATUS LOG DL_LOG)
list(GET STATUS_DL 0 STATUS_DL0)
if((NOT EXISTS ${GSH_TGZ}) OR (NOT STATUS_DL0 EQUAL 0))
execute_process(COMMAND wget -O ${GSH_TGZ} ${GSH_DOWNLOAD_URL} RESULT_VARIABLE DL_STATUS0)
if((NOT EXISTS ${GSH_TGZ}) OR (NOT DL_STATUS0 EQUAL 0))
message(FATAL_ERROR "Could not download mct from ${GSH_DOWNLOAD_URL}: ${DL_LOG}")
endif()
endif()
endif()
if(NOT EXISTS ${GSH_UNPACK_DIR})
message("Unpacking google sparse hash")
execute_process(COMMAND tar -xzf ${GSH_TGZ} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not unpack google sparsehash")
endif()
endif()
execute_process(COMMAND ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/sparsehash WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sparsehash-${GSH_VERSION} RESULT_VARIABLE SUCCESS)
execute_process(COMMAND make install WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sparsehash-${GSH_VERSION} RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not install sparsehash to ${CMAKE_CURRENT_BINARY_DIR}/sparsehash")
endif()
endif()
include_directories( ${GSH_DIR}/include )
set(MCT_VERSION1 1.6)
set(MCT_VERSION ${MCT_VERSION1}.0)
set(MCT_UNPACK_DIR ${CMAKE_CURRENT_BINARY_DIR}/mct-${MCT_VERSION})
set(MCT_DIR ${CMAKE_CURRENT_BINARY_DIR}/mct)
if(NOT EXISTS ${MCT_DIR})
set(MCT_TGZ ${CMAKE_SOURCE_DIR}/opt/mct-${MCT_VERSION}.tar.gz)
if(NOT EXISTS ${MCT_TGZ})
set(MCT_DOWNLOAD_URL http://launchpad.net/libmct/${MCT_VERSION1}/${MCT_VERSION}/+download/mct-${MCT_VERSION}.tar.gz)
message("Retrieving mct from repository: ${MCT_DOWNLOAD_URL}")
file(DOWNLOAD ${MCT_DOWNLOAD_URL} ${MCT_TGZ} STATUS DL_STATUS LOG DL_LOG)
list(GET STATUS_DL 0 STATUS_DL0)
if((NOT EXISTS ${MCT_TGZ}) OR (NOT STATUS_DL0 EQUAL 0))
execute_process(COMMAND wget -O ${MCT_TGZ} ${MCT_DOWNLOAD_URL} RESULT_VARIABLE DL_STATUS0)
if((NOT EXISTS ${MCT_TGZ}) OR (NOT DL_STATUS0 EQUAL 0))
message(FATAL_ERROR "Could not download mct from ${MCT_DOWNLOAD_URL}: ${DL_LOG}")
endif()
endif()
endif()
if(NOT EXISTS ${MCT_UNPACK_DIR})
message("Unpacking mct: ${MCT_VERSION}")
execute_process(COMMAND tar -xzf ${MCT_TGZ} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not unpack mct")
endif()
endif()
execute_process(COMMAND make install prefix=${CMAKE_CURRENT_BINARY_DIR}/mct WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mct-${MCT_VERSION} RESULT_VARIABLE SUCCESS)
if(NOT SUCCESS EQUAL 0)
message(FATAL_ERROR "Could not install mct to ${CMAKE_CURRENT_BINARY_DIR}/mct")
endif()
endif()
include_directories( ${MCT_DIR}/include )
include_directories( src )
SET(CMAKE_CXX_FLAGS "-fno-strict-aliasing ${BIT_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
add_subdirectory( src )
add_subdirectory( test )
add_subdirectory( apps )