-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
182 lines (160 loc) · 5.02 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
cmake_minimum_required(VERSION 3.12)
# Set project name and version
project(MillenniumDB VERSION 0.2.1)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Enable export of compile commands output
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Use all cores but one for compilation
include(ProcessorCount)
ProcessorCount(NUM_CORES)
if(NUM_CORES GREATER 1)
math(EXPR PARALLEL_LEVEL "${NUM_CORES} - 1")
set(CMAKE_BUILD_PARALLEL_LEVEL ${PARALLEL_LEVEL})
endif()
# Set output directories
set(EXECUTABLE_OUTPUT_PATH bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib)
if(APPLE)
message("https://cmake.org/cmake/help/latest/variable/APPLE.html?highlight=apple")
set(BREW_DIRS "/opt/homebrew/opt" "/usr/local/opt")
foreach(BREW_DIR ${BREW_DIRS})
if(EXISTS ${BREW_DIR})
include_directories("${BREW_DIR}/openssl/include")
include_directories("${BREW_DIR}/ncurses/include")
link_directories("${BREW_DIR}/openssl@3/lib")
endif(EXISTS ${BREW_DIR})
endforeach(BREW_DIR)
set(NCURSES ncurses)
set(FS "")
else()
set(NCURSES ncursesw)
set(FS "stdc++fs")
endif(APPLE)
# Define the compiler flags
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -pthread -march=native -funroll-loops -fno-operator-names")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -fsanitize=undefined,address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g0")
if(PROFILE)
add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE)
endif(PROFILE)
# When compiling with Clang generate debug info specifically for lldb
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -glldb -fstandalone-debug")
endif()
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
endif(APPLE)
# Enable OpenMP if available
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
message(WARNING "OpenMP not found")
endif(OpenMP_CXX_FOUND)
# Enable interprocedural optimization if supported and BUILD_TYPE is RELEASE
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
if(BUILD_TYPE STREQUAL "RELEASE")
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_result OUTPUT ipo_output)
if(ipo_result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported:\n${ipo_output}")
endif(ipo_result)
endif(BUILD_TYPE STREQUAL "RELEASE")
# Add include directories
include_directories(${CMAKE_SOURCE_DIR}/src)
# Define sources
file(GLOB_RECURSE SRCS src/*.cc)
file(GLOB_RECURSE BIN_SRCS src/bin/*.cc)
file(GLOB_RECURSE TEST_SRCS src/tests/*.cc)
file(GLOB_RECURSE API_SRCS src/api/*.cc)
# Remove unwanted files from common sources
list(REMOVE_ITEM SRCS ${BIN_SRCS})
list(REMOVE_ITEM SRCS ${TEST_SRCS})
message(STATUS "Build MillenniumDB's binaries")
# Third party dependencies
add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/antlr4-runtime-4.13.1)
include_directories(${CMAKE_SOURCE_DIR}/third_party/antlr4-runtime-4.13.1/src)
include_directories(${CMAKE_SOURCE_DIR}/third_party/boost_1_82/include)
# Define targets
add_library(millenniumdb STATIC ${SRCS})
target_compile_definitions(millenniumdb PUBLIC SERD_STATIC)
set(BUILD_TARGETS
mdb-server
mdb-cli
mdb-dump
mdb-import
mdb-import-tensors
mdb-index-tensors
# mdb-scsu
# mdb-text-search
)
set(PROFILE_TARGETS
profile-query
)
set(TEST_TARGETS
compare_datetime
compare_decimal_both_ext
compare_decimal_both_inl
compare_decimal_inl_ext
decimal_operations
iri_prefixes-test
normalize_decimal
regular_path_expr_to_rpq_dfa
scsu-test
variable_set
)
# Build targets
foreach(target ${BUILD_TARGETS})
add_executable(${target} ${CMAKE_SOURCE_DIR}/src/bin/${target}.cc)
target_link_libraries(${target}
millenniumdb
antlr4_cpp_runtime
${FS}
ssl
crypto
${NCURSES}
)
endforeach(target)
# Test targets
enable_testing()
foreach(target ${TEST_TARGETS})
add_executable(${target} ${CMAKE_SOURCE_DIR}/src/tests/${target}.cc)
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
target_link_libraries(${target}
millenniumdb
antlr4_cpp_runtime
${FS}
ssl
crypto
)
add_test(
NAME ${target}
COMMAND $<TARGET_FILE:${target}>
WORKING_DIRECTORY tests
)
endforeach(target)
if(PROFILE)
# Profile targets
foreach(target ${PROFILE_TARGETS})
add_executable(${target} ${CMAKE_SOURCE_DIR}/src/bin/${target}.cc)
target_link_libraries(${target}
millenniumdb
antlr4_cpp_runtime
${FS}
ssl
crypto
dl
-Wl,-no-as-needed
-no-pie
-fno-pie
tcmalloc
profiler
)
endforeach(target)
endif(PROFILE)
install(TARGETS ${BUILD_TARGETS} RUNTIME DESTINATION bin)