forked from EBIvariation/vcf-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
265 lines (234 loc) · 9.04 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
cmake_minimum_required (VERSION 2.8)
project (vcf-validator CXX C)
set (vcf-validator_VERSION_MAJOR 0)
set (vcf-validator_VERSION_MINOR 9)
set (vcf-validator_VERSION_PATCH 1)
configure_file (
"${PROJECT_SOURCE_DIR}/inc/cmake_config.hpp.in"
"${PROJECT_SOURCE_DIR}/inc/cmake_config.hpp"
)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Detect OS
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
message (STATUS "Operating system detected: Linux")
set (LINUX TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message (STATUS "Operating system detected: OSX")
set (OSX TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
message (STATUS "Operating system detected: Windows")
set (WINDOWS TRUE)
else ()
message (ERROR "Operating system not recognised. Expected Windows, Linux or Darwin, but found ${CMAKE_SYSTEM_NAME}")
endif ()
# Include directories
include_directories (inc)
include_directories (lib)
if (LINUX AND EXISTS "${PROJECT_SOURCE_DIR}/linux_dependencies")
include_directories (linux_dependencies)
set (EXT_LIB_PATH "${PROJECT_SOURCE_DIR}/linux_dependencies" CACHE STRING "Absolute path to libraries")
set (ODB_PATH "${EXT_LIB_PATH}/odb-2.4.0-x86_64-linux-gnu/bin/" CACHE STRING "Path to odb binaries")
elseif (OSX AND EXISTS "${PROJECT_SOURCE_DIR}/osx_dependencies")
include_directories (osx_dependencies)
set (EXT_LIB_PATH "${PROJECT_SOURCE_DIR}/osx_dependencies" CACHE STRING "Absolute path to libraries")
set (ODB_PATH "${EXT_LIB_PATH}/odb-2.4.0-i686-macosx/bin/" CACHE STRING "Path to odb binaries")
elseif (WINDOWS AND EXISTS "${PROJECT_SOURCE_DIR}/windows_dependencies")
include_directories (lib/sqlite) # Windows specific
include_directories (windows_dependencies)
set (EXT_LIB_PATH "${PROJECT_SOURCE_DIR}/lib/windows_specific" CACHE STRING "Absolute path to libraries")
else ()
set (EXT_LIB_PATH "/usr/local/bin" CACHE STRING "Absolute path to libraries")
if (OSX)
message(ERROR "Please run first install_dependencies.sh osx")
elseif (WINDOWS)
message(ERROR "Please run first install_dependencies.bat")
endif()
endif ()
# Compiler and linkers flags
if (LINUX)
# Static Build Extra Flags for Linux Static Build
set (BUILD_SHARED_LIBS OFF)
set (CMAKE_EXE_LINKER_FLAGS "-static")
set (CMAKE_FIND_LIBRARY_SUFFIXES .a)
set (CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
set (CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set (CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC
set (CMAKE_SHARED_LIBRARY_CXX_FLAGS)
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # remove -rdynamic
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set (Boost_USE_STATIC_LIBS ON) # only find static libs
elseif (OSX)
# Mac build not fully static. include system libraries to be dynamic
set (CMAKE_EXE_LINKER_FLAGS)
set (Boost_USE_STATIC_LIBS ON) # only find static libs
elseif (WINDOWS)
set (Boost_USE_STATIC_LIBS ON) # only find static libs
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") # also requires boost with runtime-link=static
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") # also requires boost with runtime-link=static
endif ()
# Build type
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
find_package (Threads REQUIRED)
# Flags specific to Unix
if (LINUX OR OSX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-unknown-pragmas") # no unknows pragmas warnings
set (CMAKE_C_FLAGS " -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_OMIT_LOAD_EXTENSION") # Needed to statically link ODB
find_package (Boost COMPONENTS filesystem iostreams program_options regex log thread system REQUIRED )
include_directories (${Boost_INCLUDE_DIR} )
endif ()
# Application modules
add_library (mod_sqlite3 STATIC lib/sqlite/sqlite3.c)
if (LINUX OR OSX)
set (THIRD_PARTY_LIBRARIES
${Boost_LIBRARIES}
${EXT_LIB_PATH}/libbz2.a
${EXT_LIB_PATH}/libz.a
${EXT_LIB_PATH}/libodb-sqlite.a
${EXT_LIB_PATH}/libodb.a
mod_sqlite3
${CMAKE_THREAD_LIBS_INIT}
)
elseif (WINDOWS)
set (THIRD_PARTY_LIBRARIES
${EXT_LIB_PATH}/odb-sqlite.lib
${EXT_LIB_PATH}/odb.lib
mod_sqlite3
${CMAKE_THREAD_LIBS_INIT}
)
endif ()
set (MOD_ODB_SOURCES)
set (ODB_MAPPING_CLASSES inc/vcf/error.hpp)
foreach (_file ${ODB_MAPPING_CLASSES})
string (REPLACE ".hpp" "-odb.cpp" gencppfile ${_file})
string (REPLACE "inc" "src" right_place_gencppfile ${gencppfile})
if (LINUX OR OSX)
add_custom_command (
OUTPUT ${CMAKE_HOME_DIRECTORY}/${right_place_gencppfile}
COMMAND cd ${CMAKE_HOME_DIRECTORY}/ && ${ODB_PATH}odb --include-prefix vcf --std c++11 -d sqlite --generate-query --generate-schema
--hxx-suffix .hpp --ixx-suffix .ipp --cxx-suffix .cpp
--output-dir ${CMAKE_HOME_DIRECTORY}/inc/vcf/ ${_file}
&& mv ${CMAKE_HOME_DIRECTORY}/${gencppfile} ${CMAKE_HOME_DIRECTORY}/${right_place_gencppfile}
DEPENDS ${_file}
COMMENT "Building odb for ${_file}"
)
endif ()
list (APPEND MOD_ODB_SOURCES ${right_place_gencppfile})
endforeach ()
add_library (mod_odb STATIC ${MOD_ODB_SOURCES})
target_link_libraries (mod_odb ${THIRD_PARTY_LIBRARIES})
set (MOD_VCF_SOURCES
inc/vcf/assembly_checker.hpp
inc/vcf/assembly_report_writer.hpp
inc/vcf/compression.hpp
inc/vcf/debugulator.hpp
inc/vcf/error_policy.hpp
inc/vcf/file_structure.hpp
inc/vcf/fixer.hpp
inc/vcf/meta_entry_visitor.hpp
inc/vcf/normalizer.hpp
inc/vcf/odb_report.hpp
inc/vcf/optional_policy.hpp
inc/vcf/parse_policy.hpp
inc/vcf/parsing_state.hpp
inc/vcf/record.hpp
inc/vcf/record_cache.hpp
inc/vcf/report_reader.hpp
inc/vcf/report_writer.hpp
inc/vcf/string_constants.hpp
inc/vcf/summary_report_writer.hpp
inc/vcf/validator_detail_v41.hpp
inc/vcf/validator_detail_v42.hpp
inc/vcf/validator_detail_v43.hpp
inc/vcf/validator.hpp
src/vcf/abort_error_policy.cpp
src/vcf/assembly_checker.cpp
src/vcf/compression.cpp
src/vcf/debugulator.cpp
src/vcf/fixer.cpp
src/vcf/meta_entry.cpp
src/vcf/normalizer.cpp
src/vcf/odb_report.cpp
src/vcf/parsing_state.cpp
src/vcf/record.cpp
src/vcf/report_error_policy.cpp
src/vcf/source.cpp
src/vcf/store_parse_policy.cpp
src/vcf/validate_optional_policy.cpp
src/vcf/validator.cpp
)
add_library (mod_vcf STATIC ${MOD_VCF_SOURCES})
add_dependencies (mod_vcf mod_odb) # works even without this if we add mod_vcf as target_link_libraries
target_link_libraries (mod_vcf ${THIRD_PARTY_LIBRARIES} mod_odb)
# Libraries to link with executables
if (LINUX OR OSX)
set (LIBRARIES_TO_LINK
mod_vcf
mod_odb
${Boost_LIBRARIES}
${EXT_LIB_PATH}/libbz2.a
${EXT_LIB_PATH}/libz.a
${EXT_LIB_PATH}/libodb-sqlite.a
${EXT_LIB_PATH}/libodb.a
mod_sqlite3
${CMAKE_THREAD_LIBS_INIT}
)
elseif (WINDOWS)
set (LIBRARIES_TO_LINK
mod_vcf
mod_odb
${EXT_LIB_PATH}/odb-sqlite.lib
${EXT_LIB_PATH}/odb.lib
mod_sqlite3
${CMAKE_THREAD_LIBS_INIT}
)
endif ()
# Build tests
set (V41_TESTS test/vcf/parser_v41_test.cpp)
set (V42_TESTS test/vcf/parser_v42_test.cpp)
set (V43_TESTS test/vcf/parser_v43_test.cpp)
set (ALL_TESTS
test/vcf/assembly_checker_integration_test.cpp
test/vcf/assembly_checker_test.cpp
test/vcf/compressed_file_test.cpp
test/vcf/debugulator_integration_test.cpp
test/vcf/debugulator_test.cpp
test/vcf/metaentry_test.cpp
test/vcf/normalize_test.cpp
test/vcf/optional_policy_test.cpp
test/vcf/parser_test_aux.hpp
test/vcf/parser_v41_test.cpp
test/vcf/parser_v42_test.cpp
test/vcf/parser_v43_test.cpp
test/vcf/predefined_info_tags_test.cpp
test/vcf/predefined_format_tags_test.cpp
test/vcf/record_cache_test.cpp
test/vcf/record_test.cpp
test/vcf/report_writer_test.cpp
test/vcf/test_utils.hpp
)
add_executable (test_validator_v41 test/main_test.cpp ${V41_TESTS})
target_link_libraries (test_validator_v41 ${LIBRARIES_TO_LINK})
enable_testing ()
add_test (NAME ValidatorTests_v41 COMMAND test_validator_v41)
add_executable (test_validator_v42 test/main_test.cpp ${V42_TESTS})
target_link_libraries (test_validator_v42 ${LIBRARIES_TO_LINK})
enable_testing ()
add_test (NAME ValidatorTests_v42 COMMAND test_validator_v42)
add_executable (test_validator_v43 test/main_test.cpp ${V43_TESTS})
target_link_libraries (test_validator_v43 ${LIBRARIES_TO_LINK})
enable_testing ()
add_test (NAME ValidatorTests_v43 COMMAND test_validator_v43)
add_executable (test_validation_suite test/main_test.cpp ${ALL_TESTS})
target_link_libraries (test_validation_suite ${LIBRARIES_TO_LINK})
enable_testing ()
add_test (NAME ValidatorTests COMMAND test_validation_suite)
# Build application binaries
add_executable (vcf_validator src/validator_main.cpp)
target_link_libraries (vcf_validator ${LIBRARIES_TO_LINK})
add_executable (vcf_debugulator src/debugulator_main.cpp)
target_link_libraries (vcf_debugulator ${LIBRARIES_TO_LINK})
add_executable (vcf_assembly_checker src/assembly_checker_main.cpp)
target_link_libraries (vcf_assembly_checker ${LIBRARIES_TO_LINK})