-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
176 lines (154 loc) · 6.2 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
cmake_minimum_required(VERSION 2.8)
project(SM_standalone)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9!")
endif()
else()
message(FATAL_ERROR "Please use recent GCC to compile this project")
endif()
include(ExternalProject)
if ( APPLE )
# necessary for GCC to use system assembler
# http://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion
set(CMAKE_C_FLAGS "-Wa,-q")
set(CMAKE_CXX_FLAGS "-Wa,-q -fvisibility-inlines-hidden")
elseif( WIN32 )
else()
set(CMAKE_C_FLAGS "-fPIC")
set(CMAKE_CXX_FLAGS "-fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wl,--exclude-libs=ALL -ffunction-sections")
endif()
# MessagePack - simple serialization library
externalproject_add(msgpack
GIT_REPOSITORY https://github.com/msgpack/msgpack-c
GIT_TAG cpp-1.4.0
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
) # for C++ compilation is not required
ExternalProject_Get_Property(msgpack source_dir)
include_directories(${source_dir}/include)
find_package(ZLIB REQUIRED)
# blosc - fast compressor for numeric data
externalproject_add(blosc
GIT_REPOSITORY https://github.com/Blosc/c-blosc
GIT_TAG v1.7.1
INSTALL_COMMAND ""
BUILD_COMMAND make blosc_static
CMAKE_ARGS -DBUILD_TESTS:BOOL=OFF -DBUILD_BENCHMARKS:BOOL=OFF -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
)
ExternalProject_Get_Property(blosc source_dir)
include_directories(${source_dir}/blosc/)
ExternalProject_Get_Property(blosc binary_dir)
set(BLOSC_LIBRARY ${binary_dir}/blosc/libblosc.a ${ZLIB_LIBRARY})
# cxxopts - lightweight command line options parser
externalproject_add(cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
GIT_TAG aec97a6f53c3486fc51e0d9857f10b683180d668
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
BUILD_COMMAND ""
) # header-only library, requires std::regex
ExternalProject_Get_Property(cxxopts source_dir)
include_directories(${source_dir}/src)
set(PROGRESSBAR_DIR ${PROJECT_SOURCE_DIR}/third-party/progressbar)
externalproject_add(progressbar_proj
GIT_REPOSITORY https://github.com/doches/progressbar
GIT_TAG 760e20c245a72cf564687c1ecc18163799229c58
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
DOWNLOAD_DIR ${PROGRESSBAR_DIR}
SOURCE_DIR ${PROGRESSBAR_DIR}
BINARY_DIR ${PROGRESSBAR_DIR}
BUILD_COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -c -Iinclude lib/progressbar.c -o lib/libprogressbar.a
)
include_directories(${PROGRESSBAR_DIR}/include)
add_library(progressbar STATIC IMPORTED)
set_property(TARGET progressbar PROPERTY IMPORTED_LOCATION ${PROGRESSBAR_DIR}/lib/libprogressbar.a)
add_dependencies(progressbar progressbar_proj)
if ( NOT WIN32)
find_package(OpenMP REQUIRED)
endif()
find_package(LibXml2 REQUIRED)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})
if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are strongly discouraged. "
"Please remove CMakeCache.txt and the CMakeFiles/ directory, then build out-of-source.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -Wl,--gc-sections")
if (NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -static-libgcc -Wl,--gc-sections")
# on Mac OS X static linking leads to exceptions not being caught,
# so it's better to just use the 'delocate-wheel' tool (puts needed shared libs into the wheel)
endif()
# necessary for static compilation
add_definitions(-DIN_LIBXML)
set(SRC_COMMON
imzb/reader.cpp
imzb/writer.cpp
imzb/dbscan.cpp
ims/image_measures.cpp
ms/isocalc.cpp
ms/spectrum.cpp
ms/periodic_table.cpp
)
add_library(libims STATIC ${SRC_COMMON})
target_compile_options(libims PUBLIC -std=c++11)
add_dependencies(libims blosc)
set_target_properties(libims PROPERTIES OUTPUT_NAME ims)
if ( NOT APPLE )
target_link_libraries(libims ${BLOSC_LIBRARY} -fopenmp -pthread)
else()
target_link_libraries(libims)
endif()
add_executable(ims-bin
tools/main.cpp
tools/convert.cpp
tools/isocalc.cpp
tools/detect.cpp
tools/fdr.cpp
imzml/reader.cpp
utils/isotope_pattern_db.cpp
utils/metrics.cpp)
target_compile_options(ims-bin PUBLIC -std=c++11 ${OpenMP_CXX_FLAGS} -pthread)
set_target_properties(ims-bin PROPERTIES OUTPUT_NAME ims)
target_link_libraries(ims-bin progressbar libims)
if ( WIN32 )
target_link_libraries(ims-bin -Wl,-Bstatic -lncurses -lxml2 -liconv -lgomp -lwinpthread -lws2_32)
elseif ( APPLE )
target_link_libraries(ims-bin ${BLOSC_LIBRARY} -lncurses -lxml2 ${OpenMP_CXX_FLAGS})
else()
target_link_libraries(ims-bin -Wl,-Bstatic -ltermcap -lxml2 -llzma -lstdc++ -Wl,-Bdynamic -lm)
endif()
add_dependencies(ims-bin blosc libims msgpack progressbar cxxopts)
if ( SCILS_H5_SUPPORT)
target_compile_definitions(ims-bin PRIVATE -DSCILS_H5)
target_link_libraries(ims-bin -lhdf5 -lhdf5_hl)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
add_library(ms_cffi SHARED cffi/isocalc.cpp cffi/common.cpp ms/isocalc.cpp ms/spectrum.cpp ms/periodic_table.cpp)
target_compile_options(ms_cffi PUBLIC -std=c++11)
if ( WIN32 )
target_link_libraries(ms_cffi -Wl,-Bstatic -lstdc++ -lpthread -lws2_32)
elseif ( APPLE )
else()
target_link_libraries(ms_cffi -Wl,-Bsymbolic-functions -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lm)
endif()
add_library(ims_cffi SHARED cffi/imzb.cpp cffi/common.cpp imzb/reader.cpp cffi/image_measures.cpp ims/image_measures.cpp imzb/dbscan.cpp)
target_compile_options(ims_cffi PUBLIC -std=c++11)
if ( WIN32 )
target_link_libraries(ims_cffi ${BLOSC_LIBRARY} -Wl,-Bstatic -lstdc++ -lpthread -lws2_32)
elseif ( APPLE )
target_link_libraries(ims_cffi ${BLOSC_LIBRARY})
else()
target_link_libraries(ims_cffi ${BLOSC_LIBRARY} -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lm)
endif()
add_dependencies(ims_cffi blosc)
# export compilation database for autocompletion
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)