Skip to content

Commit

Permalink
Update CMake files to enable optional mongodb build
Browse files Browse the repository at this point in the history
  • Loading branch information
harrywong committed Jun 3, 2018
1 parent 0b87808 commit 2cddb84
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 61 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cmake_minimum_required( VERSION 3.5 )
# Defines everiToken library target.
project( EVT )

option(ENABLE_MONGO_DB_PLUGIN "Build the mongodb plugin" OFF)

enable_testing()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libraries/fc/CMakeModules")
Expand Down
8 changes: 7 additions & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ add_subdirectory(wallet_plugin)
add_subdirectory(wallet_api_plugin)
add_subdirectory(evt_plugin)
add_subdirectory(evt_api_plugin)
add_subdirectory(mongo_db_plugin)
add_subdirectory(bnet_plugin)

if(ENABLE_MONGO_DB_PLUGIN)
add_subdirectory(mongo_db_plugin)
set_target_properties(evt_plugin evt_api_plugin PROPERTIES COMPILE_DEFINITIONS "ENABLE_MONGODB")
else()
message("mongo_db_plugin not selected and will be omitted.")
endif()

# Forward variables to top level so packaging picks them up
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS} PARENT_SCOPE)
7 changes: 5 additions & 2 deletions plugins/evt_api_plugin/evt_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ evt_api_plugin::plugin_startup() {
app().get_plugin<http_plugin>().add_api({EVT_RO_CALL(get_domain, 200),
EVT_RO_CALL(get_group, 200),
EVT_RO_CALL(get_token, 200),
EVT_RO_CALL(get_account, 200),
EVT_RO_CALL(get_my_tokens, 200),
EVT_RO_CALL(get_account, 200)
});
#ifdef ENABLE_MONGODB
app().get_plugin<http_plugin>().add_api({EVT_RO_CALL(get_my_tokens, 200),
EVT_RO_CALL(get_my_domains, 200),
EVT_RO_CALL(get_my_groups, 200)
});
#endif
}

void
Expand Down
6 changes: 5 additions & 1 deletion plugins/evt_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ add_library( evt_plugin
${HEADERS} )

