-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
170 lines (147 loc) · 4.66 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
# CMake 3.22.1 is the default on Ubuntu 22.04
cmake_minimum_required(VERSION 3.22.1)
project(
spider
LANGUAGES
C
CXX
VERSION 0.1.0
)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable exporting compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)
# Set the default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(SPIDER_DEFAULT_BUILD_TYPE "Release")
message(STATUS "No build type specified. Setting to '${SPIDER_DEFAULT_BUILD_TYPE}'.")
set(CMAKE_BUILD_TYPE
"${SPIDER_DEFAULT_BUILD_TYPE}"
CACHE STRING
"Choose the type of build."
FORCE
)
endif()
# Add local CMake module directory to CMake's modules path
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_SOURCE_DIR}/cmake/Modules/"
)
# Macro providing the length of the absolute source directory path so we can
# create a relative (rather than absolute) __FILE__ macro
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
# Profiling options
add_definitions(-DPROF_ENABLED=0)
# Compile-in debug logging statements
#add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG)
# Flush to disk switch
add_definitions(-DFLUSH_TO_DISK_ENABLED=1)
# Make off_t 64-bit
add_definitions(-D_FILE_OFFSET_BITS=64)
# Turn on PIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Detect linking mode (static or shared); Default to static.
set(SPIDER_USE_STATIC_LIBS ON CACHE BOOL "Whether to link against static libraries")
if(SPIDER_USE_STATIC_LIBS)
if(APPLE)
set(SPIDER_STATIC_LIBS_UNSUPPORTED_PLATFORM "macOS")
elseif(EXISTS "/etc/centos-release")
set(SPIDER_STATIC_LIBS_UNSUPPORTED_PLATFORM "CentOS")
endif()
if(DEFINED SPIDER_STATIC_LIBS_UNSUPPORTED_PLATFORM)
message(
AUTHOR_WARNING
"Building with static libraries is unsupported on"
" ${SPIDER_STATIC_LIBS_UNSUPPORTED_PLATFORM}. Switching to shared libraries."
)
set(SPIDER_USE_STATIC_LIBS OFF)
endif()
endif()
if(SPIDER_USE_STATIC_LIBS)
set(SPIDER_LIBS_STRING "static")
else()
set(SPIDER_LIBS_STRING "shared")
endif()
message(STATUS "Building using ${SPIDER_LIBS_STRING} libraries")
# Find and setup Boost Library
if(SPIDER_USE_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(
Boost
1.74
REQUIRED
COMPONENTS
headers
process
program_options
filesystem
system
)
if(Boost_FOUND)
message(STATUS "Found Boost ${Boost_VERSION}")
else()
message(FATAL_ERROR "Could not find ${SPIDER_LIBS_STRING} libraries for Boost")
endif()
# Find and setup fmt
find_package(fmt 8.0.1 REQUIRED)
if(fmt_FOUND)
message(STATUS "Found fmt ${fmt_VERSION}")
else()
message(FATAL_ERROR "Could not find static libraries for fmt")
endif()
# Find and setup spdlog
if(SPIDER_USE_STATIC_LIBS)
# NOTE: On some Linux distributions (e.g. Ubuntu), the spdlog package only contains a dynamic
# library. If the `find_package(spdlog)` call below fails, re-run
# `tools/scripts/lib_install/<dist_name>/install-packages-from-source.sh` to build spdlog from
# source.
set(spdlog_USE_STATIC_LIBS ON)
endif()
set(SPDLOG_FMT_EXTERNAL ON)
add_compile_definitions(SPDLOG_FMT_EXTERNAL)
find_package(spdlog 1.9.2 REQUIRED)
if(spdlog_FOUND)
message(STATUS "Found spdlog ${spdlog_VERSION}")
else()
if(SPIDER_USE_STATIC_LIBS)
message(FATAL_ERROR "Could not find static libraries for spdlog.`")
else()
message(FATAL_ERROR "Could not find libraries for spdlog.")
endif()
endif()
# Find and setup MariaDBClient library
if(SPIDER_USE_STATIC_LIBS)
# NOTE: We can't statically link to MariaDBClient since it's GPL
message(AUTHOR_WARNING "MariaDBClient cannot be statically linked due to its license.")
endif()
find_package(MariaDBClientCpp 1.0 REQUIRED)
if(MariaDBClientCpp_FOUND)
message(STATUS "Found MariaDBClientCpp ${MariaDBClientCpp_VERSION}")
else()
message(FATAL_ERROR "Could not find ${SPIDER_LIBS_STRING} libraries for MariaDBClientCpp")
endif()
# Find and setup msgpack
if(SPIDER_USE_STATIC_LIBS)
set(msgpack-cxx_USE_STATIC_LIBS ON)
endif()
find_package(msgpack-cxx 7.0.0 REQUIRED)
if(msgpack-cxx_FOUND)
message(STATUS "Found msgpack-cxx ${msgpack-cxx_VERSION}")
else()
message(FATAL_ERROR "Could not find msgpack-cxx")
endif()
# Add abseil-cpp
set(ABSL_PROPAGATE_CXX_STD ON)
add_subdirectory(submodules/abseil-cpp)
# Add catch2
add_subdirectory(submodules/Catch2)
find_package(Threads REQUIRED)
add_subdirectory(src/spider)
add_subdirectory(tests)