Skip to content

Commit

Permalink
Preparation for building with shared boost (#2611)
Browse files Browse the repository at this point in the history
* Preparation for building with shared boost
Can be tested currently by ensuring `-DBOOST_ROOT=<path_to_boost_root> -DNANO_SHARED_BOOST=ON` are set for cmake
This will also require you have locally built static boost 1.67+
added switch for shared/static linkage to bootstrap_boost.sh default to static

* tabs vs spaces

* Verbiage for clarity

* '-j n' switch for bootstrap_boost.sh

allows for multiple jobs to be built at once with b2
  • Loading branch information
Russel Waters committed Apr 18, 2020
1 parent 7b891ab commit 068f6d0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
74 changes: 71 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ execute_process(
option (CI_BUILD false)
set (CI_TEST 0 CACHE STRING "")

if(MSVC)
add_definitions(/MP)
endif()

set (CPACK_PACKAGE_VERSION_MAJOR "21")
set (CPACK_PACKAGE_VERSION_MINOR "0")
set (CPACK_PACKAGE_VERSION_PATCH "0")
Expand All @@ -43,7 +47,12 @@ else()
set (TAG_VERSION_STRING "V${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
endif()

set (CMAKE_INSTALL_RPATH "@executable_path/../Frameworks")
if (APPLE)
set (CMAKE_INSTALL_RPATH "@executable_path/../Frameworks;@executable_path/../boost/lib")
else()
set (CMAKE_INSTALL_RPATH "$ORIGIN/lib")
endif()

# Create all libraries and executables in the root binary dir
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

Expand Down Expand Up @@ -225,8 +234,24 @@ endif ()

include_directories (${CMAKE_SOURCE_DIR})

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
if (WIN32 AND NANO_TEST AND NANO_SHARED_BOOST)
message (SEND_ERROR
" Linking errors occur if NANO_SHARED_BOOST is used with tests on Windows"
" Disable NANO_SHARED_BOOST or NANO_TEST on Windows")
set(NANO_SHARED_BOOST)
endif()

set(NANO_SHARED_BOOST OFF CACHE BOOL "Build Nano with shared boost")

if (NANO_SHARED_BOOST)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_STATIC_RUNTIME OFF)
SET(Boost_NO_BOOST_CMAKE ON)
add_definitions( -DBOOST_ALL_DYN_LINK -DBoost_ALL_NO_LIB)
else()
set(Boost_USE_STATIC_LIBS ON)
endif()
set(Boost_USE_MULTITHREADED ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

Expand Down Expand Up @@ -521,6 +546,19 @@ if (NANO_GUI OR RAIBLOCKS_GUI)
install (DIRECTORY ${Qt5_DIR}/../../QtTest.framework DESTINATION Nano.app/Contents/Frameworks)
install (DIRECTORY ${Qt5_DIR}/../../QtWidgets.framework DESTINATION Nano.app/Contents/Frameworks)
install (FILES "${Qt5_DIR}/../../../plugins/platforms/libqcocoa.dylib" DESTINATION Nano.app/Contents/PlugIns/platforms)
if (NANO_SHARED_BOOST)
get_filename_component(Boost_LIB_DIR ${BOOST_ROOT}/lib ABSOLUTE)
install (FILES ${Boost_LIB_DIR}/libboost_log.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_filesystem.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_log_setup.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_regex.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_program_options.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_system.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_thread.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_date_time.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_chrono.dylib DESTINATION Nano.app/Contents/boost/lib)
install (FILES ${Boost_LIB_DIR}/libboost_atomic.dylib DESTINATION Nano.app/Contents/boost/lib)
endif()
if (NANO_POW_SERVER)
install (TARGETS nano_pow_server DESTINATION Nano.app/Contents/MacOS)
install (DIRECTORY ${PROJECT_SOURCE_DIR}/nano-pow-server/public DESTINATION Nano.app/Contents/MacOS)
Expand Down Expand Up @@ -549,6 +587,23 @@ if (NANO_GUI OR RAIBLOCKS_GUI)
get_filename_component (Qt5_bin_DIR ${Qt5_DIR}/../../../bin ABSOLUTE)
install (TARGETS nano_wallet DESTINATION .)
install (TARGETS nano_wallet_com DESTINATION .)
if (NANO_SHARED_BOOST)
foreach(boost_lib IN LISTS Boost_LIBRARIES)
if (${CMAKE_BUILD_TYPE} MATCHES "Rel")
string(REGEX MATCH "(.+/.*boost_[^-]+-.+-mt-x64.+\)(.lib|a)" boost_lib_name ${boost_lib})
set (boost_dll "${CMAKE_MATCH_1}.dll")
if (${boost_dll} MATCHES "boost")
install (FILES ${boost_dll} DESTINATION .)
endif()
else ()
string(REGEX MATCH "(.+/.*boost_[^-]+-.+-mt-.+-x64.+\)(.lib|a)" boost_lib_name ${boost_lib})
set (boost_dll "${CMAKE_MATCH_1}.dll")
if (${boost_dll} MATCHES "boost")
install (FILES ${boost_dll} DESTINATION .)
endif()
endif()
endforeach(boost_lib)
endif()
if (NANO_POW_SERVER)
install (TARGETS nano_pow_server DESTINATION .)
install (DIRECTORY ${PROJECT_SOURCE_DIR}/nano-pow-server/public DESTINATION .)
Expand All @@ -565,6 +620,19 @@ if (NANO_GUI OR RAIBLOCKS_GUI)
install(TARGETS nano_wallet
RUNTIME DESTINATION .
)
if (NANO_SHARED_BOOST)
get_filename_component(Boost_LIB_DIR ${BOOST_ROOT}/lib ABSOLUTE)
install (FILES ${Boost_LIB_DIR}/libboost_log.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_filesystem.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_log_setup.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_regex.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_program_options.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_system.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_thread.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_date_time.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_chrono.so.${Boost_VERSION_STRING} DESTINATION ./lib)
install (FILES ${Boost_LIB_DIR}/libboost_atomic.so.${Boost_VERSION_STRING} DESTINATION ./lib)
endif()
if (NANO_POW_SERVER)
install (TARGETS nano_pow_server DESTINATION .)
install (DIRECTORY ${PROJECT_SOURCE_DIR}/nano-pow-server/public DESTINATION .)
Expand Down
14 changes: 12 additions & 2 deletions util/build_prep/bootstrap_boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ buildArgs=()
useClang='false'
useLibCXX='false'
keepArchive='false'
LINK_TYPE=('link=static')
debugLevel=0
buildThreads=1
buildCArgs=()
buildCXXArgs=()
buildLDArgs=()
boostVersion='1.67'
while getopts 'hmcCkpvB:' OPT; do
while getopts 'hmscCkpvB:j:' OPT; do
case "${OPT}" in
h)
echo "Usage: bootstrap_boost.sh [-hmcCkpv] [-B <boostVersion>]"
echo " -h This help"
echo " -s Build Shared and static libs, default is static only"
echo " -m Build a minimal set of libraries needed for Nano"
echo " -j <threads> Number of threads to build with"
echo " -c Use Clang"
echo " -C Use libc++ when using Clang"
echo " -k Keep the downloaded archive file"
Expand All @@ -25,9 +29,15 @@ while getopts 'hmcCkpvB:' OPT; do
echo " -B <boostVersion> Specify version of Boost to build"
exit 0
;;
s)
LINK_TYPE+=('link=shared')
;;
m)
bootstrapArgs+=('--with-libraries=system,thread,log,filesystem,program_options')
;;
j)
buildThreads=${OPTARG}
;;
c)
useClang='true'
;;
Expand Down Expand Up @@ -126,7 +136,7 @@ tar xf "${BOOST_ARCHIVE}"

pushd "${BOOST_BASENAME}"
./bootstrap.sh "${bootstrapArgs[@]}"
./b2 -d${debugLevel} --prefix="${BOOST_ROOT}" link=static "${buildArgs[@]}" install
./b2 -d${debugLevel} -j${buildThreads} --prefix="${BOOST_ROOT}" ${LINK_TYPE[@]} "${buildArgs[@]}" install
popd

rm -rf "${BOOST_BASENAME}"
Expand Down

0 comments on commit 068f6d0

Please sign in to comment.