Skip to content

Commit

Permalink
add cmake support for linux/mac/windows
Browse files Browse the repository at this point in the history
This is a complete reproduction of the autotools code in cmake, with
improvements where cmake has an advantage.

The options are documented in README.md

Dependencies on Windows with Visual Studio  are handled with vcpkg, and
the `VCPKG_TARGET_TRIPLET` variable can activate vcpkg support on other
platforms as well.

Include the FindPython2 cmake modules as they are not in the base cmake
package on Ubuntu.

Make some minor fixes to the autotools code as well, for things broken
by adding the cmake support and some other fixes.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
  • Loading branch information
rkitover committed Jun 4, 2019
1 parent df0657a commit 13f4758
Show file tree
Hide file tree
Showing 27 changed files with 3,381 additions and 36 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*.idb
*.pdb

build/*
build32/*
vsbuild/*

*libtool.m4
*ltoptions.m4
*ltsugar.m4
Expand Down Expand Up @@ -125,8 +129,10 @@ _CppBlockUtils.*
/.settings
/*.wallet

/findpass.py
/*.txt
!CMakeLists.txt

/findpass.py
/sandbox.py

/lang/*.qm
Expand Down
51 changes: 51 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 2.8.12) # ubuntu 14 version

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

set(VCPKG_DEPS protobuf openssl libwebsockets)

include(Set-Toolchain-vcpkg)

project(BitcoinArmory C CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "release build with debug info" FORCE)
endif()

if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

include(ArmorySupport)
include(PrettyCompilerColors)

use_cxx11()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# use ccache if available, and not already enabled on the command line
# but not with ninja and msys ccache on msys2
if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "") AND CMAKE_GENERATOR STREQUAL Ninja))
if(NOT CMAKE_CXX_COMPILER_LAUNCHER AND NOT CMAKE_C_COMPILER_LAUNCHER)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()
endif()

# build for host CPU if desired (default yes)
option(WITH_HOST_CPU_FEATURES "support the CPU features of the build host, gcc only" ON)

if(WITH_HOST_CPU_FEATURES AND CMAKE_CXX_COMPILER_ID STREQUAL GNU)
check_x86_cpu_features()

add_compile_options(-march=native ${X86_CPU_FEATURES_COMPILER_FLAGS})
endif()

if(MSVC)
add_compile_definitions(NOMINMAX _WINSOCKAPI_)
endif()

add_subdirectory(cppForSwig)
53 changes: 53 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x64-windows",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x64-windows",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x86-windows",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}, {
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x86-windows",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}
61 changes: 39 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,20 @@ Multi-signature transactions are accommodated under-the-hood about 80%, and will

## Building Armory From Source

[Instructions for Windows](windowsbuild/Windows_build_notes.md)
[Instructions for macOS](osxbuild/macOS_build_notes.md)
[Instructions for Ubuntu and Arch Linux](linuxbuild/Linux_build_notes.md)

### Dependencies

* GNU Compiler Collection
Linux: Install package `g++`

* Crypto++
Linux: Install package `libcrypto++-dev`
Windows: [Download](https://www.cryptopp.com/#download)

* SWIG
Linux: Install package `swig`
Windows: [Download](http://www.swig.org/download.html)
Windows: [Download](http://www.swig.org/download.html)
MSVS: Copy swigwin-2.x directory next to cryptopp as `swigwin`

* Python 2.6/2.7
Linux: Install package `python-dev`
Windows: [Download](https://www.python.org/getit/)

* Python Twisted -- asynchronous networking
Linux: Install package `python-twisted`
Windows: [Download](https://twistedmatrix.com/trac/wiki/Downloads)

* PyQt 4 (for Python 2.X)
Linux: Install packages `libqtcore4`, `libqt4-dev`, `python-qt4`, and `pyqt4-dev-tools`
Windows: [Download](https://riverbankcomputing.com/software/pyqt/download)
Expand All @@ -50,19 +38,48 @@ Multi-signature transactions are accommodated under-the-hood about 80%, and will
(OPTIONAL - if you want to make a standalone executable in Windows)
Windows: [Download](http://www.py2exe.org/)

* LMDB - database engine, modified to suit Armory's use cases
[LMDB page](http://symas.com/mdb/) - No need for external installs by Armory users

* libwebsockets
Linux: Final instructions TBA.
Windows: Follow the "Windows binary build" directions [here](https://github.com/warmcat/libwebsockets/blob/master/README.md).
Linux: install latest version from source
Windows: handled automatically with vcpkg, see below

* Google Protocol Buffers (protobuf)
Linux: Install the `protobuf` package.
Windows: Follow the "C++ Installation - Windows" directions [here](https://github.com/google/protobuf/blob/master/src/README.md), downloading only the `protoc` binary.

* macOS
[Instructions for downloading, verifying, and running Armory on macOS](README_macOS.md).
Windows: handled automatically with vcpkg, see below

### CMake options

| **Option** | **Description** | **Default** |
|-----------------------------|------------------------------------------------------------------------------------------|--------------------------------|
| WITH_HOST_CPU_FEATURES | use -march=native and supported cpu feature flags, gcc only | ON |
| WITH_CRYPTOPP | use Crypto++ library for cryptography functions | OFF |
| WITH_CLIENT | build Python client | AUTO |
| WITH_GUI | build GUI support using Qt4 for the Python client | AUTO |
| ENABLE_TESTS | build the test binaries | OFF |
| LIBBTC_WITH_WALLET | enable libbtc wallet | OFF |
| LIBBTC_WITH_TESTS | enable libbtc tests | OFF |
| LIBBTC_WITH_TOOLS | build libbtc tools binaries | OFF |
| LIBBTC_RANDOM_DEVICE | device to use for random numbers | /dev/urandom |
| SECP256K1_ENABLE_ASM | enable asm routines in the secp256k1 library | ON |
| SECP256K1_USE_LIBGMP | use libgmp for numeric routines in the secp256k1 library | AUTO |
| SECP256K1_MODULE_ECDH | enable the ecdh module in the secp256k1 library | OFF |
| SECP256K1_MODULE_SCHNORR | enable the schnorr module in the secp256k1 library | OFF |
| SECP256K1_ECMULT_STATIC_PRECOMPUTATION | use a statically generated ecmult table for the secp256k1 library | OFF |
| SECP256K1_ENDOMORPHISM | use endomorphism optiomization for the secp256k1 library | OFF |
| SECP256K1_WITH_FIELD | field for the secp256k1 library, can be '32bit', '64bit' or 'AUTO' | AUTO |
| SECP256K1_WITH_SCALAR | scalar for the secp256k1 library, can be '32bit', '64bit' or 'AUTO' | AUTO |
| VCPKG_TARGET_TRIPLET | see below | not set |

### CMake Windows/vcpkg Build Type

When building on windows, set the cmake variable `VCPKG_TARGET_TRIPLET` to
`x64-windows` or `x86-windows` depending on whether the build is for 64 bit or
32 bit. You must be in the appropriate Visual Studio environment as well.

All vcpkg supported triplets should work, and this variable can be used to
activate vcpkg support on other platforms.

When building with the Visual Studio IDE, the build products will be located
under `C:\Users\<your-user>\CMakeBuilds`.

## Sample Code

Expand Down
91 changes: 91 additions & 0 deletions cmake/ArmorySupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# random utility functions/macros

# make sure architecture is set
if(NOT CMAKE_SYSTEM_PROCESSOR)
if(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
elseif(CMAKE_TOOLCHAIN_FILE MATCHES mxe)
if(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86")
set(CMAKE_SYSTEM_PROCESSOR i686)
else()
set(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()
endif()
endif()

macro(string_option opt doc_string initial_value)
if(NOT DEFINED ${${opt}})
set(${opt} ${initial_value})
endif()

set(${opt} ${${opt}} CACHE STRING ${doc_string})
endmacro()

# This is from:
# https://stackoverflow.com/a/31010221
macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS 3.1)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
else()
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()

set(CMAKE_CXX_STANDARD 11)
endif()
endmacro(use_cxx11)

unset(X86_CPU_FEATURES_COMPILER_FLAGS)

# check for x86 cpu features and sets X86_CPU_FEATURES_COMPILER_FLAGS for gcc/clang
function(check_x86_cpu_features)
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "i.86|x86_64")
return()
endif()

if(DEFINED X86_CPU_FEATURES_COMPILER_FLAGS) # already computed, do nothing
return()
endif()

include(CheckCXXSourceCompiles)

check_cxx_source_compiles("
#include <stdlib.h>
int main(int argc, char** argv)
{
__builtin_cpu_init();
}
" HAVE_CPU_INIT)

if(HAVE_CPU_INIT)
include(CheckCXXSourceRuns)

foreach(cpu_feature mmx popcnt sse sse2 sse3 sse4.1 sse4.2 sse4a avx avx2 avx512f fma fma4 bmi bmi2)
string(REPLACE . _ cpu_feature_var ${cpu_feature})

check_cxx_source_runs("
#include <stdlib.h>
int main(int argc, char** argv)
{
__builtin_cpu_init();
if (__builtin_cpu_supports(\"${cpu_feature}\"))
return 0;
return 1;
}
" HAVE_${cpu_feature_var})

if(HAVE_${cpu_feature_var})
list(APPEND X86_CPU_FEATURES_COMPILER_FLAGS -m${cpu_feature})
endif()
endforeach()

set(X86_CPU_FEATURES_COMPILER_FLAGS ${X86_CPU_FEATURES_COMPILER_FLAGS} CACHE STRING "gcc/clang cpu feature flags for the build host" FORCE)
endif()
endfunction()
Loading

0 comments on commit 13f4758

Please sign in to comment.