target_link_libraries( evt_plugin chain_plugin evt_chain appbase fc )
target_include_directories( evt_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../mongo_db_plugin/include" )
target_include_directories( evt_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

if(ENABLE_MONGO_DB_PLUGIN)
target_include_directories( evt_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../mongo_db_plugin/include" )
endif()
5 changes: 4 additions & 1 deletion plugins/evt_plugin/evt_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

#include <evt/evt_plugin/evt_plugin.hpp>
#include <evt/mongo_db_plugin/mongo_db_plugin.hpp>
#include <evt/chain/types.hpp>
#include <evt/chain/token_database.hpp>

Expand Down Expand Up @@ -104,6 +103,8 @@ read_only::get_account(const get_account_params& params) {
return var;
}

#ifdef ENABLE_MONGODB

namespace __internal {

static const char* EVERIWALLET_AUTH_STRING = "everiWallet";
Expand Down Expand Up @@ -160,6 +161,8 @@ read_only::get_my_groups(const get_my_params& params) {
return result;
}

#endif

} // namespace evt_apis

} // namespace evt
11 changes: 11 additions & 0 deletions plugins/evt_plugin/include/evt/evt_plugin/evt_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
#pragma once
#include <evt/chain_plugin/chain_plugin.hpp>
#ifdef ENABLE_MONGODB
#include <evt/mongo_db_plugin/mongo_db_plugin.hpp>
#endif

#include <appbase/application.hpp>
#include <evt/chain/asset.hpp>
Expand Down Expand Up @@ -59,6 +62,7 @@ class read_only {
};
fc::variant get_account(const get_account_params& params);

#ifdef ENABLE_MONGODB
struct get_my_params {
std::vector<std::string> signatures;
};
Expand All @@ -69,6 +73,7 @@ class read_only {
fc::variant get_my_tokens(const get_my_params& params);
fc::variant get_my_domains(const get_my_params& params);
fc::variant get_my_groups(const get_my_params& params);
#endif

private:
const controller& db_;
Expand All @@ -87,7 +92,11 @@ class read_write {

class evt_plugin : public plugin<evt_plugin> {
public:
#ifndef ENABLE_MONGODB
APPBASE_PLUGIN_REQUIRES((chain_plugin))
#else
APPBASE_PLUGIN_REQUIRES((chain_plugin)(mongo_db_plugin))
#endif

evt_plugin();
virtual ~evt_plugin();
Expand All @@ -111,4 +120,6 @@ FC_REFLECT(evt::evt_apis::read_only::get_domain_params, (name));
FC_REFLECT(evt::evt_apis::read_only::get_group_params, (name));
FC_REFLECT(evt::evt_apis::read_only::get_token_params, (domain)(name));
FC_REFLECT(evt::evt_apis::read_only::get_account_params, (name));
#ifdef ENABLE_MONGODB
FC_REFLECT(evt::evt_apis::read_only::get_my_params, (signatures));
#endif
106 changes: 51 additions & 55 deletions plugins/mongo_db_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
if(BUILD_MONGO_DB_PLUGIN)
file(GLOB HEADERS "include/evt/mongo_db_plugin/*.hpp")
add_library( mongo_db_plugin
mongo_db_plugin.cpp
evt_interpreter.cpp
wallet_query.cpp
${HEADERS} )
file(GLOB HEADERS "include/evt/mongo_db_plugin/*.hpp")
add_library( mongo_db_plugin
mongo_db_plugin.cpp
evt_interpreter.cpp
wallet_query.cpp
${HEADERS} )

find_package(libbsonc REQUIRED)
message(STATUS "Found bsonc library: ${LIBBSONC_LIBRARIES}")
find_package(libbsonc REQUIRED)
message(STATUS "Found bsonc library: ${LIBBSONC_LIBRARIES}")

find_package(libmongoc REQUIRED)
message(STATUS "Found mongoc library: ${LIBMONGOC_LIBRARIES}")
find_package(libmongoc REQUIRED)
message(STATUS "Found mongoc library: ${LIBMONGOC_LIBRARIES}")

if (LIBMONGOC_FOUND AND LIBBSONC_FOUND)
if (LIBMONGOC_FOUND AND LIBBSONC_FOUND)

# EVT has no direct dependencies on libmongoc but its static libraries
# will need to be present at runtime for the C++ libraries we use:
# libbsoncxx & libmongocxx (both from github.com/mongodb/mongo-cxx-driver)
# EVT has no direct dependencies on libmongoc but its static libraries
# will need to be present at runtime for the C++ libraries we use:
# libbsoncxx & libmongocxx (both from github.com/mongodb/mongo-cxx-driver)

find_package(libbsoncxx REQUIRED)
message(STATUS "Found bsoncxx headers: ${LIBBSONCXX_INCLUDE_DIR}")
message(STATUS "Found bsoncxx library: ${LIBBSONCXX_LIBRARIES}")
find_package(libbsoncxx REQUIRED)
message(STATUS "Found bsoncxx headers: ${LIBBSONCXX_INCLUDE_DIR}")
message(STATUS "Found bsoncxx library: ${LIBBSONCXX_LIBRARIES}")

find_package(libmongocxx REQUIRED)
message(STATUS "Found mongocxx headers: ${LIBMONGOCXX_INCLUDE_DIR}")
message(STATUS "Found mongocxx library: ${LIBMONGOCXX_LIBRARIES}")
else()
message("Could NOT find MongoDB. mongo_db_plugin with MongoDB support will not be included.")
# sudo apt-get install pkg-config libssl-dev libsasl2-dev
# wget https://github.com/mongodb/mongo-c-driver/releases/download/1.8.0/mongo-c-driver-1.8.0.tar.gz
# tar xzf mongo-c-driver-1.8.0.tar.gz
# cd mongo-c-driver-1.8.0
# ./configure --disable-automatic-init-and-cleanup --enable-static
# make
# sudo make install
#
# git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
# cd mongo-cxx-driver/build
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF ..
# sudo make EP_mnmlstc_core
# make
# sudo make install
#
# sudo apt-get install mongodb
endif()
find_package(libmongocxx REQUIRED)
message(STATUS "Found mongocxx headers: ${LIBMONGOCXX_INCLUDE_DIR}")
message(STATUS "Found mongocxx library: ${LIBMONGOCXX_LIBRARIES}")
else()
message("Could NOT find MongoDB. mongo_db_plugin with MongoDB support will not be included.")
# sudo apt-get install pkg-config libssl-dev libsasl2-dev
# wget https://github.com/mongodb/mongo-c-driver/releases/download/1.8.0/mongo-c-driver-1.8.0.tar.gz
# tar xzf mongo-c-driver-1.8.0.tar.gz
# cd mongo-c-driver-1.8.0
# ./configure --disable-automatic-init-and-cleanup --enable-static
# make
# sudo make install
#
# git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
# cd mongo-cxx-driver/build
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF ..
# sudo make EP_mnmlstc_core
# make
# sudo make install
#
# sudo apt-get install mongodb
endif()

target_include_directories(mongo_db_plugin
PRIVATE ${LIBMONGOCXX_INCLUDE_DIR} ${LIBBSONCXX_INCLUDE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../chain_interface/include"
)
target_include_directories(mongo_db_plugin
PRIVATE ${LIBMONGOCXX_INCLUDE_DIR} ${LIBBSONCXX_INCLUDE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../chain_interface/include"
)

target_compile_definitions(mongo_db_plugin
PRIVATE ${LIBMONGOCXX_DEFINITIONS} ${LIBBSONCXX_DEFINITIONS}
)
target_compile_definitions(mongo_db_plugin
PRIVATE ${LIBMONGOCXX_DEFINITIONS} ${LIBBSONCXX_DEFINITIONS}
)

target_link_libraries(mongo_db_plugin
PUBLIC chain_plugin evt_chain appbase fc
${LIBBSONC_LIBRARIES} ${LIBMONGOC_LIBRARIES}
${LIBBSONCXX_LIBRARIES} ${LIBMONGOCXX_LIBRARIES}
)
else()
message("mongo_db_plugin not selected and will be omitted.")
endif()
target_link_libraries(mongo_db_plugin
PUBLIC chain_plugin evt_chain appbase fc
${LIBBSONC_LIBRARIES} ${LIBMONGOC_LIBRARIES}
${LIBBSONCXX_LIBRARIES} ${LIBMONGOCXX_LIBRARIES}
)
2 changes: 1 addition & 1 deletion programs/evtd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ target_link_libraries(evtd
PRIVATE -Wl,${whole_archive_flag} bnet_plugin -Wl,${no_whole_archive_flag}
)

if(BUILD_MONGO_DB_PLUGIN)
if(ENABLE_MONGO_DB_PLUGIN)
target_link_libraries( evtd
PRIVATE -Wl,${whole_archive_flag} mongo_db_plugin -Wl,${no_whole_archive_flag} )
endif()
Expand Down

0 comments on commit 2cddb84

Please sign in to comment.