mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
70b9fed4fd
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.
48 lines
1.9 KiB
CMake
48 lines
1.9 KiB
CMake
set(LIBSODIUM_PREFIX ${CMAKE_BINARY_DIR}/libsodium)
|
|
set(LIBSODIUM_URL https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz)
|
|
set(LIBSODIUM_HASH SHA512=17e8638e46d8f6f7d024fe5559eccf2b8baf23e143fadd472a7d29d228b186d86686a5e6920385fe2020729119a5f12f989c3a782afbd05a8db4819bb18666ef)
|
|
|
|
if(SODIUM_TARBALL_URL)
|
|
# make a build time override of the tarball url so we can fetch it if the original link goes away
|
|
set(LIBSODIUM_URL ${SODIUM_TARBALL_URL})
|
|
endif()
|
|
|
|
|
|
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})
|
|
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 --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
|
|
PREFIX ${LIBSODIUM_PREFIX}
|
|
URL ${LIBSODIUM_URL}
|
|
URL_HASH ${LIBSODIUM_HASH}
|
|
CONFIGURE_COMMAND ${SODIUM_CONFIGURE}
|
|
BUILD_COMMAND make -j${PROCESSOR_COUNT}
|
|
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
|
|
IMPORTED_LOCATION ${LIBSODIUM_PREFIX}/lib/libsodium.a
|
|
INTERFACE_INCLUDE_DIRECTORIES ${LIBSODIUM_PREFIX}/include)
|