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.
This commit is contained in:
Jason Rhinelander 2020-06-11 15:19:44 -03:00
parent da400f6d66
commit 70b9fed4fd
17 changed files with 756 additions and 137 deletions

View File

@ -142,11 +142,12 @@ endif()
cmake_policy(SET CMP0069 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(USE_LTO_DEFAULT ON)
if(MINGW)
set(USE_LTO_DEFAULT OFF) # FIXME - investigate whether this is still needed with non-ancient mingw
if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT MINGW)
set(USE_LTO_DEFAULT ON)
else()
set(USE_LTO_DEFAULT OFF)
endif()
option(USE_LTO "Use Link-Time Optimization (Release mode only)" ${USE_LTO_DEFAULT})
option(USE_LTO "Use Link-Time Optimization" ${USE_LTO_DEFAULT})
if(USE_LTO)
include(CheckIPOSupported)
@ -254,8 +255,8 @@ if (BUILD_TESTS)
add_definitions(-DUNIT_TEST)
endif()
find_package(Git)
if(NOT MANUAL_SUBMODULES)
find_package(Git)
if(GIT_FOUND)
function (check_submodule relative_path)
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead)
@ -347,12 +348,22 @@ if(APPLE)
endif()
endif()
if(MSVC OR MINGW)
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()
option(STATIC "Try to link external libraries statically, where possible" ${DEFAULT_STATIC})
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)
set(PIC_FLAG "-fPIC")
@ -420,7 +431,11 @@ if (APPLE AND NOT IOS)
endif()
endif()
find_package(OpenSSL REQUIRED)
if(BUILD_STATIC_DEPS)
# SSL::* targets already set up
else()
find_package(OpenSSL REQUIRED)
endif()
message(STATUS "Using OpenSSL include dir at ${OPENSSL_INCLUDE_DIR}")
if(MINGW)
@ -438,35 +453,40 @@ add_subdirectory(translations)
add_library(miniupnpc INTERFACE)
add_library(systemd INTERFACE) # Will do nothing unless we find and enable systemd support
if(NOT TARGET sodium)
# Allow -D DOWNLOAD_SODIUM=FORCE to download without even checking for a local libsodium
option(DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF)
if(NOT DOWNLOAD_SODIUM STREQUAL "FORCE")
find_package(PkgConfig REQUIRED)
pkg_check_modules(SODIUM libsodium>=1.0.9 IMPORTED_TARGET)
endif()
add_library(sodium INTERFACE)
if(SODIUM_FOUND AND NOT DOWNLOAD_SODIUM STREQUAL "FORCE")
target_link_libraries(sodium INTERFACE PkgConfig::SODIUM)
else()
if(NOT DOWNLOAD_SODIUM)
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")
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()
message(STATUS "Sodium >= 1.0.9 not found, but DOWNLOAD_SODIUM specified, so downloading it")
include(DownloadLibSodium)
target_link_libraries(sodium INTERFACE sodium_vendor)
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 loki-mq properly picks up sodium
export(TARGETS sodium NAMESPACE sodium:: FILE sodium-exports.cmake)
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(UNBOUND unbound REQUIRED IMPORTED_TARGET)
add_library(libunbound INTERFACE)
target_link_libraries(libunbound PkgConfig::UNBOUND)
export(TARGETS sodium NAMESPACE sodium:: FILE sodium-exports.cmake)
install(TARGETS sodium EXPORT sodiumConfig DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(UNBOUND libunbound REQUIRED IMPORTED_TARGET)
add_library(libunbound INTERFACE)
target_link_libraries(libunbound INTERFACE PkgConfig::UNBOUND)
endif()
option(WITH_SYSTEMD "Attempts to link against and enable systemd daemon notification support" ON)
if (WITH_SYSTEMD)
if (WITH_SYSTEMD AND NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD libsystemd IMPORTED_TARGET)
if(SYSTEMD_FOUND)
@ -799,7 +819,9 @@ if(STATIC)
endif()
set(Boost_USE_MULTITHREADED TRUE) # Needed for macOS, at least, and won't hurt elsewhere
if (WIN32)
if(BUILD_STATIC_DEPS)
# StaticBuild.cmake sets Boost targets up for us
elseif (WIN32)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options locale)
else()
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options)
@ -874,7 +896,9 @@ if (BUILD_INTEGRATION)
target_compile_definitions(extra INTERFACE LOKI_ENABLE_INTEGRATION_TEST_HOOKS)
else()
option(USE_READLINE "Build with GNU readline support." ON)
if(USE_READLINE AND NOT DEPENDS)
if(USE_READLINE AND BUILD_STATIC_DEPS)
# readline target already set up
elseif(USE_READLINE AND NOT DEPENDS)
find_package(Readline)
if(READLINE_FOUND AND GNU_READLINE_FOUND)
add_library(readline INTERFACE)
@ -912,14 +936,18 @@ if (LOKI_DEBUG_SHORT_PROOFS)
endif()
add_library(sqlite3 INTERFACE)
if (NOT SQLITE3_LIBRARIES)
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
if(BUILD_STATIC_DEPS)
# sqlite3 target already set up
else()
add_library(sqlite3 INTERFACE)
if (NOT SQLITE3_LIBRARIES)
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
endif()
find_library(sqlite3_link_libs NAMES ${SQLITE3_LIBRARIES} PATHS ${SQLITE3_LIBRARY_DIRS})
message(STATUS "sqlite3: ${SQLITE3_LIBRARIES} ${sqlite3_link_libs}")
target_link_libraries(sqlite3 INTERFACE ${sqlite3_link_libs})
target_include_directories(sqlite3 INTERFACE ${SQLITE3_INCLUDE_DIRS})
endif()
find_library(sqlite3_link_libs NAMES ${SQLITE3_LIBRARIES} PATHS ${SQLITE3_LIBRARY_DIRS})
message(STATUS "sqlite3: ${SQLITE3_LIBRARIES} ${sqlite3_link_libs}")
target_link_libraries(sqlite3 INTERFACE ${sqlite3_link_libs})
target_include_directories(sqlite3 INTERFACE ${SQLITE3_INCLUDE_DIRS})
add_subdirectory(contrib)
add_subdirectory(src)

View File

