Build a static libzmq if no system one or system one is too old

This commit is contained in:
Jason Rhinelander 2020-03-05 01:00:35 -04:00
parent 882750b700
commit 443eca3955
4 changed files with 57 additions and 0 deletions

View File

@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.5)
project(liblokimq CXX)
include(GNUInstallDirs)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
add_library(lokimq
lokimq/lokimq.cpp
lokimq/bt_serialize.cpp
@ -16,6 +20,16 @@ install(
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lokimq
)
# We require cppzmq >= 4.3, and versions before 4.3.2 have some security issues, so try to find
# >=4.3.2 on the system and, if we don't (or found an old one) build a bundled one.
include(FindPkgConfig)
pkg_search_module(libzmq QUIET libzmq>=4.3.2)
if(NOT libzmq_FOUND)
message(STATUS "libzmq >= 4.3.2 not found, building bundled 4.3.2")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/local-libzmq")
include(LocalLibzmq)
endif()
set(CPPZMQ_BUILD_TESTS OFF CACHE BOOL "Disable cppzmq tests")
add_subdirectory(cppzmq EXCLUDE_FROM_ALL)

View File

@ -0,0 +1,6 @@
# cppzmq expects these targets:
add_library(libzmq ALIAS libzmq_vendor)
add_library(libzmq-static ALIAS libzmq_vendor)
set(ZeroMQ_FOUND ON)

View File

@ -0,0 +1,33 @@
set(LIBZMQ_PREFIX ${CMAKE_BINARY_DIR}/libzmq)
set(ZeroMQ_VERSION 4.3.2)
set(LIBZMQ_URL https://github.com/zeromq/libzmq/releases/download/v${ZeroMQ_VERSION}/zeromq-${ZeroMQ_VERSION}.tar.gz)
set(LIBZMQ_HASH SHA512=b6251641e884181db9e6b0b705cced7ea4038d404bdae812ff47bdd0eed12510b6af6846b85cb96898e253ccbac71eca7fe588673300ddb9c3109c973250c8e4)
message(${LIBZMQ_URL})
if(LIBZMQ_TARBALL_URL)
# make a build time override of the tarball url so we can fetch it if the original link goes away
set(LIBZMQ_URL ${LIBZMQ_TARBALL_URL})
endif()
file(MAKE_DIRECTORY ${LIBZMQ_PREFIX}/include)
include(ExternalProject)
include(ProcessorCount)
ExternalProject_Add(libzmq_external
PREFIX ${LIBZMQ_PREFIX}
URL ${LIBZMQ_URL}
URL_HASH ${LIBZMQ_HASH}
CMAKE_ARGS -DWITH_LIBSODIUM=ON -DZMQ_BUILD_TESTS=OFF -DWITH_PERF_TOOL=OFF -DENABLE_DRAFTS=OFF
-DBUILD_SHARED=OFF -DBUILD_STATIC=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=${LIBZMQ_PREFIX}
#BUILD_BYPRODUCTS ${LIBSODIUM_PREFIX}/lib/libsodium.a ${LIBSODIUM_PREFIX}/include
)
add_library(libzmq_vendor STATIC IMPORTED GLOBAL)
add_dependencies(libzmq_vendor libzmq_external)
set_target_properties(libzmq_vendor PROPERTIES
IMPORTED_LOCATION ${LIBZMQ_PREFIX}/lib/libzmq.a
INTERFACE_INCLUDE_DIRECTORIES ${LIBZMQ_PREFIX}/include
)

View File

@ -0,0 +1,4 @@
LocalLibzmq.cmake - builds a local static copy
FindZeroMQ.cmake - overrides cppzmq's version with a simple file that just sets up the minimum bits
cppzmq needs to use our static copy build above.