oxen-core/CMakeLists.txt

989 lines
36 KiB
CMake
Raw Normal View History

# Copyright (c) 2018, The Loki Project
# Copyright (c) 2014-2019, The Monero Project
#
2014-09-11 08:25:07 +02:00
# All rights reserved.
#
2014-09-11 08:25:07 +02:00
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
2014-09-11 08:25:07 +02:00
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
2014-09-11 08:25:07 +02:00
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
2014-09-11 08:25:07 +02:00
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
2014-09-11 08:25:07 +02:00
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
2014-09-11 08:25:07 +02:00
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_SOURCE_DIR}/cmake")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
foreach(lang C CXX)
if(NOT DEFINED CMAKE_${lang}_COMPILER_LAUNCHER AND NOT CMAKE_${lang}_COMPILER MATCHES ".*/ccache")
message(STATUS "Enabling ccache for ${lang}")
set(CMAKE_${lang}_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE STRING "")
endif()
endforeach()
endif()
cmake_minimum_required(VERSION 3.13...3.24)
message(STATUS "CMake version ${CMAKE_VERSION}")
2014-03-03 23:07:58 +01:00
2020-10-13 23:13:08 +02:00
# Has to be set before `project()`, and ignored on non-macos:
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12 CACHE STRING "macOS deployment target (Apple clang only)")
2020-10-13 23:13:08 +02:00
2021-01-04 04:19:42 +01:00
project(oxen
2022-09-01 23:57:23 +02:00
VERSION 11.0.0
LANGUAGES CXX C)
2022-05-30 22:13:27 +02:00
set(OXEN_RELEASE_CODENAME "Wistful Wagyu")
# Version update notes:
# - bump the version above.
# - for a new major release, make a new codename
# - (if update needed) required SS/lokinet versions are in cryptonote_core/service_node_rules.h
2014-10-23 20:03:54 +02:00
# String value to append to the full version string; this is intended to easily identify whether a
# binary was build from the release or development branches. This should be permanently set to an
2020-10-02 02:21:37 +02:00
# empty string on `stable`, "-dev" on the `dev` branch, and can be set externally (via cmake
# arguments) where it makes sense to take some other branch release with an extra value.
2021-01-04 04:19:42 +01:00
if(NOT DEFINED OXEN_RELEASE_SUFFIX)
set(OXEN_RELEASE_SUFFIX "-dev")
endif()
2014-10-23 20:03:54 +02:00
if(POLICY CMP0079)
cmake_policy(SET CMP0079 NEW)
endif()
C++17 Switch loki dev branch to C++17 compilation, and update the code with various C++17 niceties. - stop including the (deprecated) lokimq/string_view.h header and instead switch everything to use std::string_view and `""sv` instead of `""_sv`. - std::string_view is much nicer than epee::span, so updated various loki-specific code to use it instead. - made epee "portable storage" serialization accept a std::string_view instead of const lvalue std::string so that we can avoid copying. - switched from mapbox::variant to std::variant - use `auto [a, b] = whatever()` instead of `T1 a; T2 b; std::tie(a, b) = whatever()` in a couple places (in the wallet code). - switch to std::lock(...) instead of boost::lock(...) for simultaneous lock acquisition. boost::lock() won't compile in C++17 mode when given locks of different types. - removed various pre-C++17 workarounds, e.g. for fold expressions, unused argument attributes, and byte-spannable object detection. - class template deduction means lock types no longer have to specify the mutex, so `std::unique_lock<std::mutex> lock{mutex}` can become `std::unique_lock lock{mutex}`. This will make switching any mutex types (e.g. from boost to std mutexes) far easier as you just have to update the type in the header and everything should work. This also makes the tools::unique_lock and tools::shared_lock methods redundant (which were a sort of poor-mans-pre-C++17 way to eliminate the redundancy) so they are now gone and replaced with direct unique_lock or shared_lock constructions. - Redid the LNS validation using a string_view; instead of using raw char pointers the code now uses a string view and chops off parts of the view as it validates. So, for instance, it starts with "abcd.loki", validates the ".loki" and chops the view to "abcd", then validates the first character and chops to "bcd", validates the last and chops to "bc", then can just check everything remaining for is-valid-middle-char. - LNS validation gained a couple minor validation checks in the process: - slightly tightened the requirement on lokinet addresses to require that the last character of the mapped address is 'y' or 'o' (the last base32z char holds only one significant bit). - In parse_owner_to_generic_owner made sure that the owner value has the correct size (otherwise we could up end not filling or overfilling the pubkey buffer). - Replaced base32z/base64/hex conversions with lokimq's versions which have a nicer interface, are better optimized, and don't depend on epee.
2020-05-13 20:12:49 +02:00
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
cmake_policy(SET CMP0083 NEW)
include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE pie_error LANGUAGES CXX C)
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
message(WARNING "PIE linking is not supported: ${pie_error}")
endif()
else()
message(WARNING "PIE disabled: cmake 3.14+ is required for proper PIE linking support")
endif()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLinkerFlag)
include(CheckLibraryExists)
include(CheckFunctionExists)
function (add_c_flag_if_supported flag var)
string(REPLACE "-" "_" supported ${flag}_c)
check_c_compiler_flag(${flag} ${supported})
if(${${supported}})
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function (add_cxx_flag_if_supported flag var)
string(REPLACE "-" "_" supported ${flag}_cxx)
check_cxx_compiler_flag(${flag} ${supported})
if(${${supported}})
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function (add_linker_flag_if_supported flag var)
string(REPLACE "-" "_" supported ${flag}_ld)
string(REPLACE "," "_" supported ${flag}_ld)
check_linker_flag(${flag} ${supported})
if(${${supported}})
set(${var} "${${var}} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function (add_definition_if_function_found function var)
string(REPLACE "-" "_" supported ${function}_function)
check_function_exists(${function} ${supported})
if(${${supported}})
add_definitions("-D${var}")
endif()
endfunction()
function (add_definition_if_library_exists library function header var)
string(REPLACE "-" "_" supported ${function}_library)
check_library_exists(${library} ${function} ${header} ${supported})
if(${${supported}})
add_definitions("-D${var}")
endif()
endfunction()
# Properly links a target to a list of library names by finding the given libraries. Takes:
# - a target
# - a linktype (e.g. INTERFACE, PUBLIC, PRIVATE)
# - a library search path (or "" for defaults)
# - any number of library names
function(link_dep_libs target linktype libdirs)
foreach(lib ${ARGN})
find_library(link_lib-${lib} NAMES ${lib} PATHS ${libdirs})
if(link_lib-${lib})
target_link_libraries(${target} ${linktype} ${link_lib-${lib}})
endif()
endforeach()
endfunction()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}")
endif()
cmake_policy(SET CMP0069 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT MINGW AND NOT ANDROID)
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
set(USE_LTO_DEFAULT ON)
else()
set(USE_LTO_DEFAULT OFF)
endif()
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
option(USE_LTO "Use Link-Time Optimization" ${USE_LTO_DEFAULT})
if(USE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_ENABLED OUTPUT ipo_error)
if(IPO_ENABLED)
message(STATUS "LTO enabled")
else()
message(WARNING "LTO not supported by compiler: ${ipo_error}")
endif()
else()
message(STATUS "LTO disabled")
set(IPO_ENABLED OFF)
endif()
if(IPO_ENABLED AND NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
# On Darwin, ensure the user-defined paths are used to find PCSC
# before falling back to the system frameworks.
set(CMAKE_FIND_FRAMEWORK "LAST")
# ARCH defines the target architecture, either by an explicit identifier or
# one of the following two keywords. By default, ARCH a value of 'native':
# target arch = host arch, binary is not portable. When ARCH is set to the
# string 'default', no -march arg is passed, which creates a binary that is
# portable across processors in the same family as host processor. In cases
# when ARCH is not set to an explicit identifier, cmake's builtin is used
# to identify the target architecture, to direct logic in this cmake script.
# Since ARCH is a cached variable, it will not be set on first cmake invocation.
if (NOT ARCH_ID)
if (NOT ARCH OR ARCH STREQUAL "" OR ARCH STREQUAL "native" OR ARCH STREQUAL "default")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "")
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
set(ARCH_ID "${CMAKE_SYSTEM_PROCESSOR}")
else()
set(ARCH_ID "${ARCH}")
endif()
endif()
string(TOLOWER "${ARCH_ID}" ARM_ID)
string(SUBSTRING "${ARM_ID}" 0 3 ARM_TEST)
if (ARM_TEST STREQUAL "arm")
set(ARM 1)
string(SUBSTRING "${ARM_ID}" 0 5 ARM_TEST)
if (ARM_TEST STREQUAL "armv6")
set(ARM6 1)
endif()
if (ARM_TEST STREQUAL "armv7")
set(ARM7 1)
endif()
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
endif()
if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64" OR ARM_ID STREQUAL "armv8-a")
set(ARM 1)
set(ARM8 1)
set(ARCH "armv8-a")
endif()
if(ARCH_ID STREQUAL "ppc64le")
set(PPC64LE 1)
set(PPC64 0)
set(PPC 0)
endif()
if(ARCH_ID STREQUAL "powerpc64" OR ARCH_ID STREQUAL "ppc64")
set(PPC64LE 0)
set(PPC64 1)
set(PPC 0)
endif()
2018-11-01 04:11:09 +01:00
if(ARCH_ID STREQUAL "powerpc" OR ARCH_ID STREQUAL "ppc")
set(PPC64LE 0)
set(PPC64 0)
set(PPC 1)
endif()
if(ARCH_ID STREQUAL "s390x")
set(S390X 1)
endif()
# BUILD_TAG is used to select the build type to check for a new version
if(BUILD_TAG)
message(STATUS "Building build tag ${BUILD_TAG}")
add_definitions("-DBUILD_TAG=${BUILD_TAG}")
else()
message(STATUS "Building without build tag")
endif()
enable_testing()
option(BUILD_DOCUMENTATION "Build the Doxygen documentation." ON)
option(BUILD_TESTS "Build tests." OFF)
if (BUILD_TESTS)
add_definitions(-DUNIT_TEST)
endif()
OPTION(USE_DEVICE_TREZOR "Build Trezor support (currently non-functional)" OFF)
if(NOT MINGW AND NOT ANDROID)
set(USE_PYBIND_DEFAULT ON)
else()
set(USE_PYBIND_DEFAULT OFF)
endif()
option(BUILD_PYBIND "build python bindings" ${USE_PYBIND_DEFAULT})
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
find_package(Git)
if(NOT MANUAL_SUBMODULES)
if(GIT_FOUND)
2018-10-16 16:43:56 +02:00
function (check_submodule relative_path)
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead)
execute_process(COMMAND git rev-parse "HEAD:${relative_path}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE checkedHead)
2018-10-16 16:43:56 +02:00
string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate)
if (upToDate)
message(STATUS "Submodule '${relative_path}' is up-to-date")
else()
message(FATAL_ERROR "Submodule '${relative_path}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DMANUAL_SUBMODULES=1")
2018-10-16 16:43:56 +02:00
endif()
# Extra arguments check nested submodules
foreach(submod ${ARGN})
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path}/${submod} OUTPUT_VARIABLE localHead)
execute_process(COMMAND git rev-parse "HEAD:${submod}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE checkedHead)
string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate)
if (NOT upToDate)
message(FATAL_ERROR "Nested submodule '${relative_path}/${submod}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DMANUAL_SUBMODULES=1")
endif()
endforeach()
2018-10-16 16:43:56 +02:00
endfunction ()
message(STATUS "Checking submodules")
2018-10-16 16:43:56 +02:00
check_submodule(external/rapidjson)
2018-08-23 23:50:53 +02:00
check_submodule(external/trezor-common)
check_submodule(external/randomx)
check_submodule(external/oxen-mq cppzmq)
check_submodule(external/SQLiteCpp)
if(BUILD_TESTS)
check_submodule(external/googletest)
check_submodule(external/Catch2)
endif()
Replace epee http rpc server with uWebSockets This replaces the NIH epee http server which does not work all that well with an external C++ library called uWebSockets. Fundamentally this gives the following advantages: - Much less code to maintain - Just one thread for handling HTTP connections versus epee's pool of threads - Uses existing LokiMQ job server and existing thread pool for handling the actual tasks; they are processed/scheduled in the same "rpc" or "admin" queues as lokimq rpc calls. One notable benefit is that "admin" rpc commands get their own queue (and thus cannot be delayed by long rpc commands). Currently the lokimq threads and the http rpc thread pool and the p2p thread pool and the job queue thread pool and the dns lookup thread pool and... are *all* different thread pools; this is a step towards consolidating them. - Very little mutex contention (which has been a major problem with epee RPC in the past): there is one mutex (inside uWebSockets) for putting responses back into the thread managing the connection; everything internally gets handled through (lock-free) lokimq inproc sockets. - Faster RPC performance on average, and much better worst case performance. Epee's http interface seems to have some race condition that ocassionally stalls a request (even a very simple one) for a dozen or more seconds for no good reason. - Long polling gets redone here to no longer need threads; instead we just store the request and respond when the thread pool, or else in a timer (that runs once/second) for timing out long polls. --- The basic idea of how this works from a high level: We launch a single thread to handle HTTP RPC requests and response data. This uWebSockets thread is essentially running an event loop: it never actually handles any logic; it only serves to shuttle data that arrives in a request to some other thread, and then, at some later point, to send some reply back to that waiting connection. Everything is asynchronous and non-blocking here: the basic uWebSockets event loop just operates as things arrive, passes it off immediately, and goes back to waiting for the next thing to arrive. The basic flow is like this: 0. uWS thread -- listens on localhost:22023 1. uWS thread -- incoming request on localhost:22023 2. uWS thread -- fires callback, which injects the task into the LokiMQ job queue 3. LMQ main loop -- schedules it as an RPC job 4. LMQ rpc thread -- Some LokiMQ thread runs it, gets the result 5. LMQ rpc thread -- Result gets queued up for the uWS thread 6. uWS thread -- takes the request and starts sending it (asynchronously) back to the requestor. In more detail: uWebSockets has registered has registered handlers for non-jsonrpc requests (legacy JSON or binary). If the port is restricted then admin commands get mapped to a "Access denied" response handler, otherwise public commands (and admin commands on an unrestricted port) go to the rpc command handler. POST requests to /json_rpc have their own handler; this is a little different than the above because it has to parse the request before it can determine whether it is allowed or not, but once this is done it continues roughly the same as legacy/binary requests. uWebSockets then listens on the given IP/port for new incoming requests, and starts listening for requests in a thread (we own this thread). When a request arrives, it fires the event handler for that request. (This may happen multiple times, if the client is sending a bunch of data in a POST request). Once we have the full request, we then queue the job in LokiMQ, putting it in the "rpc" or "admin" command categories. (The one practical different here is that "admin" is configured to be allowed to start up its own thread if all other threads are busy, while "rpc" commands are prioritized along with everything else.) LokiMQ then schedules this, along with native LokiMQ "rpc." or "admin." requests. When a LMQ worker thread becomes available, the RPC command gets called in it and runs. Whatever output it produces (or error message, if it throws) then gets wrapped up in jsonrpc boilerplate (if necessary), and delivered to the uWebSockets thread to be sent in reply to that request. uWebSockets picks up the data and sends whatever it can without blocking, then buffers whatever it couldn't send to be sent again in a later event loop iteration once the requestor can accept more data. (This part is outside lokid; we only have to give uWS the data and let it worry about delivery). --- PR specifics: Things removed from this PR: 1. ssl settings; with this PR the HTTP RPC interface is plain-text. The previous default generated a self-signed certificate for the server on startup and then the client accepted any certificate. This is actually *worse* than unencrypted because it is entirely MITM-readable and yet might make people think that their RPC communication is encrypted, and setting up actual certificates is difficult enough that I think most people don't bother. uWebSockets *does* support HTTPS, and we could glue the existing options into it, but I'm not convinced it's worthwhile: it works much better to put HTTPS in a front-end proxy holding the certificate that proxies requests to the backend (which can then listen in restricted mode on some localhost port). One reason this is better is that it is much easier to reload and/or restart such a front-end server, while certificate updates with lokid require a full restart. Another reason is that you get an error page instead of a timeout if something is wrong with the backend. Finally we also save having to generate a temporary certificate on *every* lokid invocation. 2. HTTP Digest authentication. Digest authentication is obsolete (and was already obsolete when it got added to Monero). HTTP-Digest was originally an attempt to provide a password authentication mechanism that does not leak the password in transit, but still required that the server know the password. It only has marginal value against replay attacks, and is made entirely obsolete by sending traffic over HTTPS instead. No client out there supports Digest but *not* Basic auth, and so given the limited usefulness it seems pointless to support more than Basic auth for HTTP RPC login. What's worse is that epee's HTTP Digest authentication is a terrible implementation: it uses boost::spirit -- a recursive descent parser meant for building complex language grammars -- just to parse a single HTTP header for Digest auth. This is a big load of crap that should never have been accepted upstream, and that we should get rid of (even if we wanted to support Digest auth it takes less than 100 lines of code to do it when *not* using a recursive descent parser).
2020-06-29 01:23:06 +02:00
check_submodule(external/uWebSockets uSockets)
check_submodule(external/ghc-filesystem)
check_submodule(external/SQLiteCpp)
check_submodule(external/pybind11)
endif()
endif()
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
# set this to 0 if per-block checkpoint needs to be disabled
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
option(PER_BLOCK_CHECKPOINT "Enables per-block checkpointing" ON)
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
2014-10-22 21:17:52 +02:00
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_SOURCE_DIR}/cmake")
2020-06-12 00:59:20 +02:00
option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost installation" OFF)
2014-03-03 23:07:58 +01:00
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
2015-03-02 17:04:58 +01:00
set(DEFAULT_BUILD_64 ON)
else()
2015-03-02 17:04:58 +01:00
set(DEFAULT_BUILD_64 OFF)
endif()
2015-03-03 20:57:40 +01:00
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
2015-03-02 17:04:58 +01:00
if(BUILD_64)
set(ARCH_WIDTH "64")
else()
set(ARCH_WIDTH "32")
endif()
message(STATUS "Building for a ${ARCH_WIDTH}-bit system")
# CMAKE_SYSTEM_NAME checks are commonly known, but specifically taken from libsdl's CMakeLists
if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*|FreeBSD")
set(FREEBSD TRUE)
endif()
# Check if we're on DragonFly BSD. See the README.md for build instructions.
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*")
set(DRAGONFLY TRUE)
endif()
# Check if we're on OpenBSD. See the README.md for build instructions.
2016-01-21 19:18:26 +01:00
if(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
set(OPENBSD TRUE)
endif()
# TODO: check bsdi, NetBSD, to see if they need the same FreeBSD changes
#
# elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
# set(NETBSD TRUE)
# elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
# set(BSDI TRUE)
include(cmake/check_for_std_filesystem.cmake)
include_directories(external/rapidjson/include src external)
2014-03-03 23:07:58 +01:00
if(APPLE)
2014-04-30 22:50:06 +02:00
include_directories(SYSTEM /usr/include/malloc)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
endif()
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
option(BUILD_STATIC_DEPS "Download, build and statically link against core dependencies" OFF)
if(BUILD_STATIC_DEPS)
include(StaticBuild)
endif()
if(MSVC OR MINGW OR BUILD_STATIC_DEPS)
set(DEFAULT_STATIC true)
else()
set(DEFAULT_STATIC false)
endif()
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
option(STATIC "Try to link external dependencies statically, where possible" ${DEFAULT_STATIC})
if(BUILD_STATIC_DEPS AND NOT STATIC)
message(FATAL_ERROR "Option BUILD_STATIC_DEPS requires STATIC be enabled as well")
endif()
option(BUILD_SHARED_LIBS "Build shared internal libraries" OFF)
if(MINGW)
string(REGEX MATCH "^[^/]:/[^/]*" msys2_install_path "${CMAKE_C_COMPILER}")
message(STATUS "MSYS location: ${msys2_install_path}")
set(CMAKE_INCLUDE_PATH "${msys2_install_path}/mingw${ARCH_WIDTH}/include")
# This is necessary because otherwise CMake will make Boost libraries -lfoo
# rather than a full path. Unfortunately, this makes the shared libraries get
# linked due to a bug in CMake which misses putting -static flags around the
# -lfoo arguments.
set(DEFLIB ${msys2_install_path}/mingw${ARCH_WIDTH}/lib)
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_DIRECTORIES ${DEFLIB})
list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES ${DEFLIB})
endif()
if(STATIC)
if(MSVC)
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()
endif()
if(SANITIZE)
if (MSVC)
message(FATAL_ERROR "Cannot sanitize with MSVC")
else()
message(STATUS "Using ASAN")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
endif()
# Set default blockchain storage location:
# memory was the default in Cryptonote before Monero implemented LMDB, it still works but is unnecessary.
# set(DATABASE memory)
set(DATABASE lmdb)
if (DEFINED ENV{DATABASE})
set(DATABASE $ENV{DATABASE})
message(STATUS "DATABASE set: ${DATABASE}")
else()
message(STATUS "Could not find DATABASE in env (not required unless you want to change database type from default: ${DATABASE})")
endif()
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
if (DATABASE STREQUAL "lmdb")
message(STATUS "Using LMDB as default DB type")
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
set(BLOCKCHAIN_DB "lmdb")
else()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
message(FATAL_ERROR "Invalid database type: ${DATABASE}")
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
2017-10-10 15:05:28 +02:00
2017-04-02 12:19:25 +02:00
if (APPLE AND NOT IOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64 -fvisibility=default")
endif()
add_definition_if_library_exists(c memset_s "string.h" HAVE_MEMSET_S)
add_definition_if_library_exists(c explicit_bzero "strings.h" HAVE_EXPLICIT_BZERO)
add_definition_if_function_found(strptime HAVE_STRPTIME)
# Generate header for embedded translations
add_subdirectory(translations)
add_library(systemd INTERFACE) # Will do nothing unless we find and enable systemd support
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
if(NOT TARGET sodium)
# Allow -D DOWNLOAD_SODIUM=FORCE to download without even checking for a local libsodium
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
option(DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF)
if(NOT DOWNLOAD_SODIUM STREQUAL "FORCE" AND NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SODIUM libsodium>=1.0.9 IMPORTED_TARGET)
endif()
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
add_library(sodium INTERFACE)
if(SODIUM_FOUND AND NOT DOWNLOAD_SODIUM STREQUAL "FORCE" AND NOT BUILD_STATIC_DEPS)
target_link_libraries(sodium INTERFACE PkgConfig::SODIUM)
else()
if(NOT DOWNLOAD_SODIUM AND NOT BUILD_STATIC_DEPS)
message(FATAL_ERROR "Could not find libsodium >= 1.0.9; either install it on your system or use -DDOWNLOAD_SODIUM=ON to download and build an internal copy")
endif()
message(STATUS "Sodium >= 1.0.9 not found, but DOWNLOAD_SODIUM specified, so downloading it")
include(DownloadLibSodium)
target_link_libraries(sodium INTERFACE sodium_vendor)
endif()
# Need this target export so that oxen-mq properly picks up sodium
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
export(TARGETS sodium NAMESPACE sodium:: FILE sodium-exports.cmake)
endif()
option(WITH_SYSTEMD "Attempts to link against and enable systemd daemon notification support" ON)
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
if (WITH_SYSTEMD AND NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD libsystemd IMPORTED_TARGET)
if(SYSTEMD_FOUND)
target_compile_definitions(systemd INTERFACE ENABLE_SYSTEMD)
target_link_libraries(systemd INTERFACE PkgConfig::SYSTEMD)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
message(WARNING "systemd not found; building without systemd support (use -DWITH_SYSTEMD=OFF to suppress this warning)")
endif()
endif()
if(NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SQLITE3 REQUIRED sqlite3>=3.24.0 IMPORTED_TARGET GLOBAL)
2021-10-05 02:33:24 +02:00
message(STATUS "Found sqlite3 ${SQLITE3_VERSION}")
2021-10-07 01:04:23 +02:00
add_library(SQLite::SQLite3 ALIAS PkgConfig::SQLITE3)
2021-10-05 02:33:24 +02:00
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
add_subdirectory(external)
if(USE_DEVICE_TREZOR)
include(CheckTrezor)
endif()
2018-08-23 23:50:53 +02:00
2014-03-03 23:07:58 +01:00
if(MSVC)
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")
2014-03-03 23:07:58 +01:00
if(STATIC)
foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
endforeach()
endif()
include_directories(SYSTEM src/platform/msc)
else()
include(TestCXXAcceptsFlag)
if (NOT ARCH)
set(ARCH native CACHE STRING "CPU to build for: -march value or 'default' to not pass -march at all")
endif()
message(STATUS "Building on ${CMAKE_SYSTEM_PROCESSOR} for ${ARCH}")
if(ARCH STREQUAL "default")
2014-03-03 23:07:58 +01:00
set(ARCH_FLAG "")
elseif(PPC64LE)
set(ARCH_FLAG "-mcpu=power8")
elseif(PPC64)
set(ARCH_FLAG "-mcpu=970")
elseif(PPC)
set(ARCH_FLAG "-mcpu=7400")
2017-06-23 10:02:07 +02:00
elseif(IOS AND ARCH STREQUAL "arm64")
message(STATUS "IOS: Changing arch from arm64 to armv8")
set(ARCH_FLAG "-march=armv8")
2019-11-01 02:41:31 +01:00
elseif(IOS AND ARCH STREQUAL "x86_64")
message(STATUS "IOS: Changing arch from x86_64 to x86-64")
set(ARCH_FLAG "-march=x86-64")
2014-03-03 23:07:58 +01:00
else()
set(ARCH_FLAG "-march=${ARCH}")
2018-09-02 16:51:23 +02:00
if(ARCH STREQUAL "native")
check_c_compiler_flag(-march=native CC_SUPPORTS_MARCH_NATIVE)
if (NOT CC_SUPPORTS_MARCH_NATIVE)
check_c_compiler_flag(-mtune=native CC_SUPPORTS_MTUNE_NATIVE)
if (CC_SUPPORTS_MTUNE_NATIVE)
set(ARCH_FLAG "-mtune=${ARCH}")
else()
set(ARCH_FLAG "")
endif()
endif()
endif()
2014-03-03 23:07:58 +01:00
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAG}")
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=uninitialized")
option(WARNINGS_AS_ERRORS "Enable warning as errors" OFF)
if(NOT MINGW AND WARNINGS_AS_ERRORS)
set(WARNINGS_AS_ERRORS_FLAG "-Werror")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
if(ARM)
set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
endif()
2014-03-03 23:07:58 +01:00
else()
set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized -Wno-error=cpp -Wno-error=logical-op")
2014-03-03 23:07:58 +01:00
endif()
if(MINGW)
set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable")
set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN")
2014-08-06 18:43:01 +02:00
set(Boost_THREADAPI win32)
2014-03-03 23:07:58 +01:00
include_directories(SYSTEM src/platform/mingw)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10485760")
if(NOT BUILD_64)
add_definitions(-DWINVER=0x0501 -D_WIN32_WINNT=0x0501)
endif()
2014-03-03 23:07:58 +01:00
endif()
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
2017-01-05 02:11:05 +01:00
option(COVERAGE "Enable profiling for test coverage report" 0)
if(COVERAGE)
message(STATUS "Building with profiling for test coverage report")
set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage --coverage")
endif()
# if those don't work for your compiler, single it out where appropriate
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT OPENBSD)
set(C_SECURITY_FLAGS "${C_SECURITY_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1")
set(C_SECURITY_FLAGS "${C_SECURITY_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1")
set(CXX_SECURITY_FLAGS "${CXX_SECURITY_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1")
endif()
# warnings
add_c_flag_if_supported(-Wformat C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-Wformat CXX_SECURITY_FLAGS)
add_c_flag_if_supported(-Wformat-security C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-Wformat-security CXX_SECURITY_FLAGS)
# -fstack-protector
if (NOT OPENBSD AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
add_c_flag_if_supported(-fstack-protector C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-fstack-protector CXX_SECURITY_FLAGS)
add_c_flag_if_supported(-fstack-protector-strong C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-fstack-protector-strong CXX_SECURITY_FLAGS)
endif()
2019-11-01 02:41:31 +01:00
# -fno-stack-check
if (IOS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-check")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-check")
endif()
# New in GCC 8.2
if (NOT OPENBSD AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
add_c_flag_if_supported(-fcf-protection=full C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-fcf-protection=full CXX_SECURITY_FLAGS)
endif()
if (NOT WIN32 AND NOT OPENBSD AND NOT APPLE)
add_c_flag_if_supported(-fstack-clash-protection C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-fstack-clash-protection CXX_SECURITY_FLAGS)
endif()
# GCC 12's stringop-overflow warnings are really broken, with tons and tons of false positives all
# over the place (not just in our code, but also in its own stdlibc++ code).
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 12 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
set(CXX_WARNINGS "${CXX_WARNINGS} -Wno-stringop-overflow")
endif()
# Removed in GCC 9.1 (or before ?), but still accepted, so spams the output
if (NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)
add_c_flag_if_supported(-mmitigate-rop C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-mmitigate-rop CXX_SECURITY_FLAGS)
endif()
# linker
add_linker_flag_if_supported(-Wl,-z,relro LD_SECURITY_FLAGS)
add_linker_flag_if_supported(-Wl,-z,now LD_SECURITY_FLAGS)
add_linker_flag_if_supported(-Wl,-z,noexecstack noexecstack_SUPPORTED)
if (noexecstack_SUPPORTED)
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecstack")
endif()
add_linker_flag_if_supported(-Wl,-z,noexecheap noexecheap_SUPPORTED)
if (noexecheap_SUPPORTED)
set(LD_SECURITY_FLAGS "${LD_SECURITY_FLAGS} -Wl,-z,noexecheap")
endif()
if(BACKCOMPAT)
add_linker_flag_if_supported(-Wl,--wrap=__divmoddi4 LD_BACKCOMPAT_FLAGS)
add_linker_flag_if_supported(-Wl,--wrap=glob LD_BACKCOMPAT_FLAGS)
message(STATUS "Using Lib C back compat flags: ${LD_BACKCOMPAT_FLAGS}")
endif()
# some windows linker bits
if (WIN32)
add_linker_flag_if_supported(-Wl,--dynamicbase LD_SECURITY_FLAGS)
add_linker_flag_if_supported(-Wl,--nxcompat LD_SECURITY_FLAGS)
add_linker_flag_if_supported(-Wl,--high-entropy-va LD_SECURITY_FLAGS)
endif()
message(STATUS "Using C security hardening flags: ${C_SECURITY_FLAGS}")
message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}")
message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${C_WARNINGS} ${COVERAGE_FLAGS} ${C_SECURITY_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${COVERAGE_FLAGS} ${CXX_SECURITY_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${LD_BACKCOMPAT_FLAGS}")
if(ARM)
message(STATUS "Setting FPU Flags for ARM Processors")
#NB NEON hardware does not fully implement the IEEE 754 standard for floating-point arithmetic
#Need custom assembly code to take full advantage of NEON SIMD
#Cortex-A5/9 -mfpu=neon-fp16
#Cortex-A7/15 -mfpu=neon-vfpv4
#Cortex-A8 -mfpu=neon
#ARMv8 -FP and SIMD on by default for all ARM8v-A series, NO -mfpu setting needed
#For custom -mtune, processor IDs for ARMv8-A series:
#0xd04 - Cortex-A35
#0xd07 - Cortex-A57
#0xd08 - Cortex-A72
#0xd03 - Cortex-A73
if(NOT ARM8)
CHECK_CXX_ACCEPTS_FLAG(-mfpu=vfp3-d16 CXX_ACCEPTS_VFP3_D16)
CHECK_CXX_ACCEPTS_FLAG(-mfpu=vfp4 CXX_ACCEPTS_VFP4)
CHECK_CXX_ACCEPTS_FLAG(-mfloat-abi=hard CXX_ACCEPTS_MFLOAT_HARD)
CHECK_CXX_ACCEPTS_FLAG(-mfloat-abi=softfp CXX_ACCEPTS_MFLOAT_SOFTFP)
endif()
2015-04-06 14:00:09 +02:00
if(ARM8)
CHECK_CXX_ACCEPTS_FLAG(-mfix-cortex-a53-835769 CXX_ACCEPTS_MFIX_CORTEX_A53_835769)
CHECK_CXX_ACCEPTS_FLAG(-mfix-cortex-a53-843419 CXX_ACCEPTS_MFIX_CORTEX_A53_843419)
endif()
if(ARM6)
message(STATUS "Selecting VFP for ARMv6")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp")
endif(ARM6)
if(ARM7)
if(CXX_ACCEPTS_VFP3_D16 AND NOT CXX_ACCEPTS_VFP4)
message(STATUS "Selecting VFP3 for ARMv7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp3-d16")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp3-d16")
endif()
if(CXX_ACCEPTS_VFP4)
message(STATUS "Selecting VFP4 for ARMv7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp4")
endif()
if(CXX_ACCEPTS_MFLOAT_HARD)
message(STATUS "Setting Hardware ABI for Floating Point")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
endif()
if(CXX_ACCEPTS_MFLOAT_SOFTFP AND NOT CXX_ACCEPTS_MFLOAT_HARD)
message(STATUS "Setting Software ABI for Floating Point")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=softfp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp")
endif()
endif(ARM7)
if(ARM8)
if(CXX_ACCEPTS_MFIX_CORTEX_A53_835769)
message(STATUS "Enabling Cortex-A53 workaround 835769")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-835769")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfix-cortex-a53-835769")
endif()
if(CXX_ACCEPTS_MFIX_CORTEX_A53_843419)
message(STATUS "Enabling Cortex-A53 workaround 843419")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-843419")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfix-cortex-a53-843419")
endif()
endif(ARM8)
endif(ARM)
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY) Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 22:09:32 +02:00
2014-04-30 22:50:06 +02:00
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
2014-04-30 22:50:06 +02:00
endif()
# At least some CLANGs default to not enough for monero
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=900")
if(STATIC)
# STATIC already configures most deps to be linked in statically,
# here we make more deps static if the platform permits it
if (MINGW)
# On Windows, this is as close to fully-static as we get:
# this leaves only deps on /c/Windows/system32/*.dll
set(STATIC_FLAGS "-static")
elseif (NOT (APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY))
# On Linux, we don't support fully static build, but these can be static
set(STATIC_FLAGS "-static-libgcc -static-libstdc++")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STATIC_FLAGS} ")
endif()
2014-03-03 23:07:58 +01:00
endif()
if (${BOOST_IGNORE_SYSTEM_PATHS} STREQUAL "ON")
set(Boost_NO_SYSTEM_PATHS TRUE)
2014-09-22 12:30:53 +02:00
endif()
set(OLD_LIB_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
2014-03-03 23:07:58 +01:00
if(STATIC)
if(MINGW)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(Boost_NO_BOOST_CMAKE ON)
endif()
2014-03-03 23:07:58 +01:00
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
set(Boost_USE_MULTITHREADED TRUE) # Needed for macOS, at least, and won't hurt elsewhere
Static builds: make usable binaries from cmake This adds a static dependency script for libraries like boost, unbound, etc. to cmake, invokable with: cmake .. -DBUILD_STATIC_DEPS=ON which downloads and builds static versions of all our required dependencies (boost, unbound, openssl, ncurses, etc.). It also implies -DSTATIC=ON to build other vendored deps (like miniupnpc, lokimq) as static as well. Unlike the contrib/depends system, this is easier to maintain (one script using nicer cmake with functions instead of raw Makefile spaghetti code), and isn't concerned with reproducible builds -- this doesn't rebuild the compiler, for instance. It also works with the existing build system so that it is simply another way to invoke the cmake build scripts but doesn't require any external tooling. This works on Linux, Mac, and Windows. Some random comments on this commit (for preserving history): - Don't use target_link_libraries on imported targets. Newer cmake is fine with it, but Bionic's cmake doesn't like it but seems okay with setting the properties directly. - This rebuilds libzmq and libsodium, even though there is some provision already within loki-core to do so: however, the existing embedded libzmq fails with the static deps because it uses libzmq's cmake build script, which relies on pkg-config to find libsodium which ends up finding the system one (or not finding any), rather than the one we build with DownloadLibSodium. Since both libsodium and libzmq are faily simple builds it seemed easiest to just add them to the cmake static build rather than trying to shoehorn the current code into the static build script. - Half of the protobuf build system ignores CC/CXX just because Google, and there's no documentation anywhere except for a random closed bug report about needing to set these other variables (CC_FOR_BUILD, CXX_FOR_BUILD) instead, but you need to. Thanks Google. - The boost build is set to output very little because even the minimum -d1 output level spams ~15k lines of output just for the headers it installs.
2020-06-11 20:19:44 +02:00
if(BUILD_STATIC_DEPS)
# StaticBuild.cmake sets Boost targets up for us
else()
Remove openssl, unbound, expat, OpenAlias openssl is a miserable dependency to fight with, especially for iOS/Android, and we use it for very little: - it gets (mis)used to write base64 data to a file in wallet2 for things like multisig data. However this mode is *not* enabled by default, basically completely unknown, completely unused, only exists in the cli wallet, and is just dumb. (Honestly the justification given in the PR is that "Windows users might want it", presupposing that there exists Windows users who are capable of generating a multisig wallet in a CLI-only application and yet are incapable of dealing with binary files). - it's a dependency of unbound (in order to do dnssec, I believe). Unbound itself is fairly useless for Oxen, so I've removed it too: - it does OpenAlias lookups, which are a Monero thing that has never been used outside Monero, doesn't work reliably (because it fails if the result isn't DNSSEC validated) and is pointless when we have ONS. - it does DNS resolution on seed nodes, but we have never set seed nodes by name and just use seed node IPs instead (which seems a bit better anyway since the DNS lookup leaks some metadata). - it *was* being used for sha256, but an earlier commit in this PR already replaced that with libsodium (entirely coincidentally). - for static deps, it enables HTTPS support for the wallet. However only the CLI wallet actually supports this (the GUI and mobile wallets don't), and since oxend hasn't support this for a while I have strong doubts it is being used anywhere. (Plus wallet3 will do everything encrypted using zmq/libsodium, so doesn't need this to be secure). Note here that it is *only* removed by this commit for static builds: if doing a system build that links to libcurl supporting HTTPS then HTTPS support will still work. Libexpat is also gone because it was only there for libunbound.
2022-04-15 01:11:36 +02:00
find_package(Boost 1.62 QUIET REQUIRED COMPONENTS system thread serialization program_options)
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})
if(NOT Boost_FOUND)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
message(FATAL_ERROR "Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (>=1.58) or the equivalent")
elseif(Boost_FOUND)
message(STATUS "Found Boost Version: ${Boost_VERSION}")
2014-03-03 23:07:58 +01:00
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
# Interface target for random extra system libraries that we need to link everything against
add_library(extra INTERFACE)
target_link_libraries(extra INTERFACE ${CMAKE_DL_LIBS})
target_link_libraries(extra INTERFACE Boost::boost)
target_link_libraries(extra INTERFACE Threads::Threads)
if(APPLE AND BUILD_SHARED_LIBS)
# Don't crap out on circular dependencies between internal libs on macOS when doing a shared build
target_link_libraries(extra INTERFACE "-undefined dynamic_lookup")
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
# Interface target for ICU libs (if needed)
add_library(icu INTERFACE)
2014-03-03 23:07:58 +01:00
if(MINGW)
2018-05-31 11:40:00 +02:00
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE mswsock ws2_32 iphlpapi crypt32 bcrypt)
link_dep_libs(icu INTERFACE "" icuio icuin icuuc icudt icutu iconv)
elseif(FREEBSD)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE execinfo)
elseif(DRAGONFLY)
find_library(COMPAT compat)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE ${COMPAT})
2017-10-10 15:05:28 +02:00
elseif(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE socket nsl resolv)
elseif(APPLE)
find_library(COREFOUNDATION CoreFoundation)
find_library(IOKIT IOKit)
target_link_libraries(extra INTERFACE ${IOKIT} ${COREFOUNDATION})
elseif(NOT (MSVC OR APPLE OR OPENBSD OR ANDROID))
find_library(RT rt)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE rt)
2014-03-03 23:07:58 +01:00
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
if (WIN32)
target_link_libraries(extra INTERFACE setupapi)
endif()
option(USE_READLINE "Build with GNU readline support." ON)
if(USE_READLINE AND BUILD_STATIC_DEPS)
# readline target already set up
elseif(USE_READLINE)
find_package(Readline)
if(READLINE_FOUND AND GNU_READLINE_FOUND)
add_library(readline INTERFACE)
target_link_libraries(readline INTERFACE ${GNU_READLINE_LIBRARY})
target_include_directories(readline INTERFACE ${Readline_INCLUDE_DIR})
target_compile_definitions(readline INTERFACE HAVE_READLINE)
message(STATUS "Found readline library at: ${GNU_READLINE_LIBRARY}")
else()
message(STATUS "Could not find GNU readline library so building without readline support")
endif()
endif()
2017-01-21 05:15:00 +01:00
if(ANDROID)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_compile_options(extra INTERFACE "-Wno-error=user-defined-warnings")
2017-01-21 05:15:00 +01:00
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ARCH_WIDTH EQUAL "32" AND NOT IOS AND NOT FREEBSD)
find_library(ATOMIC atomic)
if (ATOMIC_FOUND)
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
target_link_libraries(extra INTERFACE ${ATOMIC})
endif()
endif()
cmake modernization The archaic (i.e. decade old) cmake usage here really got in the way of trying to properly use newer libraries (like lokimq), so this undertakes overhauling it considerably to make it much more sane (and significantly reduce the size). I left more of the architecture-specific bits in the top-level CMakeLists.txt intact; most of the efforts here are about properly loading dependencies, specifying dependencies and avoiding a whole pile of cmake antipatterns. This bumps the required cmake version to 3.5, which is what xenial comes with. - extensive use of interface libraries to include libraries, definitions, and include paths - use Boost::whatever instead of ${Boost_WHATEVER_LIBRARY}. The interface targets are (again) much better as they also give you any needed include or linking flags without needing to worry about them. - don't list header files when building things. This has *never* been correct cmake usage (cmake has always known how to wallet_rpc_headers the headers that .cpp files include to know about build changes). - remove the loki_add_library monstrosity; it breaks target names and makes compiling less efficient because the author couldn't figure out how to link things together. - make loki_add_executable take the output filename, and set the output path to bin/ and install to bin because *every single usage* of loki_add_executable was immediately followed by setting the output filename and setting the output path to bin/ and installing to bin. - move a bunch of crap that is only used in one particular src/whatever/CMakeLists.txt into that particular CMakeLists.txt instead of the top level CMakeLists.txt (or src/CMakeLists.txt). - Remove a bunch of redundant dependencies; most of them look like they were just copy-and-pasted in, and many more aren't needed (since they are implied by the PUBLIC linking of other dependencies). - Removed `die` since it just does a FATAL_ERROR, but adds color (which is useless since CMake already makes FATAL_ERRORs perfectly visible). - Change the way LOKI_DAEMON_AND_WALLET_ONLY works to just change the make targets to daemon and simplewallet rather than changing the build process (this should make it faster, too, since there are various other things that will be excluded).
2020-03-03 04:57:08 +01:00
add_subdirectory(contrib)
add_subdirectory(src)
if(BUILD_TESTS)
message(STATUS "Building tests")
add_subdirectory(tests)
else()
message(STATUS "Not building tests")
endif()
if(BUILD_DOCUMENTATION)
set(DOC_GRAPHS "YES" CACHE STRING "Create dependency graphs (needs graphviz)")
set(DOC_FULLGRAPHS "NO" CACHE STRING "Create call/callee graphs (large)")
find_program(DOT_PATH dot)
if (DOT_PATH STREQUAL "DOT_PATH-NOTFOUND")
message("Doxygen: graphviz not found - graphs disabled")
set(DOC_GRAPHS "NO")
endif()
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file("cmake/Doxyfile.in" "Doxyfile" @ONLY)
configure_file("cmake/Doxygen.extra.css.in" "Doxygen.extra.css" @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen.." VERBATIM)
endif()
endif()
find_package(PythonInterp)
find_program(iwyu_tool_path NAMES iwyu_tool.py iwyu_tool)
if (iwyu_tool_path AND PYTHONINTERP_FOUND)
add_custom_target(iwyu
COMMAND "${PYTHON_EXECUTABLE}" "${iwyu_tool_path}" -p "${CMAKE_BINARY_DIR}" -- --no_fwd_decls
COMMENT "Running include-what-you-use tool"
VERBATIM
)
endif()
# Set up a `make strip_binaries` target that strips built binaries. This depends on all
# default-built binaries and strips them after build. (To also build and strip debug utilities
# there is also a `make strip_binaries_all` target.)
2021-01-04 04:19:42 +01:00
get_property(oxen_exec_tgts_all GLOBAL PROPERTY oxen_executable_targets)
set(oxen_exec_tgts "")
set(strip_binaries "")
set(strip_binaries_all "")
2021-01-04 04:19:42 +01:00
foreach(tgt ${oxen_exec_tgts_all})
list(APPEND strip_binaries_all COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${tgt}>)
# Look for a EXCLUDE_FROM_ALL property:
get_property(tgt_excl_all TARGET ${tgt} PROPERTY EXCLUDE_FROM_ALL)
# Also look for EXCLUDE_FROM_ALL on the target's source directory (this, unfortunately, is not
# inherited into the target itself, hence we check both).
get_property(tgt_dir TARGET ${tgt} PROPERTY SOURCE_DIR)
get_property(tgt_dir_excl_all DIRECTORY ${tgt_dir} PROPERTY EXCLUDE_FROM_ALL)
if (NOT tgt_excl_all AND NOT tgt_dir_excl_all)
2021-01-04 04:19:42 +01:00
list(APPEND oxen_exec_tgts ${tgt})
list(APPEND strip_binaries COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${tgt}>)
endif()
endforeach()
2021-01-04 04:19:42 +01:00
add_custom_target(strip_binaries ${strip_binaries} DEPENDS ${oxen_exec_tgts})
add_custom_target(strip_binaries_all ${strip_binaries_all} DEPENDS ${oxen_exec_tgts_all})
execute_process(COMMAND tar --version RESULT_VARIABLE tar_exit_code OUTPUT_VARIABLE tar_vers)
set(git_tag "-unknown")
if(GIT_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD RESULT_VARIABLE ret OUTPUT_VARIABLE branch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ret AND branch STREQUAL "stable")
# Get the tag description; for a tagged release this will be just the tag (v1.2.3); for
# something following a tag this will be something like "v1.2.3-2-abcdef" for something 2
# commits beyond the tag, currently at commit "abcdef".
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=6 HEAD RESULT_VARIABLE ret OUTPUT_VARIABLE tag OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ret AND tag MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(-.*)")
# We're building something following a tagged release, so append the post-version git tag info
set(git_tag "${CMAKE_MATCH_1}")
else()
set(git_tag "") # No tag appended if we're building a tagged stable branch release
endif()
else()
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short=9 HEAD RESULT_VARIABLE ret OUTPUT_VARIABLE commithash OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ret)
set(git_tag "-${commithash}")
endif()
endif()
endif()
set(tar_os ${CMAKE_SYSTEM_NAME})
set(default_archive create_tarxz)
if(tar_os STREQUAL "Linux")
set(tar_os "linux-${CMAKE_SYSTEM_PROCESSOR}")
elseif(tar_os STREQUAL "Darwin")
set(tar_os "macos")
elseif(tar_os STREQUAL "Windows")
if(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES i686-.*mingw)
set(tar_os "win-x86")
elseif(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES x86_64-.*mingw)
set(tar_os "win-x64")
else()
set(tar_os "windows") # Don't know what arch
endif()
set(default_archive create_zip) # .tar.xz files are too scary for Windows users
endif()
2021-01-04 04:19:42 +01:00
set(tar_dir "oxen-${tar_os}-${PROJECT_VERSION}${OXEN_RELEASE_SUFFIX}${git_tag}")
add_custom_target(create_tarxz
COMMAND ${CMAKE_COMMAND} -E rename bin "${tar_dir}"
COMMAND ${CMAKE_COMMAND} -E tar cvJ "${tar_dir}.tar.xz" -- "${tar_dir}"
COMMAND ${CMAKE_COMMAND} -E rename "${tar_dir}" bin
2021-01-04 04:19:42 +01:00
DEPENDS ${oxen_exec_tgts})
add_custom_target(create_zip
COMMAND ${CMAKE_COMMAND} -E rename bin "${tar_dir}"
COMMAND ${CMAKE_COMMAND} -E tar cv "${tar_dir}.zip" --format=zip -- "${tar_dir}"
COMMAND ${CMAKE_COMMAND} -E rename "${tar_dir}" bin
2021-01-04 04:19:42 +01:00
DEPENDS ${oxen_exec_tgts})
add_custom_target(create_archive DEPENDS ${default_archive})
if(BUILD_PYBIND)
add_subdirectory(pybind)
endif()