@ -26,25 +26,23 @@
# 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.
if (NOT CMAKE_HOST_WIN32)
set (CMAKE_SYSTEM_NAME Windows)
if(NOT CMAKE_HOST_WIN32)
set(CMAKE_SYSTEM_NAME Windows)
endif()
set (GCC_PREFIX i686-w64-mingw32)
set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc)
set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++)
set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
set (CMAKE_NM nm CACHE FILEPATH "" FORCE)
set (CMAKE_LINKER ld CACHE FILEPATH "" FORCE)
#set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE)
set (CMAKE_RC_COMPILER windres)
set(ARCH_TRIPLET i686-w64-mingw32)
set(CMAKE_C_COMPILER ${ARCH_TRIPLET}-gcc-posix)
set(CMAKE_CXX_COMPILER ${ARCH_TRIPLET}-g++-posix)
set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
set(CMAKE_NM nm CACHE FILEPATH "" FORCE)
set(CMAKE_LINKER ld CACHE FILEPATH "" FORCE)
set(CMAKE_RC_COMPILER ${ARCH_TRIPLET}-windres)
set (CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw32")
if(MSYS2_FOLDER)
set(CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw32")
endif()
# Ensure cmake doesn't find things in the wrong places
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target
set (MINGW_FLAG "-m32")
set (USE_LTO_DEFAULT false)

View File

@ -30,21 +30,19 @@ if (NOT CMAKE_HOST_WIN32)
set (CMAKE_SYSTEM_NAME Windows)
endif()
set (GCC_PREFIX x86_64-w64-mingw32)
set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc)
set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++)
set (ARCH_TRIPLET x86_64-w64-mingw32)
set (CMAKE_C_COMPILER ${ARCH_TRIPLET}-gcc-posix)
set (CMAKE_CXX_COMPILER ${ARCH_TRIPLET}-g++-posix)
set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
set (CMAKE_NM nm CACHE FILEPATH "" FORCE)
set (CMAKE_LINKER ld CACHE FILEPATH "" FORCE)
#set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE)
set (CMAKE_RC_COMPILER windres)
set (CMAKE_RC_COMPILER ${ARCH_TRIPLET}-windres)
set (CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw64")
if(MSYS2_FOLDER)
set(CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw64")
endif()
# Ensure cmake doesn't find things in the wrong places
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target
set (MINGW_FLAG "-m64")
set (USE_LTO_DEFAULT false)

View File

@ -4,55 +4,40 @@ OPTION(USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" OFF)
OPTION(USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" OFF)
OPTION(TREZOR_DEBUG "Main trezor debugging switch" OFF)
# Helper function to fix cmake < 3.6.0 FindProtobuf variables
function(_trezor_protobuf_fix_vars)
if(${CMAKE_VERSION} VERSION_LESS "3.6.0")
foreach(UPPER
PROTOBUF_SRC_ROOT_FOLDER
PROTOBUF_IMPORT_DIRS
PROTOBUF_DEBUG
PROTOBUF_LIBRARY
PROTOBUF_PROTOC_LIBRARY
PROTOBUF_INCLUDE_DIR
PROTOBUF_PROTOC_EXECUTABLE
PROTOBUF_LIBRARY_DEBUG
PROTOBUF_PROTOC_LIBRARY_DEBUG
PROTOBUF_LITE_LIBRARY
PROTOBUF_LITE_LIBRARY_DEBUG
)
if (DEFINED ${UPPER})
string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER})
if (NOT DEFINED ${Camel})
set(${Camel} ${${UPPER}} PARENT_SCOPE)
endif()
endif()
endforeach()
endif()
endfunction()
add_library(protobuf INTERFACE)
# Use Trezor master switch
if (USE_DEVICE_TREZOR)
if (BUILD_STATIC_DEPS)
add_library(libusb INTERFACE)
target_link_libraries(libusb INTERFACE libusb_vendor)
target_compile_definitions(libusb INTERFACE HAVE_TREZOR_LIBUSB=1)
target_link_libraries(protobuf INTERFACE protobuf_lite)
target_compile_definitions(protobuf INTERFACE DEVICE_TREZOR_READY=1 PROTOBUF_INLINE_NOT_IN_HEADERS=0)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(protobuf INTERFACE TREZOR_DEBUG=1)
endif()
if(USE_DEVICE_TREZOR_UDP_RELEASE)
target_compile_definitions(protobuf INTERFACE USE_DEVICE_TREZOR_UDP_RELEASE=1)
endif()
return()
endif()
# Protobuf is required to build protobuf messages for Trezor
include(FindProtobuf OPTIONAL)
find_package(Protobuf)
_trezor_protobuf_fix_vars()
# Protobuf handling the cache variables set in docker.
if(NOT Protobuf_FOUND AND NOT Protobuf_LIBRARY AND NOT Protobuf_PROTOC_EXECUTABLE AND NOT Protobuf_INCLUDE_DIR)
if(NOT Protobuf_FOUND)
message(STATUS "Could not find Protobuf")
elseif(NOT Protobuf_LIBRARY OR NOT EXISTS "${Protobuf_LIBRARY}")
message(STATUS "Protobuf library not found: ${Protobuf_LIBRARY}")
elseif(NOT TARGET protobuf::libprotobuf)
message(STATUS "Protobuf library not found")
unset(Protobuf_FOUND)
elseif(NOT Protobuf_PROTOC_EXECUTABLE OR NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
message(STATUS "Protobuf executable not found: ${Protobuf_PROTOC_EXECUTABLE}")
unset(Protobuf_FOUND)
elseif(NOT Protobuf_INCLUDE_DIR OR NOT EXISTS "${Protobuf_INCLUDE_DIR}")
message(STATUS "Protobuf include dir not found: ${Protobuf_INCLUDE_DIR}")
unset(Protobuf_FOUND)
else()
message(STATUS "Protobuf lib: ${Protobuf_LIBRARY}, inc: ${Protobuf_INCLUDE_DIR}, protoc: ${Protobuf_PROTOC_EXECUTABLE}")
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR})
set(Protobuf_FOUND 1) # override found if all rquired info was provided by variables
message(STATUS "Protobuf lib ${Protobuf_VERSION}, protoc: ${Protobuf_PROTOC_EXECUTABLE}")
endif()
if(TREZOR_DEBUG)
@ -104,7 +89,7 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES=${Protobuf_INCLUDE_DIR};${CMAKE_BINARY_DIR}"
"-DCMAKE_CXX_STANDARD=11"
LINK_LIBRARIES ${Protobuf_LIBRARY}
LINK_LIBRARIES protobuf::libprotobuf
OUTPUT_VARIABLE OUTPUT
)
if(NOT Protobuf_COMPILE_TEST_PASSED)
@ -114,14 +99,15 @@ endif()
# Try to build protobuf messages
if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON AND Protobuf_COMPILE_TEST_PASSED)
set(ENV{PROTOBUF_INCLUDE_DIRS} "${Protobuf_INCLUDE_DIR}")
set(ENV{PROTOBUF_PROTOC_EXECUTABLE} "${Protobuf_PROTOC_EXECUTABLE}")
set(TREZOR_PROTOBUF_PARAMS "")
if (USE_DEVICE_TREZOR_DEBUG)
set(TREZOR_PROTOBUF_PARAMS "--debug")
endif()
execute_process(COMMAND ${TREZOR_PYTHON} tools/build_protob.py ${TREZOR_PROTOBUF_PARAMS} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
execute_process(COMMAND ${CMAKE_COMMAND} -E env "PROTOBUF_INCLUDE_DIRS=${Protobuf_INCLUDE_DIR}" "PROTOBUF_PROTOC_EXECUTABLE=${Protobuf_PROTOC_EXECUTABLE}"
${TREZOR_PYTHON} tools/build_protob.py ${TREZOR_PROTOBUF_PARAMS}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor
RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
if(RET)
message(WARNING "Trezor protobuf messages could not be regenerated (err=${RET}, python ${PYTHON})."
"OUT: ${OUT}, ERR: ${ERR}."
@ -129,43 +115,38 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON AND Protobuf_COMPILE_T
else()
message(STATUS "Trezor protobuf messages regenerated out: \"${OUT}.\"")
set(DEVICE_TREZOR_READY 1)
add_definitions(-DDEVICE_TREZOR_READY=1)
add_definitions(-DPROTOBUF_INLINE_NOT_IN_HEADERS=0)
target_compile_definitions(protobuf INTERFACE DEVICE_TREZOR_READY=1 PROTOBUF_INLINE_NOT_IN_HEADERS=0)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DTREZOR_DEBUG=1)
target_compile_definitions(protobuf INTERFACE TREZOR_DEBUG=1)
endif()
if(USE_DEVICE_TREZOR_UDP_RELEASE)
add_definitions(-DUSE_DEVICE_TREZOR_UDP_RELEASE=1)
target_compile_definitions(protobuf INTERFACE USE_DEVICE_TREZOR_UDP_RELEASE=1)
endif()
if (Protobuf_INCLUDE_DIR)
include_directories(${Protobuf_INCLUDE_DIR})
target_include_directories(protobuf INTERFACE ${Protobuf_INCLUDE_DIR})
endif()
target_link_libraries(protobuf INTERFACE protobuf::libprotobuf)
# LibUSB support, check for particular version
# Include support only if compilation test passes
if (USE_DEVICE_TREZOR_LIBUSB)
find_package(LibUSB)
endif()
add_library(libusb INTERFACE)
find_package(LibUSB)
if (LibUSB_COMPILE_TEST_PASSED)
add_definitions(-DHAVE_TREZOR_LIBUSB=1)
target_compile_definitions(libusb INTERFACE HAVE_TREZOR_LIBUSB=1)
if(LibUSB_INCLUDE_DIRS)
include_directories(${LibUSB_INCLUDE_DIRS})
target_include_directories(libusb INTERFACE ${LibUSB_INCLUDE_DIRS})
endif()
endif()
set(TREZOR_LIBUSB_LIBRARIES "")
if(LibUSB_COMPILE_TEST_PASSED)
list(APPEND TREZOR_LIBUSB_LIBRARIES ${LibUSB_LIBRARIES} ${LIBUSB_DEP_LINKER})
message(STATUS "Trezor compatible LibUSB found at: ${LibUSB_INCLUDE_DIRS}")
target_link_libraries(libusb INTERFACE ${LibUSB_LIBRARIES} ${LIBUSB_DEP_LINKER})
message(STATUS "Trezor compatible LibUSB found")
endif()
if (BUILD_GUI_DEPS)
set(TREZOR_DEP_LIBS "")
set(TREZOR_DEP_LINKER "")
if (Protobuf_LIBRARY)
list(APPEND TREZOR_DEP_LIBS ${Protobuf_LIBRARY})

View File

@ -12,13 +12,23 @@ file(MAKE_DIRECTORY ${LIBSODIUM_PREFIX}/include)
include(ExternalProject)
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0)
set(PROCESSOR_COUNT 1)
endif()
set(SODIUM_CONFIGURE ./configure --prefix=${LIBSODIUM_PREFIX} CC=${CMAKE_C_COMPILER})
set(SODIUM_CONFIGURE ./configure --prefix=${LIBSODIUM_PREFIX})
if (LIBSODIUM_CROSS_TARGET)
set(SODIUM_CONFIGURE ${SODIUM_CONFIGURE} --target=${LIBSODIUM_CROSS_TARGET} --host=${LIBSODIUM_CROSS_TARGET})
endif()
set(SODIUM_CONFIGURE ${SODIUM_CONFIGURE} --enable-static --disable-shared)
set(SODIUM_CONFIGURE ${SODIUM_CONFIGURE} --enable-static --disable-shared --with-pic --quiet)
if(CMAKE_C_COMPILER_LAUNCHER)
set(SODIUM_CONFIGURE ${SODIUM_CONFIGURE} "CC=${CMAKE_C_COMPILER_LAUNCHER} ${CMAKE_C_COMPILER}")
else()
set(SODIUM_CONFIGURE ${SODIUM_CONFIGURE} "CC=${CMAKE_C_COMPILER}")
endif()
ExternalProject_Add(libsodium_external
BUILD_IN_SOURCE ON
@ -27,12 +37,12 @@ ExternalProject_Add(libsodium_external
URL_HASH ${LIBSODIUM_HASH}
CONFIGURE_COMMAND ${SODIUM_CONFIGURE}
BUILD_COMMAND make -j${PROCESSOR_COUNT}
INSTALL_COMMAND ${MAKE}
INSTALL_COMMAND make install
BUILD_BYPRODUCTS ${LIBSODIUM_PREFIX}/lib/libsodium.a ${LIBSODIUM_PREFIX}/include
)
add_library(sodium_vendor STATIC IMPORTED GLOBAL)
add_dependencies(sodium_vendor libsodium_external)
set_target_properties(sodium_vendor PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBSODIUM_PREFIX}/include)
set_property(TARGET sodium_vendor PROPERTY IMPORTED_LOCATION ${LIBSODIUM_PREFIX}/lib/libsodium.a)
set_target_properties(sodium_vendor PROPERTIES
IMPORTED_LOCATION ${LIBSODIUM_PREFIX}/lib/libsodium.a
INTERFACE_INCLUDE_DIRECTORIES ${LIBSODIUM_PREFIX}/include)

458
cmake/StaticBuild.cmake Normal file
View File

@ -0,0 +1,458 @@
# cmake bits to do a full static build, downloading and building all dependencies.
# Most of these are CACHE STRINGs so that you can override them using -DWHATEVER during cmake
# invocation to override.
set(LOCAL_MIRROR "" CACHE STRING "local mirror path/URL for lib downloads")
set(OPENSSL_VERSION 1.1.1g CACHE STRING "openssl version")
set(OPENSSL_MIRROR ${LOCAL_MIRROR} https://www.openssl.org/source CACHE STRING "openssl download mirror(s)")
set(OPENSSL_SOURCE openssl-${OPENSSL_VERSION}.tar.gz)
set(OPENSSL_HASH SHA256=ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46
CACHE STRING "openssl source hash")
set(EXPAT_VERSION 2.2.9 CACHE STRING "expat version")
string(REPLACE "." "_" EXPAT_TAG "R_${EXPAT_VERSION}")
set(EXPAT_MIRROR ${LOCAL_MIRROR} https://github.com/libexpat/libexpat/releases/download/${EXPAT_TAG}
CACHE STRING "expat download mirror(s)")
set(EXPAT_SOURCE expat-${EXPAT_VERSION}.tar.xz)
set(EXPAT_HASH SHA512=e082874efcc4b00709e2c0192c88fb15dfc4f33fc3a2b09e619b010ea93baaf7e7572683f738463db0ce2350cab3de48a0c38af6b74d1c4f5a9e311f499edab0
CACHE STRING "expat source hash")
set(UNBOUND_VERSION 1.10.1 CACHE STRING "unbound version")
set(UNBOUND_MIRROR ${LOCAL_MIRROR} https://nlnetlabs.nl/downloads/unbound CACHE STRING "unbound download mirror(s)")
set(UNBOUND_SOURCE unbound-${UNBOUND_VERSION}.tar.gz)
set(UNBOUND_HASH SHA256=b73677c21a71cf92f15cc8cfe76a3d875e40f65b6150081c39620b286582d536
CACHE STRING "unbound source hash")
set(BOOST_VERSION 1.73.0 CACHE STRING "boost version")
set(BOOST_MIRROR ${LOCAL_MIRROR} https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source
CACHE STRING "boost download mirror(s)")
string(REPLACE "." "_" BOOST_VERSION_ ${BOOST_VERSION})
set(BOOST_SOURCE boost_${BOOST_VERSION_}.tar.bz2)
set(BOOST_HASH SHA256=4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402
CACHE STRING "boost source hash")
set(NCURSES_VERSION 6.2 CACHE STRING "ncurses version")
set(NCURSES_MIRROR ${LOCAL_MIRROR} http://ftpmirror.gnu.org/gnu/ncurses
CACHE STRING "ncurses download mirror(s)")
set(NCURSES_SOURCE ncurses-${NCURSES_VERSION}.tar.gz)
set(NCURSES_HASH SHA512=4c1333dcc30e858e8a9525d4b9aefb60000cfc727bc4a1062bace06ffc4639ad9f6e54f6bdda0e3a0e5ea14de995f96b52b3327d9ec633608792c99a1e8d840d
CACHE STRING "ncurses source hash")
set(READLINE_VERSION 8.0 CACHE STRING "readline version")
set(READLINE_MIRROR ${LOCAL_MIRROR} http://ftpmirror.gnu.org/gnu/readline
CACHE STRING "readline download mirror(s)")
set(READLINE_SOURCE readline-${READLINE_VERSION}.tar.gz)
set(READLINE_HASH SHA512=41759d27bc3a258fefd7f4ff3277fa6ab9c21abb7b160e1a75aa8eba547bd90b288514e76264bd94fb0172da8a4faa54aab2c07b68a0356918ecf7f1969e866f
CACHE STRING "readline source hash")
set(SQLITE3_VERSION 3320200 CACHE STRING "sqlite3 version")
set(SQLITE3_MIRROR ${LOCAL_MIRROR} https://www.sqlite.org/2020
CACHE STRING "sqlite3 download mirror(s)")
set(SQLITE3_SOURCE sqlite-autoconf-${SQLITE3_VERSION}.tar.gz)
set(SQLITE3_HASH SHA512=5b551a1366ce4fd5dfaa687e5021194d34315935b26dd7d71f8abc9935d03c3caea323263a8330fb42038c487cd399e95de68e451cc26d573f852f219c00a02f
CACHE STRING "sqlite3 source hash")
set(EUDEV_VERSION 3.2.9 CACHE STRING "eudev version")
set(EUDEV_MIRROR ${LOCAL_MIRROR} https://github.com/gentoo/eudev/archive/
CACHE STRING "eudev download mirror(s)")
set(EUDEV_SOURCE v${EUDEV_VERSION}.tar.gz)
set(EUDEV_HASH SHA512=33ee9849875fc381fc1bd9eef9119b96ed4014719ccf96f88c957e2c53ae6c46152bc0623e5efc99579a4063ab25251ed63ffe69441bca3b0074398cffda7747
CACHE STRING "eudev source hash")
set(LIBUSB_VERSION 1.0.23 CACHE STRING "libusb version")
set(LIBUSB_MIRROR ${LOCAL_MIRROR} https://github.com/libusb/libusb/releases/download/v${LIBUSB_VERSION}
CACHE STRING "libusb download mirror(s)")
set(LIBUSB_SOURCE libusb-${LIBUSB_VERSION}.tar.bz2)
set(LIBUSB_HASH SHA256=db11c06e958a82dac52cf3c65cb4dd2c3f339c8a988665110e0d24d19312ad8d
CACHE STRING "libusb source hash")
set(HIDAPI_VERSION 0.9.0 CACHE STRING "hidapi version")
set(HIDAPI_MIRROR ${LOCAL_MIRROR} https://github.com/libusb/hidapi/archive
CACHE STRING "hidapi download mirror(s)")
set(HIDAPI_SOURCE hidapi-${HIDAPI_VERSION}.tar.gz)
set(HIDAPI_HASH SHA512=d9f28d394b78daece7d2dfb946e62349a56b388b3a06241585c6fad5a4e24dc914723de6c0f12a9e51cd23fb245f6b5ac9b3721319646d5ba5912bbe0a3f9a52
CACHE STRING "hidapi source hash")
set(PROTOBUF_VERSION 3.12.3 CACHE STRING "protobuf version")
set(PROTOBUF_MIRROR ${LOCAL_MIRROR} https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}
CACHE STRING "protobuf mirror(s)")
set(PROTOBUF_SOURCE protobuf-cpp-${PROTOBUF_VERSION}.tar.gz)
set(PROTOBUF_HASH SHA512=a30677d152eee663960ed363b62464a455057796a5938e900deaa8fa0e3ba468675be450846b7c27b722114ee6d735bd27edc302f38a39486f7e44f71d155c66
CACHE STRING "protobuf source hash")
set(SODIUM_VERSION 1.0.18 CACHE STRING "libsodium version")
set(SODIUM_MIRROR ${LOCAL_MIRROR}
https://download.libsodium.org/libsodium/releases
https://github.com/jedisct1/libsodium/releases/download/${SODIUM_VERSION}-RELEASE
CACHE STRING "libsodium mirror(s)")
set(SODIUM_SOURCE libsodium-${SODIUM_VERSION}.tar.gz)
set(SODIUM_HASH SHA512=17e8638e46d8f6f7d024fe5559eccf2b8baf23e143fadd472a7d29d228b186d86686a5e6920385fe2020729119a5f12f989c3a782afbd05a8db4819bb18666ef
CACHE STRING "libsodium source hash")
set(ZMQ_VERSION 4.3.2 CACHE STRING "libzmq version")
set(ZMQ_MIRROR ${LOCAL_MIRROR} https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}
CACHE STRING "libzmq mirror(s)")
set(ZMQ_SOURCE zeromq-${ZMQ_VERSION}.tar.gz)
set(ZMQ_HASH SHA512=b6251641e884181db9e6b0b705cced7ea4038d404bdae812ff47bdd0eed12510b6af6846b85cb96898e253ccbac71eca7fe588673300ddb9c3109c973250c8e4
CACHE STRING "libzmq source hash")
include(ExternalProject)
set(DEPS_DESTDIR ${CMAKE_BINARY_DIR}/static-deps)
set(DEPS_SOURCEDIR ${CMAKE_BINARY_DIR}/static-deps-sources)
include_directories(BEFORE SYSTEM ${DEPS_DESTDIR}/include)
file(MAKE_DIRECTORY ${DEPS_DESTDIR}/include)
set(deps_cc "${CMAKE_C_COMPILER}")
set(deps_cxx "${CMAKE_CXX_COMPILER}")
if(CMAKE_C_COMPILER_LAUNCHER)
set(deps_cc "${CMAKE_C_COMPILER_LAUNCHER} ${deps_cc}")
endif()
if(CMAKE_CXX_COMPILER_LAUNCHER)
set(deps_cxx "${CMAKE_CXX_COMPILER_LAUNCHER} ${deps_cxx}")
endif()
function(expand_urls output source_file)
set(expanded)
foreach(mirror ${ARGN})
list(APPEND expanded "${mirror}/${source_file}")
endforeach()
set(${output} "${expanded}" PARENT_SCOPE)
endfunction()
function(add_static_target target ext_target libname)
add_library(${target} STATIC IMPORTED GLOBAL)
add_dependencies(${target} ${ext_target})
set_target_properties(${target} PROPERTIES
IMPORTED_LOCATION ${DEPS_DESTDIR}/lib/${libname}
)
endfunction()
if(USE_LTO)
set(flto "-flto")
else()
set(flto "")
endif()
set(cross_host "")
set(cross_rc "")
if(CMAKE_CROSSCOMPILING)
set(cross_host "--host=${ARCH_TRIPLET}")
if (ARCH_TRIPLET MATCHES mingw AND CMAKE_RC_COMPILER)
set(cross_rc "WINDRES=${CMAKE_RC_COMPILER}")
endif()
endif()
# Builds a target; takes the target name (e.g. "readline") and builds it in an external project with
# target name suffixed with `_external`. Its upper-case value is used to get the download details
# (from the variables set above). The following options are supported and passed through to
# ExternalProject_Add if specified. If omitted, these defaults are used:
set(build_def_DEPENDS "")
set(build_def_PATCH_COMMAND "")
set(build_def_CONFIGURE_COMMAND ./configure ${cross_host} --disable-shared --prefix=${DEPS_DESTDIR} --with-pic
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=-O2 ${flto}" "CXXFLAGS=-O2 ${flto}" ${cross_rc})
set(build_def_BUILD_COMMAND make)
set(build_def_INSTALL_COMMAND make install)
set(build_def_BUILD_BYPRODUCTS ${DEPS_DESTDIR}/lib/lib___TARGET___.a ${DEPS_DESTDIR}/include/___TARGET___.h)
function(build_external target)
set(options DEPENDS PATCH_COMMAND CONFIGURE_COMMAND BUILD_COMMAND INSTALL_COMMAND BUILD_BYPRODUCTS)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "${options}")
foreach(o ${options})
if(NOT DEFINED arg_${o})
set(arg_${o} ${build_def_${o}})
endif()
endforeach()
string(REPLACE ___TARGET___ ${target} arg_BUILD_BYPRODUCTS "${arg_BUILD_BYPRODUCTS}")
string(TOUPPER "${target}" prefix)
expand_urls(urls ${${prefix}_SOURCE} ${${prefix}_MIRROR})
ExternalProject_Add("${target}_external"
DEPENDS ${arg_DEPENDS}
BUILD_IN_SOURCE ON
PREFIX ${DEPS_SOURCEDIR}
URL ${urls}
URL_HASH ${${prefix}_HASH}
DOWNLOAD_NO_PROGRESS ON
PATCH_COMMAND ${arg_PATCH_COMMAND}
CONFIGURE_COMMAND ${arg_CONFIGURE_COMMAND}
BUILD_COMMAND ${arg_BUILD_COMMAND}
INSTALL_COMMAND ${arg_INSTALL_COMMAND}
BUILD_BYPRODUCTS ${arg_BUILD_BYPRODUCTS}
)
endfunction()
set(openssl_system_env "")
if(CMAKE_CROSSCOMPILING)
if(ARCH_TRIPLET STREQUAL x86_64-w64-mingw32)
set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER})
elseif(ARCH_TRIPLET STREQUAL i686-w64-mingw32)
set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER})
endif()
endif()
build_external(openssl
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${deps_cc} ${openssl_system_env} ./config
--prefix=${DEPS_DESTDIR} no-shared no-capieng no-dso no-dtls1 no-ec_nistp_64_gcc_128 no-gost
no-heartbeats no-md2 no-rc5 no-rdrand no-rfc3779 no-sctp no-ssl-trace no-ssl2 no-ssl3
no-static-engine no-tests no-weak-ssl-ciphers no-zlib no-zlib-dynamic "CFLAGS=-O2 ${flto}"
INSTALL_COMMAND make install_sw
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libssl.a ${DEPS_DESTDIR}/lib/libcrypto.a
${DEPS_DESTDIR}/include/openssl/ssl.h ${DEPS_DESTDIR}/include/openssl/crypto.h
)
add_static_target(OpenSSL::SSL openssl_external libssl.a)
add_static_target(OpenSSL::Crypto openssl_external libcrypto.a)
set(OPENSSL_INCLUDE_DIR ${DEPS_DESTDIR}/include)
set(OPENSSL_VERSION 1.1.1)
build_external(expat
CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --enable-static
--disable-shared --with-pic --without-examples --without-tests --without-docbook --without-xmlwf
"CC=${deps_cc}" "CFLAGS=-O2 ${flto}"
)
add_static_target(expat expat_external libexpat.a)
build_external(unbound
DEPENDS openssl_external expat_external
CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} --prefix=${DEPS_DESTDIR} --disable-shared
--enable-static --with-libunbound-only --with-pic
--$<IF:$<BOOL:${USE_LTO}>,enable,disable>-flto --with-ssl=${DEPS_DESTDIR}
--with-libexpat=${DEPS_DESTDIR}
"CC=${deps_cc}" "CFLAGS=-O2 ${flto}"
)
add_static_target(libunbound unbound_external libunbound.a)
if(WIN32)
set_target_properties(libunbound PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32;crypt32;iphlpapi")
endif()
set(boost_threadapi "pthread")
set(boost_bootstrap_cxx "CXX=${deps_cxx}")
set(boost_toolset "")
set(boost_extra "")
if(USE_LTO)
list(APPEND boost_extra "lto=on")
endif()
if(CMAKE_CROSSCOMPILING)
set(boost_bootstrap_cxx "") # need to use our native compiler to bootstrap
if(ARCH_TRIPLET MATCHES mingw)
set(boost_threadapi win32)
list(APPEND boost_extra "target-os=windows")
if(ARCH_TRIPLET MATCHES x86_64)
list(APPEND boost_extra "address-model=64")
else()
list(APPEND boost_extra "address-model=32")
endif()
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(boost_toolset gcc)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
set(boost_toolset clang)
else()
message(FATAL_ERROR "don't know how to build boost with ${CMAKE_CXX_COMPILER_ID}")
endif()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/user-config.bjam "using ${boost_toolset} : : ${deps_cxx} ;")
set(boost_patch_commands "")
if(APPLE AND BOOST_VERSION VERSION_LESS 1.74.0)
set(boost_patch_commands PATCH_COMMAND patch -p1 -d tools/build -i ${PROJECT_SOURCE_DIR}/utils/build_scripts/boostorg-build-pr560-macos-build-fix.patch)
endif()
build_external(boost
# PATCH_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/user-config.bjam tools/build/src/user-config.jam
${boost_patch_commands}
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${boost_bootstrap_cxx}
./bootstrap.sh --without-icu --prefix=${DEPS_DESTDIR} --with-toolset=${boost_toolset}
--with-libraries=chrono,filesystem,program_options,system,thread,date_time,regex,serialization,locale,atomic
BUILD_COMMAND true
INSTALL_COMMAND
./b2 -d0 variant=release link=static runtime-link=static optimization=speed ${boost_extra}
threading=multi threadapi=${boost_threadapi} cxxflags=-fPIC cxxstd=14 visibility=global
--disable-icu --user-config=${CMAKE_CURRENT_BINARY_DIR}/user-config.bjam
install
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libboost_atomic.a
${DEPS_DESTDIR}/lib/libboost_chrono.a
${DEPS_DESTDIR}/lib/libboost_date_time.a
${DEPS_DESTDIR}/lib/libboost_filesystem.a
${DEPS_DESTDIR}/lib/libboost_locale.a
${DEPS_DESTDIR}/lib/libboost_program_options.a
${DEPS_DESTDIR}/lib/libboost_regex.a
${DEPS_DESTDIR}/lib/libboost_serialization.a
${DEPS_DESTDIR}/lib/libboost_system.a
${DEPS_DESTDIR}/lib/libboost_thread.a
${DEPS_DESTDIR}/include/boost/version.hpp
)
add_library(boost_core INTERFACE)
add_dependencies(boost_core INTERFACE boost_external)
target_include_directories(boost_core SYSTEM INTERFACE ${DEPS_DESTDIR}/include)
add_library(Boost::boost ALIAS boost_core)
foreach(boostlib atomic chrono date_time filesystem locale program_options regex serialization system thread)
add_static_target(Boost::${boostlib} boost_external libboost_${boostlib}.a)
target_link_libraries(Boost::${boostlib} INTERFACE boost_core)
endforeach()
target_link_libraries(Boost::locale INTERFACE Boost::thread)
set(Boost_FOUND ON)
set(Boost_VERSION ${BOOST_VERSION})
build_external(sqlite3)
add_static_target(sqlite3 sqlite_external libsqlite3.a)
if (NOT WIN32)
build_external(ncurses
CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --without-debug --without-ada
--without-cxx-binding --without-cxx --without-ticlib --without-tic --without-progs
--without-tests --without-tack --without-manpages --with-termlib --disable-tic-depends
--disable-big-strings --disable-ext-colors --enable-pc-files --without-shared --without-pthread
--disable-rpath --disable-colorfgbg --disable-ext-mouse --disable-symlinks --enable-warnings
--enable-assertions --with-default-terminfo-dir=/etc/_terminfo_
--with-terminfo-dirs=/etc/_terminfo_ --disable-pc-files --enable-database --enable-sp-funcs
--disable-term-driver --enable-interop --enable-widec "CC=${CMAKE_C_COMPILER}" "CFLAGS=-O2 -fPIC ${flto}"
INSTALL_COMMAND make install.libs
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libncursesw.a
${DEPS_DESTDIR}/lib/libtinfow.a
${DEPS_DESTDIR}/include/ncursesw
${DEPS_DESTDIR}/include/ncursesw/termcap.h
${DEPS_DESTDIR}/include/ncursesw/ncurses.h
)
add_static_target(ncurses_tinfo ncurses_external libtinfow.a)
build_external(readline
DEPENDS ncurses_external
CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --disable-shared --with-curses
"CC=${deps_cc}" "CFLAGS=-fPIC ${flto}"
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libreadline.a
${DEPS_DESTDIR}/include/readline
${DEPS_DESTDIR}/include/readline/readline.h
)
add_static_target(readline readline_external libreadline.a)
set_target_properties(readline PROPERTIES
INTERFACE_LINK_LIBRARIES ncurses_tinfo
INTERFACE_COMPILE_DEFINITIONS HAVE_READLINE)
endif()
if(APPLE OR WIN32)
add_library(libudev INTERFACE)
set(maybe_eudev "")
else()
build_external(eudev
CONFIGURE_COMMAND autoreconf -ivf && ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --disable-shared --disable-introspection
--disable-programs --disable-manpages --disable-hwdb --with-pic "CC=${deps_cc}" "CFLAGS=-O2 ${flto}"
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libudev.a
${DEPS_DESTDIR}/include/libudev.h
)
add_static_target(libudev eudev_external libudev.a)
set(maybe_eudev "eudev_external")
endif()
build_external(libusb
CONFIGURE_COMMAND autoreconf -ivf && ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --disable-shared --disable-udev --with-pic
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=-O2 ${flto}" "CXXFLAGS=-O2 ${flto}"
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libusb-1.0.a
${DEPS_DESTDIR}/include/libusb-1.0
${DEPS_DESTDIR}/include/libusb-1.0/libusb.h
)
add_static_target(libusb_vendor libusb_external libusb-1.0.a)
set_target_properties(libusb_vendor PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${DEPS_DESTDIR}/include/libusb-1.0)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(hidapi_libusb_lib libhidapi-libusb.a)
set(hidapi_lib_byproducts ${DEPS_DESTDIR}/lib/libhidapi-libusb.a ${DEPS_DESTDIR}/lib/libhidapi-hidraw.a)
else()
set(hidapi_libusb_lib libhidapi.a)
set(hidapi_lib_byproducts ${DEPS_DESTDIR}/lib/libhidapi.a)
endif()
build_external(hidapi
DEPENDS ${maybe_eudev} libusb_external
CONFIGURE_COMMAND autoreconf -ivf && ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --disable-shared --enable-static --with-pic
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=-O2 ${flto}" "CXXFLAGS=-O2 ${flto}"
"libudev_CFLAGS=-I${DEPS_DESTDIR}/include" "libudev_LIBS="
"libusb_CFLAGS=-I${DEPS_DESTDIR}/include/libusb-1.0" "libusb_LIBS="
BUILD_BYPRODUCTS
${hidapi_lib_byproducts}
${DEPS_DESTDIR}/include/hidapi
${DEPS_DESTDIR}/include/hidapi/hidapi.h
)
set(HIDAPI_FOUND TRUE)
add_static_target(hidapi_libusb hidapi_external ${hidapi_libusb_lib})
set_target_properties(hidapi_libusb PROPERTIES
INTERFACE_LINK_LIBRARIES "libusb_vendor;libudev"
INTERFACE_COMPILE_DEFINITIONS HAVE_HIDAPI)
build_external(protobuf
CONFIGURE_COMMAND
./configure ${cross_host} --disable-shared --prefix=${DEPS_DESTDIR} --with-pic
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=-O2 ${flto}" "CXXFLAGS=-O2 ${flto}"
"CPP=${deps_cc} -E" "CXXCPP=${deps_cxx} -E"
"CC_FOR_BUILD=${deps_cc}" "CXX_FOR_BUILD=${deps_cxx}" # Thanks Google for making people hunt for undocumented magic variables
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libprotobuf-lite.a
${DEPS_DESTDIR}/lib/libprotobuf.a
${DEPS_DESTDIR}/lib/libprotoc.a
${DEPS_DESTDIR}/include/google/protobuf
)
add_static_target(protobuf_lite protobuf_external libprotobuf-lite.a)
add_static_target(protobuf_bloated protobuf_external libprotobuf.a)
build_external(sodium)
add_static_target(sodium sodium_external libsodium.a)
if(ZMQ_VERSION VERSION_LESS 4.3.3 AND CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES mingw)
set(zmq_patch PATCH_COMMAND patch -p1 -i ${PROJECT_SOURCE_DIR}/utils/build_scripts/libzmq-pr3601-mingw-build-fix.patch
COMMAND patch -p1 -i ${PROJECT_SOURCE_DIR}/utils/build_scripts/libzmq-pr3613-fix-funcptr-call.patch)
endif()
build_external(zmq
DEPENDS sodium_external
${zmq_patch}
CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --enable-static --disable-shared
--disable-curve-keygen --enable-curve --disable-drafts --disable-libunwind --with-libsodium
--without-pgm --without-norm --without-vmci --without-docs --with-pic --disable-Werror
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=-O2 -fstack-protector ${flto}" "CXXFLAGS=-O2 -fstack-protector ${flto}"
"sodium_CFLAGS=-I${DEPS_DESTDIR}/include" "sodium_LIBS=-L${DEPS_DESTDIR}/lib -lsodium"
)
add_static_target(libzmq zmq_external libzmq.a)
set(libzmq_link_libs "sodium")
if(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES mingw)
list(APPEND libzmq_link_libs iphlpapi)
endif()
set_target_properties(libzmq PROPERTIES INTERFACE_LINK_LIBRARIES "${libzmq_link_libs}")

