-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
66 lines (46 loc) · 2.62 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
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)
project(mongo-cxx-drivers LANGUAGES CXX)
# set mongo-c driver version, which are necessery for mongo-cxx drivers
set(MONGOC_DRIVER_VER "1.15.3")
# set mongodb drivers directory
set(MONGO_DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers)
# set mongo-cxx driver version
set(MONGOCXX_DRIVER_VER "r3.5.0")
# Set boost c++ libraries path
set(BOOST_ROOT "C:/boost_1_70_0")
# Varibles for connection to MongoDB
# How to secure MongoDB connections read here: https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89
# set path to ca file
set(CA_FILE_PATH "C:/mongossl/rootCA.pem")
# set path to pem file
set(PEM_FILE_PATH "C:/mongossl/mongodb.pem")
#set connection URI with ssl flag true
set(CONNECTION_URI "mongodb://localhost:27017/?ssl=true")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
# Find the mongodb drivers
find_package(MongoDB REQUIRED)
configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_SOURCE_DIR}/config.h")
include_directories(${MONGO_DRIVERS_DIR}/mongo-cxx-driver/include/bsoncxx/v_noabi
${MONGO_DRIVERS_DIR}/mongo-cxx-driver/include/mongocxx/v_noabi
${MONGO_DRIVERS_DIR}/mongo-c-driver/include/libbson-1.0
${MONGO_DRIVERS_DIR}/mongo-c-driver/include/libmongoc-1.0
${BOOST_ROOT})
# Populate a CMake variable with the sources
add_executable(test_mongocxx config.h
main.cpp)
target_link_libraries(test_mongocxx PUBLIC ${MONGO_DRIVERS_DIR}/mongo-c-driver/lib/bson-1.0.lib
${MONGO_DRIVERS_DIR}/mongo-c-driver/lib/mongoc-1.0.lib
${MONGO_DRIVERS_DIR}/mongo-cxx-driver/lib/bsoncxx.lib
${MONGO_DRIVERS_DIR}/mongo-cxx-driver/lib/mongocxx.lib)
if(WIN32)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/install" CACHE STRING "Install path prefix, prepended onto install directories" FORCE)
install(FILES ${MONGO_DRIVERS_DIR}/mongo-c-driver/bin/libbson-1.0.dll
${MONGO_DRIVERS_DIR}/mongo-c-driver/bin/libmongoc-1.0.dll
${MONGO_DRIVERS_DIR}/mongo-cxx-driver/bin/bsoncxx.dll
${MONGO_DRIVERS_DIR}/mongo-cxx-driver/bin/mongocxx.dll
${CMAKE_BINARY_DIR}/Debug/test_mongocxx.exe
DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()