-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional static libraries building #64
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
[submodule "external/monero-project"] | ||
path = external/monero-project | ||
url = https://github.com/woodser/monero | ||
url = https://github.com/nsec1/monero.git | ||
branch = fixIncludePaths | ||
[submodule "external/boost"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this further, I'm wondering if we should checkout these submodules as part of the monero-cpp project, to be generally available within that project, or if they're only necessary in the way we're building monero-java? monero-ts, for example, does not require these submodules to be checked out, and I wouldn't want them to interfere with the build in that project. But I could understand the argument to make these generally available in monero-cpp for other build setups. Curious to get your thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed your suggestion: woodser/monero-java#105 (comment) |
||
path = external/boost | ||
url = https://github.com/boostorg/boost.git | ||
[submodule "external/openssl"] | ||
path = external/openssl | ||
url = https://github.com/openssl/openssl | ||
[submodule "external/libsodium"] | ||
path = external/libsodium | ||
url = https://github.com/jedisct1/libsodium.git | ||
[submodule "external/libexpat"] | ||
path = external/libexpat | ||
url = https://github.com/libexpat/libexpat.git | ||
[submodule "external/unbound"] | ||
path = external/unbound | ||
url = https://github.com/NLnetLabs/unbound.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,17 @@ set(BUILD_SAMPLE OFF) | |
set(BUILD_SCRATCHPAD OFF) | ||
set(BUILD_TESTS OFF) | ||
|
||
option(STATIC "Build using static libraries") | ||
if(STATIC) | ||
if(WIN32) | ||
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||
else() | ||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||
endif() | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZMQ_STATIC") | ||
endif() | ||
|
||
|
||
################### | ||
# monero-project | ||
################### | ||
|
@@ -78,7 +89,11 @@ set(LibUSB_LIBRARIES ${usb_LIBRARY}) | |
set(Boost_NO_BOOST_CMAKE 1) | ||
set(Boost_USE_MULTITHREADED ON) | ||
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS chrono date_time filesystem program_options regex serialization wserialization system thread) | ||
message(STATUS "Using Boost include dir at ${Boost_INCLUDE_DIR}") | ||
if(Boost_FOUND) | ||
message(STATUS "Using Boost include dir at ${Boost_INCLUDE_DIR}") | ||
message(STATUS "Using Boost lib version: ${Boost_LIB_VERSION}") | ||
message(STATUS "Using Boost libs: ${Boost_LIBRARIES}") | ||
endif() | ||
|
||
############ | ||
# OpenSSL | ||
|
@@ -95,7 +110,10 @@ if (APPLE AND NOT IOS) | |
endif() | ||
|
||
find_package(OpenSSL REQUIRED) | ||
message(STATUS "Using OpenSSL include dir at ${OPENSSL_INCLUDE_DIR}") | ||
if(OPENSSL_FOUND) | ||
message(STATUS "Using OpenSSL include dir at ${OPENSSL_INCLUDE_DIR}") | ||
message(STATUS "Using OpenSSL libs: ${OPENSSL_LIBRARIES}") | ||
endif() | ||
|
||
if(STATIC AND NOT IOS) | ||
if(UNIX) | ||
|
@@ -112,22 +130,34 @@ endif() | |
############ | ||
|
||
find_library(SODIUM_LIBRARY sodium REQUIRED) | ||
message(STATUS "Using libsodium library at ${SODIUM_LIBRARY}") | ||
if(SODIUM_LIBRARY) | ||
message(STATUS "Using libsodium library at ${SODIUM_LIBRARY}") | ||
find_path(SODIUM_INCLUDE_PATH sodium/crypto_verify_32.h) | ||
if (SODIUM_INCLUDE_PATH) | ||
message(STATUS "SODIUM_INCLUDE_PATH: ${SODIUM_INCLUDE_PATH}") | ||
else() | ||
message(FATAL_ERROR "Could not find required sodium/crypto_verify_32.h") | ||
endif() | ||
endif() | ||
|
||
|
||
############ | ||
# HIDAPI | ||
############ | ||
|
||
if(APPLE) | ||
include_directories(SYSTEM /usr/include/malloc) | ||
if(POLICY CMP0042) | ||
cmake_policy(SET CMP0042 NEW) | ||
option(USE_DEVICE_TREZOR "Trezor hardware wallet suport" ON) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again wondering if we can skip this check and assume that support is Would be better to be able to support these dependencies anyway. |
||
if (USE_DEVICE_TREZOR) | ||
if(APPLE) | ||
include_directories(SYSTEM /usr/include/malloc) | ||
if(POLICY CMP0042) | ||
cmake_policy(SET CMP0042 NEW) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
find_package(HIDAPI REQUIRED) | ||
message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}") | ||
add_definitions(-DHAVE_HIDAPI) | ||
find_package(HIDAPI REQUIRED) | ||
message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}") | ||
add_definitions(-DHAVE_HIDAPI) | ||
endif() | ||
|
||
############# | ||
# Monero | ||
|
@@ -200,10 +230,6 @@ add_library(cryptonote_core STATIC IMPORTED) | |
set_target_properties(cryptonote_core PROPERTIES IMPORTED_LOCATION | ||
${MONERO_PROJECT_BUILD}/src/cryptonote_core/libcryptonote_core.a) | ||
|
||
add_library(cryptonote_protocol STATIC IMPORTED) | ||
set_target_properties(cryptonote_protocol PROPERTIES IMPORTED_LOCATION | ||
${MONERO_PROJECT_BUILD}/src/cryptonote_protocol/libcryptonote_protocol.a) | ||
|
||
add_library(cryptonote_basic STATIC IMPORTED) | ||
set_target_properties(cryptonote_basic PROPERTIES IMPORTED_LOCATION | ||
${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_basic.a) | ||
|
@@ -280,7 +306,14 @@ set( | |
) | ||
|
||
if (BUILD_LIBRARY) | ||
add_library(monero-cpp SHARED ${LIBRARY_SRC_FILES}) | ||
|
||
if(STATIC) | ||
set(BUILD_SHARED_LIBS OFF) | ||
else() | ||
set(BUILD_SHARED_LIBS ON) | ||
endif() | ||
|
||
add_library(monero-cpp ${LIBRARY_SRC_FILES}) | ||
|
||
target_include_directories(monero-cpp PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
|
@@ -294,12 +327,10 @@ if (BUILD_LIBRARY) | |
"${MONERO_PROJECT_SRC}/wallet/api" | ||
"${MONERO_PROJECT_SRC}/hardforks" | ||
"${MONERO_PROJECT_SRC}/crypto" | ||
"${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/" | ||
${SODIUM_INCLUDE_PATH} | ||
${Protobuf_INCLUDE_DIR} | ||
${Boost_INCLUDE_DIR} | ||
${OPENSSL_INCLUDE_DIR} | ||
external/libsodium/include/sodium | ||
external/openssl-sdk/include | ||
${HIDAPI_INCLUDE_DIR} | ||
${UNBOUND_INCLUDE_DIR} | ||
) | ||
|
@@ -312,7 +343,6 @@ if (BUILD_LIBRARY) | |
unbound | ||
easylogging | ||
cryptonote_core | ||
cryptonote_protocol | ||
cryptonote_basic | ||
cryptonote_format_utils_basic | ||
mnemonics | ||
|
@@ -388,12 +418,10 @@ if (BUILD_SAMPLE) | |
"${MONERO_PROJECT_SRC}/wallet/api" | ||
"${MONERO_PROJECT_SRC}/hardforks" | ||
"${MONERO_PROJECT_SRC}/crypto" | ||
"${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/" | ||
${SODIUM_INCLUDE_PATH} | ||
${Protobuf_INCLUDE_DIR} | ||
${Boost_INCLUDE_DIR} | ||
${OPENSSL_INCLUDE_DIR} | ||
external/libsodium/include/sodium | ||
external/openssl-sdk/include | ||
${HIDAPI_INCLUDE_DIR} | ||
${UNBOUND_INCLUDE_DIR} | ||
) | ||
|
@@ -405,7 +433,6 @@ if (BUILD_SAMPLE) | |
lmdb | ||
easylogging | ||
cryptonote_core | ||
cryptonote_protocol | ||
cryptonote_basic | ||
cryptonote_format_utils_basic | ||
mnemonics | ||
|
@@ -460,12 +487,10 @@ if (BUILD_SCRATCHPAD) | |
"${MONERO_PROJECT_SRC}/wallet/api" | ||
"${MONERO_PROJECT_SRC}/hardforks" | ||
"${MONERO_PROJECT_SRC}/crypto" | ||
"${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/" | ||
${SODIUM_INCLUDE_PATH} | ||
${Protobuf_INCLUDE_DIR} | ||
${Boost_INCLUDE_DIR} | ||
${OPENSSL_INCLUDE_DIR} | ||
external/libsodium/include/sodium | ||
external/openssl-sdk/include | ||
${HIDAPI_INCLUDE_DIR} | ||
${UNBOUND_INCLUDE_DIR} | ||
) | ||
|
@@ -477,7 +502,6 @@ if (BUILD_SCRATCHPAD) | |
lmdb | ||
easylogging | ||
cryptonote_core | ||
cryptonote_protocol | ||
cryptonote_basic | ||
cryptonote_format_utils_basic | ||
mnemonics | ||
|
@@ -532,12 +556,10 @@ if (BUILD_TESTS) | |
"${MONERO_PROJECT_SRC}/wallet/api" | ||
"${MONERO_PROJECT_SRC}/hardforks" | ||
"${MONERO_PROJECT_SRC}/crypto" | ||
"${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/" | ||
${SODIUM_INCLUDE_PATH} | ||
${Protobuf_INCLUDE_DIR} | ||
${Boost_INCLUDE_DIR} | ||
${OPENSSL_INCLUDE_DIR} | ||
external/libsodium/include/sodium | ||
external/openssl-sdk/include | ||
${HIDAPI_INCLUDE_DIR} | ||
${UNBOUND_INCLUDE_DIR} | ||
) | ||
|
@@ -549,7 +571,6 @@ if (BUILD_TESTS) | |
lmdb | ||
easylogging | ||
cryptonote_core | ||
cryptonote_protocol | ||
cryptonote_basic | ||
cryptonote_format_utils_basic | ||
mnemonics | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,41 +162,9 @@ For example, [monero-java](https://github.com/woodser/monero-java) compiles this | |
### Linux | ||
|
||
1. Clone the project repository if applicable: `git clone --recurse-submodules https://github.com/woodser/monero-cpp.git` | ||
2. Update dependencies: `sudo apt update && sudo apt install build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz nettle-dev libevent-dev` | ||
3. Follow instructions to install [unbound](https://unbound.docs.nlnetlabs.nl/en/latest/getting-started/installation.html) for Linux to your home directory (e.g. `~/unbound-1.19.0`). | ||
|
||
For example, install expat: | ||
``` | ||
cd ~ | ||
wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.bz2 | ||
tar -xf expat-2.4.8.tar.bz2 | ||
sudo rm expat-2.4.8.tar.bz2 | ||
cd expat-2.4.8 | ||
./configure --enable-static --disable-shared | ||
make | ||
sudo make install | ||
cd ../ | ||
``` | ||
|
||
For example, install unbound: | ||
``` | ||
cd ~ | ||
wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.19.0.tar.gz | ||
tar xzf unbound-1.19.0.tar.gz | ||
sudo apt update | ||
sudo apt install -y build-essential | ||
sudo apt install -y libssl-dev | ||
sudo apt install -y libexpat1-dev | ||
sudo apt-get install -y bison | ||
sudo apt-get install -y flex | ||
cd unbound-1.19.0 | ||
./configure --with-libexpat=/usr --with-ssl=/usr --enable-static-exe | ||
make | ||
sudo make install | ||
cd ../ | ||
``` | ||
4. Build monero-project, located as a submodule at ./external/monero-project. Install [dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system, then build with: `make release-static -j8` | ||
5. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: `./bin/build_libmonero_cpp.sh` | ||
2. Update dependencies: `sudo apt update && sudo apt install build-essential autoconf libtool cmake pkg-config libzmq3-dev libunwind8-dev liblzma-dev libreadline6-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev python3 ccache doxygen graphviz nettle-dev libevent-dev bison flex` | ||
3. Build monero-project, located as a submodule at ./external/monero-project. Install [dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system, then build with: `make release-static -j8` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must admit, it's nice to see that unbound doesn't need to be installed separately. |
||
4. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: `./bin/build_libmonero_cpp.sh` | ||
|
||
### macOS | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
#!/bin/sh | ||
|
||
export HOST_NCORES=${HOST_NCORES-$(nproc 2>/dev/null || shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)} | ||
BUILD_DIR="$(pwd)/build" | ||
INSTALL_DIR="$BUILD_DIR/install" | ||
export CMAKE_PREFIX_PATH=$INSTALL_DIR${CMAKE_PREFIX_PATH+:$CMAKE_PREFIX_PATH} | ||
USE_DEVICE_TREZOR=${USE_DEVICE_TREZOR-ON} | ||
echo "HOST_NCORES=$HOST_NCORES in $0" | ||
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH in $0" | ||
echo "USE_DEVICE_TREZOR=$USE_DEVICE_TREZOR in $0" | ||
|
||
[ -d $INSTALL_DIR ] || mkdir -p $INSTALL_DIR | ||
|
||
(cd external/boost && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just need to ensure these additions don't interfere with the build process in monero-ts. |
||
./bootstrap.sh --prefix=$INSTALL_DIR && ./b2 -j$HOST_NCORES \ | ||
--with-chrono \ | ||
--with-date_time \ | ||
--with-filesystem \ | ||
--with-program_options \ | ||
--with-regex \ | ||
--with-serialization \ | ||
--with-system \ | ||
--with-thread \ | ||
--with-locale \ | ||
link=static \ | ||
cxxflags=-fPIC cflags=-fPIC \ | ||
install) && \ | ||
|
||
(cd external/openssl && \ | ||
./Configure no-apps no-afalgeng no-docs no-ui-console no-shared --prefix=$INSTALL_DIR --libdir=lib && \ | ||
make -j$HOST_NCORES && make install) && \ | ||
|
||
(cd external/libsodium && \ | ||
./configure --enable-shared=no --with-pic=yes --prefix=$INSTALL_DIR && \ | ||
make -j$HOST_NCORES && make check && make install) && \ | ||
|
||
(cd external/libexpat/expat && \ | ||
./buildconf.sh && ./configure --prefix=$INSTALL_DIR --enable-static --disable-shared --with-pic=yes && \ | ||
make -j$HOST_NCORES install) && \ | ||
|
||
(cd external/unbound && \ | ||
./configure --with-ssl=$INSTALL_DIR --prefix=$INSTALL_DIR --with-libexpat=$INSTALL_DIR --enable-static-exe --enable-static --disable-shared --with-pic=yes && \ | ||
make -j$HOST_NCORES install) && \ | ||
|
||
# build monero-project dependencies | ||
cd ./external/monero-project/ || exit 1 | ||
git submodule update --init --force || exit 1 | ||
HOST_NCORES=$(nproc 2>/dev/null || shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1) | ||
|
||
if [[ "$OSTYPE" == "msys" ]]; then | ||
bit=$(getconf LONG_BIT) | ||
if [ "$bit" == "64" ]; then | ||
|
@@ -16,13 +58,20 @@ elif [[ "$OSTYPE" == "cygwin" ]]; then | |
exit 1 | ||
else | ||
# OS is not windows | ||
make release-static -j$HOST_NCORES || exit 1 | ||
MONERO_BUILD_DIR="build/release" | ||
test -d $MONERO_BUILD_DIR || mkdir -p $MONERO_BUILD_DIR | ||
(cd $MONERO_BUILD_DIR && \ | ||
cmake -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=Release \ | ||
-D OPENSSL_ROOT_DIR=$INSTALL_DIR \ | ||
-D USE_DEVICE_TREZOR=$USE_DEVICE_TREZOR \ | ||
-D BOOST_IGNORE_SYSTEM_PATHS=ON \ | ||
../.. && make -j$HOST_NCORES wallet) || exit 1 | ||
fi | ||
cd ../../ | ||
|
||
# build libmonero-cpp shared library | ||
mkdir -p build && | ||
cd build && | ||
cmake .. && | ||
cmake -D USE_DEVICE_TREZOR=$USE_DEVICE_TREZOR -D OPENSSL_ROOT_DIR=$INSTALL_DIR $@ .. && | ||
cmake --build . && | ||
make . | ||
make -j$HOST_NCORES . |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the change in your branch, "fix zmq and sodium include dirs search", be generally applied to monero-project and opened as a PR?
If so, the PR should be opened ASAP, and then I can include your PR as a customization in monero-project until it's merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
monero-project/monero#9504