From 082df7ab4a77c34685ec9c146931b5a5f176cd75 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Mon, 26 Oct 2020 17:02:22 -0500 Subject: [PATCH] Allow build of dynamic libraries In order to support dynamically linked nodes based on Graphene, add support for building dynamic libraries for the core Graphene modules: chain, db, protocol, net, and utilities. --- CMakeLists.txt | 6 ++++-- libraries/chain/CMakeLists.txt | 16 ++++++++++------ libraries/db/CMakeLists.txt | 15 ++++++++++++++- libraries/net/CMakeLists.txt | 6 +++++- libraries/protocol/CMakeLists.txt | 7 ++++++- libraries/utilities/CMakeLists.txt | 13 ++++++++++--- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index debcd378..82a21c3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ set( CUSTOM_URL_SCHEME "gcs" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) set( CMAKE_CXX_STANDARD 14 ) +set( GRAPHENE_BUILD_DYNAMIC_LIBRARIES OFF CACHE BOOL + "Whether to build dynamic libraries instead of static. Applies only to chain, db, protocol, net, and utilities" ) + # http://stackoverflow.com/a/18369825 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) @@ -162,8 +165,7 @@ endif() add_subdirectory( libraries ) - -set(BUILD_BITSHARES_PROGRAMS TRUE CACHE BOOL "Build bitshares executables (witness node, cli wallet, etc)") +set(BUILD_PEERPLAYS_PROGRAMS TRUE CACHE BOOL "Build peerplays executables (witness node, cli wallet, etc)") add_subdirectory( programs ) set(BUILD_BITSHARES_TESTS TRUE CACHE BOOL "Build bitshares unit tests") diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 8d13885a..3319aedf 100755 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -19,12 +19,16 @@ else( GRAPHENE_DISABLE_UNITY_BUILD ) message( STATUS "Graphene database unity build enabled" ) endif( GRAPHENE_DISABLE_UNITY_BUILD ) -## SORT .cpp by most likely to change / break compile -add_library( graphene_chain - ${CPP_FILES} - ${HEADERS} - "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" - ) +set( GRAPHENE_CHAIN_FILES + ${CPP_FILES} + ${HEADERS} + "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" + ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_chain ${GRAPHENE_CHAIN_FILES} ) +else() + add_library( graphene_chain SHARED ${GRAPHENE_CHAIN_FILES} ) +endif() add_dependencies( graphene_chain build_hardfork_hpp ) target_link_libraries( graphene_chain fc graphene_db graphene_protocol ) diff --git a/libraries/db/CMakeLists.txt b/libraries/db/CMakeLists.txt index b0899d86..8ec6fea1 100644 --- a/libraries/db/CMakeLists.txt +++ b/libraries/db/CMakeLists.txt @@ -1,5 +1,18 @@ file(GLOB HEADERS "include/graphene/db/*.hpp") -add_library( graphene_db undo_database.cpp index.cpp object_database.cpp ${HEADERS} ) + +set( GRAPHENE_DB_FILES + undo_database.cpp + index.cpp + object_database.cpp + ${HEADERS} + ) + +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_db ${GRAPHENE_DB_FILES} ) +else() + add_library( graphene_db SHARED ${GRAPHENE_DB_FILES} ) +endif() + target_link_libraries( graphene_db graphene_protocol fc ) target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/net/CMakeLists.txt b/libraries/net/CMakeLists.txt index 806864af..2dcc2c78 100644 --- a/libraries/net/CMakeLists.txt +++ b/libraries/net/CMakeLists.txt @@ -9,7 +9,11 @@ set(SOURCES node.cpp message.cpp message_oriented_connection.cpp) -add_library( graphene_net ${SOURCES} ${HEADERS} ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_net ${SOURCES} ${HEADERS} ) +else() + add_library( graphene_net SHARED ${SOURCES} ${HEADERS} ) +endif() target_link_libraries( graphene_net PUBLIC fc graphene_db graphene_protocol ) diff --git a/libraries/protocol/CMakeLists.txt b/libraries/protocol/CMakeLists.txt index a96e3bfe..8c05638f 100644 --- a/libraries/protocol/CMakeLists.txt +++ b/libraries/protocol/CMakeLists.txt @@ -42,7 +42,12 @@ list(APPEND SOURCES account.cpp ) -add_library( graphene_protocol ${SOURCES} ${HEADERS} ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_protocol ${SOURCES} ${HEADERS} ) +else() + add_library( graphene_protocol SHARED ${SOURCES} ${HEADERS} ) +endif() + target_link_libraries( graphene_protocol fc ) target_include_directories( graphene_protocol PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/utilities/CMakeLists.txt b/libraries/utilities/CMakeLists.txt index 98086b10..22decaf7 100644 --- a/libraries/utilities/CMakeLists.txt +++ b/libraries/utilities/CMakeLists.txt @@ -20,9 +20,16 @@ set(sources configure_file("${CMAKE_CURRENT_SOURCE_DIR}/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY) list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp") -add_library( graphene_utilities - ${sources} - ${HEADERS} ) +if (NOT ${GRAPHENE_BUILD_DYNAMIC_LIBRARIES}) + add_library( graphene_utilities + ${sources} + ${HEADERS} ) +else() + add_library( graphene_utilities SHARED + ${sources} + ${HEADERS} ) +endif() + target_link_libraries( graphene_utilities fc ) target_include_directories( graphene_utilities PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )