-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
410 lines (332 loc) · 14.8 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Modified from the Apache Arrow project for the Terrier project.
cmake_minimum_required(VERSION 3.8)
# Extract Terrier version number
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/build-support/version.xml" POM_XML)
string(REGEX MATCHALL
"\n<version>[^<]+</version>" TERRIER_VERSION_TAG "${POM_XML}")
string(REGEX REPLACE
"(\n<version>|</version>)" "" TERRIER_VERSION "${TERRIER_VERSION_TAG}")
string(REGEX MATCH
"^[0-9]+\\.[0-9]+\\.[0-9]+" TERRIER_BASE_VERSION "${TERRIER_VERSION}")
project(terrier
LANGUAGES CXX
VERSION "${TERRIER_BASE_VERSION}"
)
set(TERRIER_VERSION_MAJOR "${terrier_VERSION_MAJOR}")
set(TERRIER_VERSION_MINOR "${terrier_VERSION_MINOR}")
set(TERRIER_VERSION_PATCH "${terrier_VERSION_PATCH}")
if (TERRIER_VERSION_MAJOR STREQUAL "" OR
TERRIER_VERSION_MINOR STREQUAL "" OR
TERRIER_VERSION_PATCH STREQUAL "")
MESSAGE(FATAL_ERROR "Failed to determine Terrier version from '${TERRIER_VERSION}'")
endif ()
# The SO version is also the ABI version
# Terrier 0.x.y => SO version is "x", full SO version is "x.y.0"
set(TERRIER_SO_VERSION "${TERRIER_VERSION_MINOR}")
set(TERRIER_FULL_SO_VERSION "${TERRIER_SO_VERSION}.${TERRIER_VERSION_PATCH}.0")
message(STATUS "Terrier version: "
"${TERRIER_VERSION_MAJOR}.${TERRIER_VERSION_MINOR}.${TERRIER_VERSION_PATCH} "
"(full: '${TERRIER_VERSION}')")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
include(CMakeParseArguments)
include(ExternalProject)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(GNUInstallDirs)
# Compatibility with CMake 3.1
if (POLICY CMP0054)
# http://www.cmake.org/cmake/help/v3.1/policy/CMP0054.html
cmake_policy(SET CMP0054 NEW)
endif ()
if (APPLE)
cmake_policy(SET CMP0068 NEW)
endif ()
set(BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build-support")
set(BUILD_SUPPORT_DATA_DIR "${CMAKE_SOURCE_DIR}/build-support/data")
###################################################
# CMAKE OPTIONS
###################################################
set(TERRIER_CXXFLAGS "" CACHE STRING
"Compiler flags to append when compiling Terrier")
option(TERRIER_BUILD_STATIC
"Build the libterrier static libraries"
ON)
option(TERRIER_BUILD_SHARED
"Build the libterrier shared libraries"
ON)
option(TERRIER_TEST_MEMCHECK
"Run the test suite using valgrind --tool=memcheck"
OFF)
option(TERRIER_BUILD_TESTS
"Build the Terrier googletest unit tests"
ON)
option(TERRIER_BUILD_BENCHMARKS
"Build the Terrier micro benchmarks"
ON)
option(TERRIER_RPATH_ORIGIN
"Build Terrier libraries with RATH set to \$ORIGIN"
OFF)
option(TERRIER_INSTALL_NAME_RPATH
"Build Terrier libraries with install_name set to @rpath"
ON)
option(TERRIER_GENERATE_COVERAGE
"Build with C++ code coverage enabled"
OFF)
option(TERRIER_USE_JEMALLOC
"Dynamically link jemalloc as the memory allocator."
OFF)
option(TERRIER_VERBOSE_THIRDPARTY_BUILD
"If off, output from ExternalProjects will be logged to files rather than shown"
OFF)
option(TERRIER_VERBOSE_LINT
"If off, 'quiet' flags will be passed to linting tools"
OFF)
if (NOT TERRIER_BUILD_TESTS)
set(NO_TESTS 1)
endif ()
if (NOT TERRIER_BUILD_BENCHMARKS)
set(NO_BENCHMARKS 1)
endif ()
###################################################
# COMPILER TOOLS
###################################################
set(CLANG_TOOLS_VERSION "8")
find_package(ClangTools)
if ("$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}" STREQUAL "1" OR CLANG_TIDY_FOUND)
# Generate a Clang compile_commands.json "compilation database" file for use
# with various development tools, such as Vim's YouCompleteMe plugin.
# See http://clang.llvm.org/docs/JSONCompilationDatabase.html
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
endif ()
############################################################
# Compiler flags
############################################################
# Determine compiler version
include(CompilerInfo)
include(SetupCxxFlags)
############################################################
# Dependencies
############################################################
include(BuildUtils)
enable_testing()
include(ThirdpartyToolchain)
# ASAN / TSAN / UBSAN
include(san-config)
###########################################################
# code coverage
###########################################################
if (TERRIER_GENERATE_COVERAGE)
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
message(FATAL_ERROR "Coverage can only be generated with a debug build type!")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif ()
# Add common flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_COMMON_FLAGS}")
# For any C code, use the same flags.
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
# Remove --std=c++17 to avoid errors from C compilers
string(REPLACE "-std=c++17" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
# Add C++-only flags, like -std=c++17
set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}")
# CMAKE_CXX_FLAGS now fully assembled
message(STATUS "CXX_ONLY_FLAGS: ${CXX_ONLY_FLAGS}")
message(STATUS "CXX_COMMON_FLAGS: ${CXX_COMMON_FLAGS}")
message(STATUS "CXX_OPTIMIZATION_FLAGS: ${CXX_OPTIMIZATION_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
###########################################################
# "make check-lint" and "make check-censored" targets
###########################################################
if (NOT TERRIER_VERBOSE_LINT)
set(TERRIER_LINT_QUIET "--quiet")
endif ()
if (UNIX)
file(GLOB_RECURSE LINT_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/benchmark/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/benchmark/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/util/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/util/*.cpp"
)
find_program(CPPLINT_BIN NAMES cpplint cpplint.py HINTS ${BUILD_SUPPORT_DIR})
message(STATUS "Found cpplint executable at ${CPPLINT_BIN}")
# Full lint
# Balancing act: cpplint.py takes a non-trivial time to launch,
# so process 12 files per invocation, while still ensuring parallelism
add_custom_target(check-lint echo '${LINT_FILES}' | xargs -n12 -P8
${CPPLINT_BIN}
--verbose=2 ${TERRIER_LINT_QUIET}
--linelength=120
--filter=-legal/copyright,-build/header_guard
)
set(CENSOR_FILES ${LINT_FILES})
# If whitelisting ALL words becomes necessary, do it here. Make it harder so that people try not to do it.
# file(GLOB_RECURSE UNCENSORED_FILES
# "${CMAKE_CURRENT_SOURCE_DIR}/src/..."
# )
# list(REMOVE_ITEM CENSOR_FILES ${UNCENSORED_FILES})
add_custom_target(check-censored
grep --invert-match -n -e '^ *//' -e '^ *[*]' ${CENSOR_FILES} # check all uncommented lines w/ line num
| grep -i -f ${BUILD_SUPPORT_DATA_DIR}/bad_words.txt # for bad words, not case sensitive
| grep --invert-match -e 'NOLINT' # the count of them that aren't NOLINT
# whitelist-start
# Description: allow usage of 'inline' in execution engine
# Reason: pmenon 2019/08/13
# All the bytecode handler functions have to be inline to ensure one definition.
# gen_opt_bc also cleans up the modules to add the odr to all functions.
# On top of that, many are marked ALWAYS_INLINE to force physical inlining into the VM.
# These are hand-selected by me based on profiling.
| grep --invert-match -e 'src/include/execution/.*:.*inline\\b.*'
| grep --invert-match -e 'src/execution/ast/context.cpp.*:.*inline\\b.*'
| grep --invert-match -e 'src/execution/vm/vm.cpp.*:.*inline\\b.*'
# Description: Regions, memory pool chunks, and vm stacks are managed using malloc and free
| grep --invert-match -e 'src/execution/sql/memory_pool.cpp:.*malloc\(.*'
| grep --invert-match -e 'src/execution/sql/memory_pool.cpp:.*calloc\(.*'
| grep --invert-match -e 'src/execution/sql/memory_pool.cpp:.*free\(.*'
| grep --invert-match -e 'src/execution/util/region.cpp:.*malloc\(.*'
| grep --invert-match -e 'src/execution/util/region.cpp:.*free\(.*'
| grep --invert-match -e 'src/execution/vm/vm.cpp:.*free\(.*'
# Description: This one is a false positive on the macro Op##AGG_TYPE##Free
| grep --invert-match -e 'src/execution/vm/vm.cpp:.*Free\(.*'
# Description: We're allowing shared_ptr and make_shared in testing folders.
# I don't actually remember the justification.
| grep --invert-match -e '${CMAKE_SOURCE_DIR}/test/.*shared_ptr'
| grep --invert-match -e '${CMAKE_SOURCE_DIR}/test/.*make_shared'
# whitelist-end
|| exit 0 # if nothing found, return 0
&& exit 1 # else return 1, note || && left-associative
)
endif (UNIX)
###########################################################
# "make format" and "make check-format" targets
###########################################################
# we modified the format script to take multiple args
string(CONCAT FORMAT_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/benchmark,"
"${CMAKE_CURRENT_SOURCE_DIR}/src,"
"${CMAKE_CURRENT_SOURCE_DIR}/test,"
"${CMAKE_CURRENT_SOURCE_DIR}/util"
)
# runs clang format and updates files in place.
add_custom_target(format ${BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${BUILD_SUPPORT_DATA_DIR}/clangformat_suppressions.txt
--source_dirs
${FORMAT_DIRS}
--fix
${TERRIER_LINT_QUIET})
# runs clang format and exits with a non-zero exit code if any files need to be reformatted
add_custom_target(check-format ${BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${BUILD_SUPPORT_DATA_DIR}/clangformat_suppressions.txt
--source_dirs
${FORMAT_DIRS}
${TERRIER_LINT_QUIET})
###########################################################
# "make check-clang-tidy" target
###########################################################
if (${CLANG_TIDY_FOUND})
# runs clang-tidy and exits with a non-zero exit code if any errors are found.
# note that clang-tidy automatically looks for a .clang-tidy file in parent directories
add_custom_target(check-clang-tidy
${BUILD_SUPPORT_DIR}/run-clang-tidy.py # run LLVM's clang-tidy script
-clang-tidy-binary ${CLANG_TIDY_BIN} # using our clang-tidy binary
-p ${CMAKE_BINARY_DIR} # using cmake's generated compile commands
)
if (TERRIER_BUILD_BENCHMARKS)
add_dependencies(check-clang-tidy benchmark gtest gflags) # clang-tidy needs their headers to exist
elseif (TERRIER_BUILD_TESTS)
add_dependencies(check-clang-tidy gtest gflags) # clang-tidy needs their headers to exist
endif ()
endif ()
###########################################################
# Build properties
###########################################################
# set compile output directory
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_SUBDIR_NAME)
# If build in-source, create the latest symlink. If build out-of-source, which is
# preferred, simply output the binaries in the build folder
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/${BUILD_SUBDIR_NAME}/")
# Link build/latest to the current build directory, to avoid developers
# accidentally running the latest debug build when in fact they're building
# release builds.
FILE(MAKE_DIRECTORY ${BUILD_OUTPUT_ROOT_DIRECTORY})
if (NOT APPLE)
set(MORE_ARGS "-T")
endif ()
EXECUTE_PROCESS(COMMAND ln ${MORE_ARGS} -sf ${BUILD_OUTPUT_ROOT_DIRECTORY}
${CMAKE_CURRENT_BINARY_DIR}/build/latest)
else ()
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/")
endif ()
# where to put generated archives (.a files)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
set(ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
# where to put generated libraries (.so files)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
set(LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}")
include_directories(${PROJECT_SOURCE_DIR}/src/include)
if (${COMPILER_FAMILY} STREQUAL "gcc")
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party)
else ()
include_directories(${PROJECT_SOURCE_DIR}/third_party)
endif ()
include_directories(${PROJECT_SOURCE_DIR}/test/include)
include_directories(${PROJECT_SOURCE_DIR}/util/include)
include_directories(${PROJECT_SOURCE_DIR}/benchmark/include)
include_directories(${PROJECT_BINARY_DIR})
# needed for BwTree
if (CMAKE_COMPILER_IS_GNUCXX)
set(TERRIER_LINK_LIBS ${TERRIER_LINK_LIBS} atomic)
endif ()
set(TERRIER_LINK_LIBS
gflags
${TERRIER_LINK_LIBS}
pg_query)
set(TERRIER_DEPENDENCIES
gflags)
set(TERRIER_TEST_LINK_LIBS
test_util
terrier_static
gtest
gmock_main
gflags
${CMAKE_DL_LIBS})
set(TERRIER_BENCHMARK_LINK_LIBS
benchmark_util
test_util
terrier_static
benchmark
gtest
gmock_main
gflags
${CMAKE_DL_LIBS})
# ---[ Subdirectories
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(benchmark)
add_subdirectory(util)