-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
254 lines (217 loc) · 10.4 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
cmake_minimum_required(VERSION 3.14)
project(mgmigrate VERSION 0.0.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set default build type to 'Debug'
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
if(WIN32)
set(MGMIGRATE_ON_WINDOWS TRUE)
set(MGMIGRATE_FIND_LIBRARY_PREFIXES "lib")
elseif(APPLE)
set(MGMIGRATE_ON_OSX TRUE)
set(MGMIGRATE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
elseif(UNIX)
set(MGMIGRATE_ON_LINUX TRUE)
set(MGMIGRATE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
endif()
# Set default instalation directory to '/usr'
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# '/usr' is a special case, for more details see:
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#special-cases
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "install dir" FORCE)
endif()
# ------------------------------------------------------------------------------
# --------------------------- EXTERNAL DEPENDENCIES ----------------------------
# ------------------------------------------------------------------------------
include(ExternalProject)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(PostgreSQL REQUIRED)
if(MGMIGRATE_ON_LINUX OR MGMIGRATE_ON_OSX)
# We build static libpq.a manually so we have a lib with minimal dependencies
set(POSTGRESQL_ROOT ${PROJECT_BINARY_DIR}/postgresql)
ExternalProject_Add(postgresql-proj
PREFIX ${POSTGRESQL_ROOT}
INSTALL_DIR ${POSTGRESQL_ROOT}
URL https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
CONFIGURE_COMMAND ""
BUILD_COMMAND unset MAKEFLAGS && unset MFLAGS && unset MAKELEVEL && ${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-libpq.py <SOURCE_DIR> <INSTALL_DIR>
INSTALL_COMMAND "")
set(MGMIGRATE_POSTGRESQL_LIBRARIES ${POSTGRESQL_ROOT}/libpq.a ${POSTGRESQL_ROOT}/libpgcommon.a ${POSTGRESQL_ROOT}/libpgport.a)
endif()
if(MGMIGRATE_ON_WINDOWS)
set(GFLAGS_LIB_SUFFIX "_static")
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic")
elseif(MGMIGRATE_ON_LINUX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
# Setup gflags
set(GFLAGS_ROOT ${PROJECT_BINARY_DIR}/gflags)
ExternalProject_Add(gflags-proj
PREFIX ${GFLAGS_ROOT}
INSTALL_DIR ${GFLAGS_ROOT}
GIT_REPOSITORY https://github.com/gflags/gflags.git
GIT_TAG v2.2.2
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
set(GFLAGS_INCLUDE_DIR ${GFLAGS_ROOT}/include)
set(GFLAGS_LIBRARY_PATH ${GFLAGS_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gflags${GFLAGS_LIB_SUFFIX}.a)
set(GFLAGS_DEBUG_LIBRARY_PATH ${GFLAGS_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gflags${GFLAGS_LIB_SUFFIX}_debug.a)
add_library(gflags STATIC IMPORTED)
set_target_properties(gflags PROPERTIES
IMPORTED_LOCATION "${GFLAGS_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GFLAGS_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(gflags gflags-proj)
# Setup glog
set(GLOG_ROOT ${PROJECT_BINARY_DIR}/glog)
ExternalProject_Add(glog-proj
PREFIX ${GLOG_ROOT}
INSTALL_DIR ${GLOG_ROOT}
GIT_REPOSITORY https://github.com/google/glog.git
GIT_TAG v0.5.0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_SHARED_LIBS=OFF"
DEPENDS gflags-proj)
set(GLOG_INCLUDE_DIR ${GLOG_ROOT}/include)
set(GLOG_LIBRARY_PATH ${GLOG_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}glog.a)
set(GLOG_DEBUG_LIBRARY_PATH ${GLOG_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}glogd.a)
add_library(glog STATIC IMPORTED)
set_target_properties(glog PROPERTIES
IMPORTED_LOCATION "${GLOG_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GLOG_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(glog glog-proj)
if(MGMIGRATE_ON_OSX)
set(MGMIGRATE_MGCLIENT_OPENSSL_ROOTDIR_FLAG "-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}")
endif()
# Setup mgclient
set(MG_CLIENT_ROOT ${PROJECT_BINARY_DIR}/mgclient)
ExternalProject_Add(mgclient-proj
PREFIX ${MG_CLIENT_ROOT}
INSTALL_DIR ${MG_CLIENT_ROOT}
GIT_TAG v1.2.1
GIT_REPOSITORY https://github.com/memgraph/mgclient.git
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
${MGMIGRATE_MGCLIENT_OPENSSL_ROOTDIR_FLAG}
"-DBUILD_TESTING=OFF")
set(MG_CLIENT_INCLUDE_DIR ${MG_CLIENT_ROOT}/include)
set(MG_CLIENT_LIBRARY_PATH ${MG_CLIENT_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}mgclient.a)
add_library(mgclient STATIC IMPORTED)
set_target_properties(mgclient PROPERTIES
IMPORTED_LOCATION "${MG_CLIENT_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${OPENSSL_LIBRARIES}")
add_dependencies(mgclient mgclient-proj)
# Setup pqxx
# Note: there is package libpqxx-dev, outdated and not compatible with C++17
set(PQXX_ROOT ${PROJECT_BINARY_DIR}/pqxx)
ExternalProject_Add(pqxx-proj
PREFIX ${PQXX_ROOT}
INSTALL_DIR ${PQXX_ROOT}
GIT_REPOSITORY https://github.com/jtv/libpqxx.git
GIT_TAG 7.6.0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_SHARED_LIBS=OFF"
"-DBUILD_TEST=OFF")
set(PQXX_INCLUDE_DIR ${PQXX_ROOT}/include)
set(PQXX_LIBRARY_PATH ${PQXX_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}pqxx.a)
add_library(pqxx STATIC IMPORTED)
set_target_properties(pqxx PROPERTIES
IMPORTED_LOCATION "${PQXX_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${OPENSSL_LIBRARIES}")
add_dependencies(pqxx pqxx-proj)
include_directories(${PQXX_INCLUDE_DIR})
if(MGMIGRATE_ON_OSX)
set(MGMIGRATE_MYSQL_CONN_OPENSSL_ROOTDIR_FLAG "-DWITH_SSL=${OPENSSL_ROOT_DIR}")
endif()
# Setup MySQL Connector/C++
set(MYSQL_CONN_ROOT ${PROJECT_BINARY_DIR}/mysqlconnector)
ExternalProject_Add(mysqlconnector-proj
PREFIX ${MYSQL_CONN_ROOT}
INSTALL_DIR ${MYSQL_CONN_ROOT}
GIT_REPOSITORY https://github.com/mysql/mysql-connector-cpp
GIT_TAG 8.0.26
PATCH_COMMAND PATCH_COMMAND git reset --hard && git apply --reject --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/mysqlconnector.patch
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_STATIC=ON"
${MGMIGRATE_MYSQL_CONN_OPENSSL_ROOTDIR_FLAG}
"-DBUILD_TEST=OFF")
set(MYSQL_CONN_INCLUDE_DIR ${MYSQL_CONN_ROOT}/include)
set(MYSQL_CONN_LIBRARY_PATH ${MYSQL_CONN_ROOT}/lib64/${MGMIGRATE_FIND_LIBRARY_PREFIXES}mysqlcppconn8-static.a)
set(MYSQL_CONN_DEBUG_LIBRARY_PATH ${MYSQL_CONN_ROOT}/lib64/debug/${MGMIGRATE_FIND_LIBRARY_PREFIXES}mysqlcppconn8-static.a)
add_library(mysqlconnector STATIC IMPORTED)
set_target_properties(mysqlconnector PROPERTIES
IMPORTED_LOCATION "${MYSQL_CONN_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${MYSQL_CONN_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${OPENSSL_LIBRARIES};${THREADS_LIBRARIES}")
add_dependencies(mysqlconnector mysqlconnector-proj)
include_directories(${MYSQL_CONN_INCLUDE_DIR})
# Setup gtest
set(GTEST_ROOT ${PROJECT_BINARY_DIR}/gtest)
ExternalProject_Add(gtest-proj
PREFIX ${GTEST_ROOT}
INSTALL_DIR ${GTEST_ROOT}
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
set(GTEST_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gtest.a)
set(GTEST_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gtestd.a)
add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES
IMPORTED_LOCATION "${GTEST_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GTEST_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(gtest gtest-proj)
set(GTEST_MAIN_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gtest_main.a)
set(GTEST_MAIN_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gtest_maind.a)
add_library(gtest-main STATIC IMPORTED)
set_target_properties(gtest-main PROPERTIES
IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GTEST_MAIN_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(gtest-main gtest-proj)
# Setup gmock
set(GMOCK_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gmock.a)
set(GMOCK_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gmockd.a)
add_library(gmock STATIC IMPORTED)
set_target_properties(gmock PROPERTIES
IMPORTED_LOCATION "${GMOCK_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GMOCK_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(gmock gtest-proj)
set(GMOCK_MAIN_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gmock_main.a)
set(GMOCK_MAIN_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${MGMIGRATE_FIND_LIBRARY_PREFIXES}gmock_maind.a)
add_library(gmock-main STATIC IMPORTED)
set_target_properties(gmock-main PROPERTIES
IMPORTED_LOCATION "${GMOCK_MAIN_LIBRARY_PATH}"
IMPORTED_LOCATION_DEBUG "${GMOCK_MAIN_DEBUG_LIBRARY_PATH}"
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
add_dependencies(gmock-main gtest-proj)
# ------------------------------------------------------------------------------
add_subdirectory(src)
add_subdirectory(tests)