2020-02-06 01:21:02 +01:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
|
|
|
project(liblokimq CXX)
|
|
|
|
|
2020-03-05 06:00:35 +01:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2020-03-13 15:37:31 +01:00
|
|
|
set(LOKIMQ_VERSION_MAJOR 1)
|
|
|
|
set(LOKIMQ_VERSION_MINOR 0)
|
|
|
|
set(LOKIMQ_VERSION_PATCH 0)
|
|
|
|
set(LOKIMQ_VERSION "${LOKIMQ_VERSION_MAJOR}.${LOKIMQ_VERSION_MINOR}.${LOKIMQ_VERSION_PATCH}")
|
|
|
|
message(STATUS "lokimq v${LOKIMQ_VERSION}")
|
|
|
|
|
|
|
|
set(LOKIMQ_LIBVERSION 0)
|
|
|
|
|
2020-03-13 18:26:36 +01:00
|
|
|
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries instead of static ones" ON)
|
|
|
|
|
|
|
|
|
2020-03-05 06:00:35 +01:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
2020-03-13 19:29:30 +01:00
|
|
|
configure_file(lokimq/version.h.in lokimq/version.h @ONLY)
|
2020-03-13 19:31:43 +01:00
|
|
|
configure_file(liblokimq.pc.in liblokimq.pc @ONLY)
|
2020-03-13 19:29:30 +01:00
|
|
|
|
2020-03-02 16:21:52 +01:00
|
|
|
add_library(lokimq
|
2020-03-13 18:02:54 +01:00
|
|
|
lokimq/auth.cpp
|
|
|
|
lokimq/batch.cpp
|
2020-02-06 01:21:02 +01:00
|
|
|
lokimq/bt_serialize.cpp
|
2020-03-13 18:02:54 +01:00
|
|
|
lokimq/connections.cpp
|
|
|
|
lokimq/jobs.cpp
|
|
|
|
lokimq/lokimq.cpp
|
|
|
|
lokimq/proxy.cpp
|
|
|
|
lokimq/worker.cpp
|
2020-03-02 16:21:52 +01:00
|
|
|
)
|
2020-03-13 15:37:31 +01:00
|
|
|
set_target_properties(lokimq PROPERTIES SOVERSION ${LOKIMQ_LIBVERSION})
|
|
|
|
|
2020-03-13 19:27:29 +01:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
target_link_libraries(lokimq PRIVATE Threads::Threads)
|
|
|
|
|
2020-03-14 18:19:13 +01:00
|
|
|
# libzmq is nearly impossible to link statically from a system-installed static library: it depends
|
|
|
|
# on a ton of other libraries which typically are not all statically available. So if the caller
|
|
|
|
# asked us to do things statically, don't even try to find a system lib and just build it. If they
|
|
|
|
# really want it, they can set up the libzmq_FOUND etc. variables themselves.
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
include(FindPkgConfig)
|
|
|
|
pkg_search_module(libzmq QUIET libzmq>=4.3)
|
|
|
|
endif()
|
2020-03-05 06:00:35 +01:00
|
|
|
if(NOT libzmq_FOUND)
|
2020-03-13 23:40:08 +01:00
|
|
|
message(STATUS "libzmq >= 4.3 not found, building bundled 4.3.2")
|
2020-03-05 06:00:35 +01:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/local-libzmq")
|
|
|
|
include(LocalLibzmq)
|
|
|
|
endif()
|
|
|
|
|
2020-03-02 16:21:52 +01:00
|
|
|
set(CPPZMQ_BUILD_TESTS OFF CACHE BOOL "Disable cppzmq tests")
|
2020-02-06 01:21:02 +01:00
|
|
|
add_subdirectory(cppzmq EXCLUDE_FROM_ALL)
|
|
|
|
|
2020-03-02 16:21:52 +01:00
|
|
|
target_include_directories(lokimq
|
|
|
|
PUBLIC
|
|
|
|
$<INSTALL_INTERFACE:>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mapbox-variant/include>
|
|
|
|
)
|
2020-02-06 01:21:02 +01:00
|
|
|
|
2020-03-02 16:21:52 +01:00
|
|
|
target_compile_options(lokimq PRIVATE -Wall -Wextra -Werror)
|
2020-03-05 19:52:28 +01:00
|
|
|
set_target_properties(lokimq PROPERTIES
|
|
|
|
CXX_STANDARD 14
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
2020-03-13 19:28:03 +01:00
|
|
|
CXX_EXTENSIONS OFF
|
2020-03-05 19:52:28 +01:00
|
|
|
POSITION_INDEPENDENT_CODE ON
|
|
|
|
)
|
2020-02-06 01:21:02 +01:00
|
|
|
|
2020-03-05 21:00:26 +01:00
|
|
|
if(NOT SODIUM_LIBRARIES)
|
|
|
|
pkg_search_module(SODIUM REQUIRED libsodium)
|
|
|
|
endif()
|
|
|
|
|
2020-03-14 19:17:48 +01:00
|
|
|
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.13)
|
|
|
|
# allow adding links to non-local targets (which is allowed even under old policy as long as the
|
|
|
|
# target is an interface, but under new cmake it spews out warnings).
|
|
|
|
cmake_policy(SET CMP0079 NEW)
|
|
|
|
endif()
|
2020-03-14 18:19:13 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-03-05 21:00:26 +01:00
|
|
|
# Really want to just use SODIUM_LINK_LIBRARIES here, but that isn't in older cmake:
|
2020-03-14 18:19:13 +01:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
link_dep_libs(lokimq PRIVATE ${SODIUM_LIBRARY_DIRS} ${SODIUM_LIBRARIES})
|
|
|
|
target_include_directories(lokimq PRIVATE ${SODIUM_INCLUDE_DIRS})
|
2020-03-05 21:00:26 +01:00
|
|
|
|
2020-03-14 20:06:58 +01:00
|
|
|
if(TARGET libzmq_vendor)
|
|
|
|
link_dep_libs(libzmq_vendor INTERFACE "${SODIUM_LIBRARY_DIRS}" ${SODIUM_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
|
2020-03-14 18:19:13 +01:00
|
|
|
target_link_libraries(lokimq PUBLIC cppzmq)
|
|
|
|
else()
|
|
|
|
link_dep_libs(lokimq PRIVATE "${SODIUM_STATIC_LIBRARY_DIRS}" ${SODIUM_STATIC_LIBRARIES})
|
|
|
|
target_include_directories(lokimq PRIVATE ${SODIUM_STATIC_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
if (libzmq_FOUND)
|
|
|
|
# cppzmq doesn't properly set up its libzmq target dependencies so do it here (this isn't the
|
|
|
|
# normal case: we only get here if someone pre-set libzmq_FOUND etc. *and* wants static libs)
|
|
|
|
link_dep_libs(cppzmq-static INTERFACE "${PC_LIBZMQ_STATIC_LIBRARY_DIRS}" ${PC_LIBZMQ_STATIC_LIBRARIES})
|
|
|
|
else()
|
|
|
|
# Otherwise we built a static vendored one, so make sure it links to the static libsodium
|
|
|
|
link_dep_libs(libzmq_vendor INTERFACE "${SODIUM_STATIC_LIBRARY_DIRS}" ${SODIUM_STATIC_LIBRARIES})
|
|
|
|
endif()
|
2020-03-12 21:55:34 +01:00
|
|
|
|
2020-03-14 18:19:13 +01:00
|
|
|
target_link_libraries(lokimq PUBLIC cppzmq-static)
|
|
|
|
endif()
|
2020-03-05 21:00:26 +01:00
|
|
|
|
2020-03-01 19:28:50 +01:00
|
|
|
add_library(lokimq::lokimq ALIAS lokimq)
|
2020-03-02 16:21:52 +01:00
|
|
|
|
|
|
|
export(
|
|
|
|
TARGETS lokimq
|
|
|
|
NAMESPACE lokimq::
|
|
|
|
FILE lokimqTargets.cmake
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
TARGETS lokimq
|
|
|
|
EXPORT lokimqConfig
|
2020-03-13 19:29:59 +01:00
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2020-03-02 16:21:52 +01:00
|
|
|
)
|
2020-03-01 19:28:50 +01:00
|
|
|
|
2020-03-13 19:29:30 +01:00
|
|
|
install(
|
|
|
|
FILES lokimq/auth.h
|
|
|
|
lokimq/batch.h
|
|
|
|
lokimq/bt_serialize.h
|
|
|
|
lokimq/connections.h
|
|
|
|
lokimq/hex.h
|
|
|
|
lokimq/lokimq.h
|
|
|
|
lokimq/message.h
|
|
|
|
lokimq/string_view.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/lokimq/version.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lokimq
|
|
|
|
)
|
2020-03-13 22:53:55 +01:00
|
|
|
option(LOKIMQ_INSTALL_MAPBOX_VARIANT "Install mapbox-variant headers with lokimq/ headers" ON)
|
|
|
|
if(LOKIMQ_INSTALL_MAPBOX_VARIANT)
|
|
|
|
install(
|
|
|
|
FILES mapbox-variant/include/mapbox/variant.hpp
|
|
|
|
mapbox-variant/include/mapbox/variant_cast.hpp
|
|
|
|
mapbox-variant/include/mapbox/variant_io.hpp
|
|
|
|
mapbox-variant/include/mapbox/variant_visitor.hpp
|
|
|
|
mapbox-variant/include/mapbox/recursive_wrapper.hpp
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lokimq/mapbox
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(LOKIMQ_INSTALL_CPPZMQ "Install cppzmq header with lokimq/ headers" ON)
|
|
|
|
if(LOKIMQ_INSTALL_CPPZMQ)
|
|
|
|
install(
|
|
|
|
FILES cppzmq/zmq.hpp
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lokimq
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-03-13 19:29:30 +01:00
|
|
|
|
2020-03-13 19:31:43 +01:00
|
|
|
install(
|
|
|
|
FILES ${CMAKE_CURRENT_BINARY_DIR}/liblokimq.pc
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
|
|
|
)
|
|
|
|
|
2020-03-01 19:28:50 +01:00
|
|
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|
|
|
set(lokimq_IS_TOPLEVEL_PROJECT TRUE)
|
|
|
|
else()
|
|
|
|
set(lokimq_IS_TOPLEVEL_PROJECT FALSE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(LOKIMQ_BUILD_TESTS "Building and perform lokimq tests" ${lokimq_IS_TOPLEVEL_PROJECT})
|
|
|
|
if(LOKIMQ_BUILD_TESTS)
|
2020-02-06 23:10:26 +01:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
|
|
|
|