Skip to content

eynhaender/libbitcoin-cmake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cmake-based Build Setup for libbitcoin v4

This repository provides a minimal, developer-friendly CMake build system for the four core Libbitcoin v4 projects:

  • libbitcoin-system
  • libbitcoin-database
  • libbitcoin-network
  • libbitcoin-node

The official Libbitcoin repositories use highly automated build scripts that support Linux, Windows, macOS and many architectures.
If you just want to run a node quickly and without hassle, use the official pre-configured repository:
https://github.com/libbitcoin/libbitcoin-node

This project is aimed at Linux developers who want:

  • Simple, transparent CMake builds
  • Easy debugging and code navigation in an IDE (tested with VS Code)
  • The ability to modify the Libbitcoin source code locally
  • Separate Release and Debug builds side-by-side
  • Full control over CPU extensions (SSE4.1, SHANI, AVX2, AVX512)

Requirements

The corresponding packages can be installed with the following command:

$ sudo apt install build-essential curl git autoconf automake pkg-config libtool

Directory Layout (recommended)

~/dev/
├─ libbitcoin-system/
├─ libbitcoin-database/
├─ libbitcoin-network/
├─ libbitcoin-node/
└─ libbitcoin-install/   ← common install prefix

Build order (due to dependencies):
system → database → network → node

Quickstart - Required files per project

Copy the original source trees from the official repositories and add the CMake files from this repository.

libbitcoin-system

libbitcoin-system/
├─ include/*            ← from the official project repo
├─ src/*
├─ test/*

├─ CMakeLists.txt       ← from this repo
├─ bitcoin-system.pc.in
└─ builds/config.h

The build setup for libbitcoin-system unfortunately contains two hacks that require 3 additional files. 

├─ builds/config.h
├─ src/hash/accumulator_instances.cpp
├─ test/hash/accumulator_instances.cpp

libbitcoin-database

libbitcoin-database/    ← from the official project repo
├─ include/*
├─ src/*
├─ test/*
├─ tools/*

├─ CMakeLists.txt       ← from this repo
└─ bitcoin-database.pc.in

libbitcoin-network

libbitcoin-network/     ← from the official project repo
├─ include/*
├─ src/*
├─ test/*
├─ CMakeLists.txt       ← from this repo
└─ bitcoin-network.pc.in

libbitcoin-node

libbitcoin-node/        ← from the official project repo
├─ include/*
├─ src/*
├─ test/*
├─ console/*

├─ CMakeLists.txt       ← from this repo
├─ bitcoin-node.pc.in
└─ .vscode/*            ← vscode integration

Quickstart - configure and build

# 1. libbitcoin-system (Release build, static lib, no tests, with CPU extensions)
cd ~/dev/libbitcoin-system
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=~/dev/libbitcoin-install \
  -DENABLE_TESTS=OFF \
  -DENABLE_SHANI=ON -DENABLE_AVX2=ON -DENABLE_SSE41=ON -DENABLE_AVX512=ON

cmake --build build --parallel $(nproc)
cmake --install build

# 2. libbitcoin-database
cd ~/dev/libbitcoin-database
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=~/dev/libbitcoin-install \
  -DENABLE_TESTS=OFF \
  -DENABLE_SHANI=ON -DENABLE_AVX2=ON -DENABLE_SSE41=ON -DENABLE_AVX512=ON

cmake --build build --parallel $(nproc)
cmake --install build

# 3. libbitcoin-network
cd ~/dev/libbitcoin-network
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=~/dev/libbitcoin-install \
  -DENABLE_TESTS=OFF \
  -DENABLE_SHANI=ON -DENABLE_AVX2=ON -DENABLE_SSE41=ON -DENABLE_AVX512=ON

cmake --build build --parallel $(nproc)
cmake --install build

# 4. libbitcoin-node (with console application which is the actual node 'bn')
cd ~/dev/libbitcoin-node
cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=~/dev/libbitcoin-install \
  -DWITH_CONSOLE=ON \
  -DENABLE_TESTS=OFF \
  -DENABLE_SHANI=ON -DENABLE_AVX2=ON -DENABLE_SSE41=ON -DENABLE_AVX512=ON

cmake --build build --parallel $(nproc)
cmake --install build

You now have a fully static bn executable in ~/dev/libbitcoin-install/bin/. Build a debug version with the following command

cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=~/dev/libbitcoin-install \
  -DWITH_CONSOLE=ON \
  -DENABLE_TESTS=ON \
  -DENABLE_SHANI=ON -DENABLE_AVX2=ON -DENABLE_SSE41=ON -DENABLE_AVX512=ON
  # ... other options as needed

CMake automatically keeps Release and Debug separate by adding a 'release_static' subfolder.

VS Code Integration

The repository contains ready-to-use .vscode/ configuration (libbitcoin-node):

  • settings.json
  • launch.json (debug bn, attach to process, etc.)
  • tasks.json (build Release/Debug with one click)

setting.json contains the configre and build parameters. Make sure '-DCMAKE_INSTALL_PREFIX' corresponds with the prefix you used to build the dependencies before.

Just open the libbitcoin-node project folder in VS Code and select the desired build task.

debug session of libbitcoin-node in vscode

Important Notes & Disclaimer

  • Community-maintained alternative – not officially supported by the Libbitcoin team.
  • The CMake files are deliberately simple and will break when the official repositories change directory layout or source files.
  • When a new Libbitcoin version is released, compare the official builds/cmake/modules/CMakeLists.txt with the ones here and adapt if necessary.
  • Only Linux x86_64 is supported and regularly tested.
  • Static builds (-DBUILD_SHARED_LIBS=OFF) are the default and recommended.

Tested CMake Options

Option Description Default
CMAKE_BUILD_TYPE Release / Debug Release
BUILD_SHARED_LIBS ON → shared, OFF → static OFF
CMAKE_INSTALL_PREFIX Install location
ENABLE_TESTS Build unit tests OFF
WITH_CONSOLE Build the bn console utility (node) OFF
ENABLE_SHANI Enable Intel SHA-NI instructions ON
ENABLE_AVX2 Enable AVX2 ON
ENABLE_SSE41 Enable SSE4.1 ON
ENABLE_AVX512 Enable AVX-512 (experimental) ON

Enjoy hacking on Libbitcoin!

About

cmake setup for building libbitcoin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published