View File

@ -33,7 +33,7 @@
# ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with
# others.
if(NOT STATIC)
if(NOT STATIC AND NOT BUILD_STATIC_DEPS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MINIUPNPC miniupnpc>=2.1)
pkg_check_modules(LOKIMQ liblokimq>=1.1.4)

2
external/loki-mq vendored

@ -1 +1 @@
Subproject commit 17b912ee662e9a8fcbbd0f27626b6999b1720346
Subproject commit 843dbc4e2cc07d077ee8975c66a2a6c290bfc06a

View File

@ -27,6 +27,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_library(blocks blocks.cpp)
target_link_libraries(blocks PRIVATE Boost::boost)
foreach(BLOB_NAME checkpoints testnet_blocks stagenet_blocks)
set(OUTPUT_C_SOURCE "generated_${BLOB_NAME}.c")

View File

@ -43,17 +43,26 @@ target_link_libraries(device
version
extra)
find_package(HIDAPI)
if(BUILD_STATIC_DEPS)
message(STATUS "Using HIDAPI from static build deps")
else()
add_library(hidapi_libusb INTERFACE)
find_package(HIDAPI)
if (HIDAPI_FOUND)
message(STATUS "Using HIDAPI ${HIDAPI_LIBRARIES} (includes at ${HIDAPI_INCLUDE_DIR})")
target_compile_definitions(hidapi_libusb INTERFACE HAVE_HIDAPI)
target_include_directories(hidapi_libusb INTERFACE ${HIDAPI_INCLUDE_DIR})
target_link_libraries(hidapi_libusb INTERFACE ${HIDAPI_LIBRARIES})
else (HIDAPI_FOUND)
message(STATUS "Could not find HIDAPI")
endif()
endif()
if (HIDAPI_FOUND)
message(STATUS "Using HIDAPI ${HIDAPI_LIBRARIES} (includes at ${HIDAPI_INCLUDE_DIR})")
target_sources(device PRIVATE
device_ledger.cpp
device_io_hid.cpp
)
target_compile_definitions(device PUBLIC HAVE_HIDAPI)
target_include_directories(device PRIVATE ${HIDAPI_INCLUDE_DIR})
target_link_libraries(device PRIVATE ${HIDAPI_LIBRARIES})
else (HIDAPI_FOUND)
message(STATUS "Could not find HIDAPI")
target_link_libraries(device PRIVATE hidapi_libusb)
endif()

