mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-12 10:33:52 +01:00
7d8e3ab473
When libzmq is installed via a package manager, it causes a CMake warning when building cppzmq, which can be safely ignored.
85 lines
3.0 KiB
CMake
85 lines
3.0 KiB
CMake
cmake_minimum_required(VERSION 3.0.0)
|
|
|
|
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
include (DetectCPPZMQVersion)
|
|
|
|
project(cppzmq VERSION ${DETECTED_CPPZMQ_VERSION})
|
|
|
|
find_package(ZeroMQ QUIET)
|
|
|
|
# libzmq autotools install: fallback to pkg-config
|
|
if(NOT ZeroMQ_FOUND)
|
|
# try again with pkg-config (normal install of zeromq)
|
|
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config)
|
|
find_package(ZeroMQ REQUIRED)
|
|
endif()
|
|
|
|
if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
|
|
message(FATAL_ERROR "ZeroMQ version not supported!")
|
|
endif()
|
|
|
|
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
|
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
|
|
else ()
|
|
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
|
|
endif ()
|
|
if (ENABLE_DRAFTS)
|
|
ADD_DEFINITIONS (-DZMQ_BUILD_DRAFT_API)
|
|
set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
|
|
else (ENABLE_DRAFTS)
|
|
set (pkg_config_defines "")
|
|
endif (ENABLE_DRAFTS)
|
|
|
|
message(STATUS "cppzmq v${CPPZMQ_VERSION}")
|
|
|
|
set(CPPZMQ_HEADERS
|
|
zmq.hpp
|
|
zmq_addon.hpp
|
|
)
|
|
|
|
foreach (target cppzmq cppzmq-static)
|
|
add_library(${target} INTERFACE)
|
|
target_include_directories(${target} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
$<INSTALL_INTERFACE:include>)
|
|
endforeach()
|
|
|
|
target_link_libraries(cppzmq INTERFACE libzmq)
|
|
target_link_libraries(cppzmq-static INTERFACE libzmq-static)
|
|
|
|
include(GNUInstallDirs)
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
install(TARGETS cppzmq cppzmq-static
|
|
EXPORT ${PROJECT_NAME}-targets)
|
|
|
|
install(FILES ${CPPZMQ_HEADERS}
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
|
|
set(CPPZMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for cppzmqConfig.cmake")
|
|
|
|
export(EXPORT ${PROJECT_NAME}-targets
|
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
|
|
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
INSTALL_DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
|
|
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
|
VERSION ${CPPZMQ_VERSION}
|
|
COMPATIBILITY AnyNewerVersion)
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
FILE ${PROJECT_NAME}Targets.cmake
|
|
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
|
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
|
|
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config)
|
|
|
|
option(CPPZMQ_BUILD_TESTS "Whether or not to build the tests" ON)
|
|
|
|
if (CPPZMQ_BUILD_TESTS)
|
|
enable_testing()
|
|
add_subdirectory(tests)
|
|
endif()
|