forked from apache/kudu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
236 lines (198 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
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
############################################################
# Compiler flags
############################################################
# compiler flags that are common across debug/release builds
# - msse4.2: Enable sse4.2 compiler intrinsics.
# - Wall: Enable all warnings.
# - Wno-sign-compare: suppress warnings for comparison between signed and unsigned
# integers
# -Wno-deprecated: some of the gutil code includes old things like ext/hash_set, ignore that
# - pthread: enable multithreaded malloc
# - -D__STDC_FORMAT_MACROS: for PRI* print format macros
SET(CXX_COMMON_FLAGS "-msse4.2 -Wall -Wno-sign-compare -Wno-deprecated -pthread -D__STDC_FORMAT_MACROS")
SET(CXX_COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
# compiler flags for different build types (run 'cmake -DCMAKE_BUILD_TYPE=<type> .')
# For all builds:
# For CMAKE_BUILD_TYPE=Debug
# -ggdb: Enable gdb debugging
# For CMAKE_BUILD_TYPE=Release
# -O3: Enable all compiler optimizations
# -g: Enable symbols for profiler tools (TODO: remove for shipping)
# -DNDEBUG: Turn off dchecks/asserts/debug only code.
# -Wno-strict-aliasing: Suppress warnings for potential issues with pointer aliasing. Code
# generated by -O3 causes these warnings.
# For profile guided optimization (PGO) builds, in addition to the flags for release builds:
# 1. Build first with CMAKE_BUILD_TYPE_PROFILE_GEN:
# -fprofile-generate: Indicates compiler should insert profile guided optimization events
# 2. Run the benchmarks (generates *.gcda profiling data).
# 3. Build again with CMAKE_BUILD_TYPE_PROFILE_BUILD
# -fprofile-use: Compiler will use the profile outputs for optimizations
SET(CXX_FLAGS_DEBUG "-ggdb")
SET(CXX_FLAGS_RELEASE "-O3 -g -DNDEBUG -Wno-strict-aliasing")
if (NOT "${KUDU_USE_LTO}" STREQUAL "")
SET(CXX_FLAGS_RELEASE "${CXX_FLAGS_RELEASE} flto -fno-use-linker-plugin")
endif()
SET(CXX_FLAGS_PROFILE_GEN "${CXX_FLAGS_RELEASE} -fprofile-generate")
SET(CXX_FLAGS_PROFILE_BUILD "${CXX_FLAGS_RELEASE} -fprofile-use")
# if no build build type is specified, default to debug builds
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif(NOT CMAKE_BUILD_TYPE)
STRING (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
# Set compile flags based on the build type.
message("Configured for ${CMAKE_BUILD_TYPE} build (set with cmake -DCMAKE_BUILD_TYPE={release,debug,...})")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_DEBUG})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_RELEASE})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_GEN")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_PROFILE_GEN})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_BUILD")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_PROFILE_BUILD})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "CODE_COVERAGE_DEBUG")
SET(CMAKE_CXX_FLAGS "${CXX_FLAGS_DEBUG} ${CXX_COVERAGE_FLAGS}")
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "CODE_COVERAGE_RELEASE")
SET(CMAKE_CXX_FLAGS "${CXX_FLAGS_RELEASE} ${CXX_COVERAGE_FLAGS}")
else()
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
endif ()
# Add common flags
SET(CMAKE_CXX_FLAGS "${CXX_COMMON_FLAGS} ${CMAKE_CXX_FLAGS}")
# Flag to enable clang address sanitizer
# This will only build if clang is the chosen compiler
if (${KUDU_USE_ASAN})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g -fno-omit-frame-pointer")
# Ensure static linking is on -- otherwise can run into llvm bug #56393:
# http://www.mail-archive.com/[email protected]/msg386467.html
set(KUDU_STATIC_LINK ON)
endif ()
INCLUDE_DIRECTORIES(src)
############################################################
# Testing
############################################################
FUNCTION(ADD_KUDU_TEST TEST_NAME)
ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc)
ADD_TEST(${TEST_NAME} ${TEST_NAME})
TARGET_LINK_LIBRARIES(${TEST_NAME} ${KUDU_TEST_LINK_LIBS})
ENDFUNCTION()
ENABLE_TESTING()
############################################################
# Dependencies
############################################################
set(THIRDPARTY_PREFIX ${CMAKE_SOURCE_DIR}/thirdparty/installed)
set(LIBS ${LIBS} -lrt)
## Boost
### Workaround for http://stackoverflow.com/questions/9948375/cmake-find-package-succeeds-but-returns-wrong-path
set(Boost_NO_BOOST_CMAKE ON)
if ("${KUDU_STATIC_LINK}")
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(Boost COMPONENTS thread system REQUIRED)
include_directories( ${Boost_INCLUDE_DIR} )
set(LIBS ${LIBS} ${Boost_LIBRARIES})
## GLog
find_package(GLog REQUIRED)
include_directories(${GLOG_INCLUDE_DIR})
if ("${KUDU_STATIC_LINK}")
add_library(glog STATIC IMPORTED)
set_target_properties(glog PROPERTIES IMPORTED_LOCATION "${GLOG_STATIC_LIB}")
else()
add_library(glog SHARED IMPORTED)
set_target_properties(glog PROPERTIES IMPORTED_LOCATION "${GLOG_LIBS}/libglog.so")
endif()
SET(LIBS ${LIBS} glog)
## GFlags
find_package(GFlags REQUIRED)
INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR})
if ("${KUDU_STATIC_LINK}")
add_library(gflags STATIC IMPORTED)
set_target_properties(gflags PROPERTIES IMPORTED_LOCATION "${GFLAGS_STATIC_LIB}")
else()
add_library(gflags SHARED IMPORTED)
set_target_properties(gflags PROPERTIES IMPORTED_LOCATION "${GFLAGS_LIBS}/libgflags.so")
endif()
SET(LIBS ${LIBS} gflags)
## GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${GTEST_LIBRARY}")
set(LIBS ${LIBS} ${GTEST_LIBRARY})
SET(KUDU_MIN_TEST_LIBS ${GTEST_LIBRARY} kudu_test_main glog gflags )
## Protobuf
SET(PROTO_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(PROTO_DST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/src)
find_package( Protobuf REQUIRED )
include_directories(${PROTOBUF_INCLUDE_DIR})
if ("${KUDU_STATIC_LINK}")
add_library(protobuf STATIC IMPORTED)
set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION "${PROTOBUF_STATIC_LIBRARY}")
else()
add_library(protobuf SHARED IMPORTED)
set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION "${PROTOBUF_LIBRARY}")
endif()
set(LIBS ${LIBS} protobuf)
## Snappy
find_package(Snappy REQUIRED)
include_directories(${SNAPPY_INCLUDE_DIR})
if (${KUDU_STATIC_LINK})
set(LIBS ${LIBS} ${SNAPPY_STATIC_LIB})
else()
set(LIBS ${LIBS} ${SNAPPY_LIBS}/libsnappy.so)
endif()
## Libev
find_package(LibEv REQUIRED)
set(LIBS ${LIBS} ${LIBEV_STATIC_LIB})
include_directories(${LIBEV_INCLUDE_DIR})
## LZ4
find_package(Lz4 REQUIRED)
include_directories(${LZ4_INCLUDE_DIR})
set(LIBS ${LIBS} ${LZ4_STATIC_LIB})
## ZLib
find_package(Zlib REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
if (${KUDU_STATIC_LINK})
set(LIBS ${LIBS} ${ZLIB_STATIC_LIB})
else()
set(LIBS ${LIBS} ${ZLIB_LIBS}/libz.so)
endif()
## Google PerfTools
find_package( GPerf REQUIRED )
if (NOT "${KUDU_USE_ASAN}")
set(LIBS ${LIBS} ${TCMALLOC_LIBRARY})
endif()
############################################################
# Linker setup
############################################################
SET(KUDU_DEP_LIBS ${LIBS})
SET(KUDU_LINK_LIBS tablet cfile kudu_common kudu_util gutil ${LIBS})
SET(KUDU_TEST_LINK_LIBS ${KUDU_LINK_LIBS} ${KUDU_MIN_TEST_LIBS})
############################################################
# "make etags" target
############################################################
IF (UNIX)
ADD_CUSTOM_TARGET(tags etags --members --declarations
`find ${CMAKE_CURRENT_SOURCE_DIR}/src -name
*.cc -or -name *.hh -or -name *.cpp -or -name *.h -or -name *.c -or
-name *.f`)
ADD_CUSTOM_TARGET(etags DEPENDS tags)
ENDIF (UNIX)
############################################################
# Subdirectories
############################################################
# Google util libraries borrowed from supersonic
add_subdirectory(src/gutil)
set(LIBS ${LIBS} ${GUTIL_LIBS})
add_subdirectory(src/util)
set(LIBS ${LIBS} ${KUDU_UTIL_LIBS})
add_subdirectory(src/common)
set(LIBS ${LIBS} ${KUDU_COMMON_LIBS})
add_subdirectory(src/cfile)
set(LIBS ${LIBS} ${CFILE_LIBS})
add_subdirectory(src/tablet)
set(LIBS ${LIBS} ${TABLET_LIBS})
add_subdirectory(src/rpc)
set(LIBS ${LIBS} ${RPC_LIBS})
add_subdirectory(src/experiments)