-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
211 lines (177 loc) · 5.76 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
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
cmake_policy (VERSION 2.6.0)
set(CMAKE_SKIP_RPATH FALSE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
project (eblob)
FILE (READ "${CMAKE_CURRENT_SOURCE_DIR}/debian/changelog" DEBCHANGELOG)
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" DEBFULLVERSION "${DEBCHANGELOG}")
STRING (REGEX MATCH "([0-9]+\\.[0-9]+)" EBLOB_VERSION_ABI "${DEBFULLVERSION}")
STRING (REGEX MATCH "([0-9]+$)" EBLOB_VERSION_MINOR "${DEBFULLVERSION}")
set(EBLOB_VERSION "${EBLOB_VERSION_ABI}.${EBLOB_VERSION_MINOR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
include(cmake/Modules/locate_library.cmake)
locate_library(HANDYSTATS "handystats/core.hpp" "handystats")
include_directories(${HANDYSTATS_INCLUDE_DIRS})
link_directories(${HANDYSTATS_LIBRARY_DIRS})
include(CheckAtomic)
include(CheckSymbolExists)
option(WITH_ASSERTS "Enable asserts" OFF)
option(WITH_HARDENING "Enable hardening" OFF)
option(WITH_ASAN "Enable address sanitizer" OFF)
option(WITH_MSAN "Enable memory sanitizer" OFF)
option(WITH_TSAN "Enable thread sanitizer" OFF)
option(WITH_PYTHON "Build python bindings" ON)
option(WITH_EXAMPLES "Build examples" ON)
option(WITH_TESTS "Build tests" ON)
option(WITH_STATS "Build with runtime statistics gathering" ON)
# Turn off aserts
if (NOT WITH_ASSERTS)
add_definitions(-DNDEBUG)
endif (NOT WITH_ASSERTS)
message(STATUS "Asserts are: ${WITH_ASSERTS}")
# Enable hardening
if (WITH_HARDENING)
add_definitions(
-D_FORTIFY_SOURCE=2
-fpic
)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
add_definitions(
-pie
-z now
-z relro
)
endif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
endif (WITH_HARDENING)
message(STATUS "Hardening is: ${WITH_HARDENING}")
if (WITH_ASAN)
add_definitions(
-fno-omit-frame-pointer
-fsanitize=address
)
set(SANITIZER_LIBRARY "-lasan")
endif (WITH_ASAN)
message(STATUS "asan is: ${WITH_ASAN}")
if (WITH_MSAN)
add_definitions(
-fno-omit-frame-pointer
-fpic
-fsanitize-memory-track-origins
-fsanitize=memory
)
set(SANITIZER_LIBRARY "-lmsan")
endif (WITH_MSAN)
message(STATUS "msan is: ${WITH_MSAN}")
if (WITH_TSAN)
add_definitions(
-fno-omit-frame-pointer
-fpic
-fsanitize=thread
)
set(SANITIZER_LIBRARY "-ltsan")
endif (WITH_TSAN)
message(STATUS "tsan is: ${WITH_TSAN}")
message(STATUS "Sanitizer lib: ${SANITIZER_LIBRARY}")
# Test endianess
include(TestBigEndian)
test_big_endian(HAVE_BIG_ENDIAN)
if(HAVE_BIG_ENDIAN)
add_definitions(-DBYTEORDER=4321)
add_definitions(-DWORDS_BIGENDIAN=1)
else()
add_definitions(-DBYTEORDER=1234)
endif()
# We use gnu extensions and C99 standard
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wredundant-decls")
add_definitions(
-W
-Wall
-Wextra
-Wstrict-aliasing=2
-fstack-protector-all
-fstrict-aliasing
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -std=gnu++0x")
# GCC's builtin memcmp is slower than libc's
# See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
add_definitions(
-fno-builtin-memcmp
)
endif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
if (${CMAKE_SYSTEM_NAME} MATCHES BSD)
add_definitions(-D__BSD_VISIBLE=1)
endif()
# PThreads
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
# Check for boost
find_package(Boost REQUIRED COMPONENTS iostreams thread system regex python unit_test_framework)
message(STATUS "Boost information:")
message(STATUS " Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS " Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message(STATUS " Boost_LIBRARIES: ${Boost_LIBRARIES}")
include_directories(
${CMAKE_SOURCE_DIR}/include/
${Boost_INCLUDE_DIRS}
)
link_directories(
${Boost_LIBRARY_DIRS}
)
# Check for python
if(WITH_PYTHON)
find_package(PythonLibs REQUIRED)
message(STATUS "Python includes are situated in (${PYTHON_INCLUDE_PATH}, ${PYTHON_INCLUDE_DIRS})")
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${PYTHON_INCLUDE_DIRS})
endif()
# Check for posix_fadvise
check_symbol_exists(posix_fadvise "fcntl.h" HAVE_POSIX_FADVISE)
if (HAVE_POSIX_FADVISE)
add_definitions(-DHAVE_POSIX_FADVISE)
endif()
# Check for posix_fallocate
check_symbol_exists(posix_fallocate "fcntl.h" HAVE_POSIX_FALLOCATE)
if (HAVE_POSIX_FALLOCATE)
add_definitions(-DHAVE_POSIX_FALLOCATE)
endif()
# Check for fdatasync
check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
if (HAVE_FDATASYNC)
add_definitions(-DHAVE_FDATASYNC)
endif()
# Check for handystats
if (WITH_STATS)
find_package(Handystats REQUIRED)
include_directories(${HANDYSTATS_INCLUDE_DIRS})
add_definitions(${HANDYSTATS_CFLAGS})
else()
# Handystats symbols are spilled across many source files,
# so even if we do want to disable handystats instrumentation,
# handystats headers still needed to define macros as empty stubs.
find_package(Handystats)
if (HANDYSTATS_FOUND)
add_definitions(${HANDYSTATS_CFLAGS})
add_definitions("-DHANDYSTATS_DISABLE=1")
endif()
endif()
# Collect all libraries together
set(EBLOB_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${SANITIZER_LIBRARY})
set(EBLOB_CPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${Boost_IOSTREAMS_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})
set(EBLOB_PYTHON_LIBRARIES ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
# Build parts
add_subdirectory(library)
if (WITH_EXAMPLES)
add_subdirectory(example)
endif()
if (WITH_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
add_subdirectory(bindings)
install(FILES
include/eblob/eblob.hpp
include/eblob/blob.h
DESTINATION include/eblob/
)