View File

@ -58,8 +58,8 @@ if(DEVICE_TREZOR_READY)
sodium
Boost::chrono
Boost::regex
${Protobuf_LIBRARY}
${TREZOR_LIBUSB_LIBRARIES}
libusb
protobuf
extra)
else()

View File

@ -32,6 +32,7 @@ add_library(mnemonics
target_link_libraries(mnemonics
PRIVATE
cncrypto
epee
easylogging
extra)

View File

@ -52,6 +52,7 @@ target_link_libraries(wallet
Boost::thread
PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
extra)
loki_add_executable(wallet_rpc_server "loki-wallet-rpc"

View File

@ -30,6 +30,7 @@ add_executable(difficulty-tests
difficulty.cpp)
target_link_libraries(difficulty-tests
PRIVATE
cncrypto
cryptonote_basic
easylogging
extra)

View File

@ -0,0 +1,21 @@
diff --git a/src/tools/darwin.jam b/src/tools/darwin.jam
index 8d477410b0..97e7ecb851 100644
--- a/src/tools/darwin.jam
+++ b/src/tools/darwin.jam
@@ -137,13 +137,14 @@ rule init ( version ? : command * : options * : requirement * )
# - Set the toolset generic common options.
common.handle-options darwin : $(condition) : $(command) : $(options) ;
+ real-version = [ regex.split $(real-version) \\. ] ;
# - GCC 4.0 and higher in Darwin does not have -fcoalesce-templates.
- if $(real-version) < "4.0.0"
+ if [ version.version-less $(real-version) : 4 0 ]
{
flags darwin.compile.c++ OPTIONS $(condition) : -fcoalesce-templates ;
}
# - GCC 4.2 and higher in Darwin does not have -Wno-long-double.
- if $(real-version) < "4.2.0"
+ if [ version.version-less $(real-version) : 4 2 ]
{
flags darwin.compile OPTIONS $(condition) : -Wno-long-double ;
}

View File

@ -0,0 +1,69 @@
diff --git a/src/thread.cpp b/src/thread.cpp
index b14d70757..3675899be 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -32,6 +32,10 @@
#include "thread.hpp"
#include "err.hpp"
+#ifdef ZMQ_HAVE_WINDOWS
+#include <winnt.h>
+#endif
+
bool zmq::thread_t::get_started () const
{
return _started;
@@ -113,10 +117,22 @@ struct thread_info_t
#pragma pack(pop)
}
+typedef struct _MY_EXCEPTION_REGISTRATION_RECORD
+{
+ struct _MY_EXCEPTION_REGISTRATION_RECORD *Next;
+ void *Handler;
+} MY_EXCEPTION_REGISTRATION_RECORD;
+
+static EXCEPTION_DISPOSITION NTAPI continue_execution (EXCEPTION_RECORD *rec,
+ void *frame, CONTEXT *ctx, void *disp)
+{
+ return ExceptionContinueExecution;
+}
+
void zmq::thread_t::
applyThreadName () // to be called in secondary thread context
{
- if (!_name[0])
+ if (!_name[0] || !IsDebuggerPresent())
return;
thread_info_t thread_info;
@@ -125,17 +141,19 @@ void zmq::thread_t::
thread_info._thread_id = -1;
thread_info._flags = 0;
-#pragma warning(push)
-#pragma warning(disable : 6320 6322)
- __try {
- DWORD MS_VC_EXCEPTION = 0x406D1388;
+ NT_TIB *tib = ((NT_TIB*)NtCurrentTeb());
+
+ MY_EXCEPTION_REGISTRATION_RECORD rec;
+ rec.Next = (MY_EXCEPTION_REGISTRATION_RECORD *)tib->ExceptionList;
+ rec.Handler = continue_execution;
+
+ // push our handler, raise, and finally pop our handler
+ tib->ExceptionList = (_EXCEPTION_REGISTRATION_RECORD *)&rec;
+ DWORD MS_VC_EXCEPTION = 0x406D1388;
RaiseException (MS_VC_EXCEPTION, 0,
- sizeof (thread_info) / sizeof (ULONG_PTR),
- (ULONG_PTR *) &thread_info);
- }
- __except (EXCEPTION_CONTINUE_EXECUTION) {
- }
-#pragma warning(pop)
+ sizeof (thread_info) / sizeof (ULONG_PTR),
+ (ULONG_PTR *) &thread_info);
+ tib->ExceptionList = (_EXCEPTION_REGISTRATION_RECORD *)(((MY_EXCEPTION_REGISTRATION_RECORD *)tib->ExceptionList)->Next);
}
#elif defined ZMQ_HAVE_VXWORKS

View File

@ -0,0 +1,43 @@
diff --git a/RELICENSE/tomzbench.md b/RELICENSE/tomzbench.md
new file mode 100644
index 000000000..1cbcc4fdb
--- /dev/null
+++ b/RELICENSE/tomzbench.md
@@ -0,0 +1,14 @@
+# Permission to Relicense under MPLv2
+
+This is a statement by Thomas Chiantia
+that grants permission to relicense its copyrights in the libzmq C++
+library (ZeroMQ) under the Mozilla Public License v2 (MPLv2).
+
+A portion of the commits made by the Github handle "tomzbench", with
+commit author "Thomas<Thomas@Altronix.com>", are copyright of
+Thomas Chiantia.
+This document hereby grants the libzmq project team to relicense libzmq,
+including all past, present and future contributions of the author listed above.
+
+Thomas Chiantia
+2019/08/10
diff --git a/src/thread.cpp b/src/thread.cpp
index 2cad2adaa..6f07e9cee 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -117,11 +117,14 @@ struct thread_info_t
#pragma pack(pop)
}
-typedef struct _MY_EXCEPTION_REGISTRATION_RECORD
+struct MY_EXCEPTION_REGISTRATION_RECORD
{
- struct _MY_EXCEPTION_REGISTRATION_RECORD *Next;
- void *Handler;
-} MY_EXCEPTION_REGISTRATION_RECORD;
+ typedef EXCEPTION_DISPOSITION (NTAPI *HandlerFunctionType) (
+ EXCEPTION_RECORD *, void *, CONTEXT *, void *);
+
+ MY_EXCEPTION_REGISTRATION_RECORD *Next;
+ HandlerFunctionType Handler;
+};
static EXCEPTION_DISPOSITION NTAPI continue_execution (EXCEPTION_RECORD *rec,
void *frame,