Showing
1 changed file
with
107 additions
and
0 deletions
etc_files/CMakeLists.txt
0 → 100644
1 | +cmake_minimum_required(VERSION 3.11) | ||
2 | + | ||
3 | +list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
4 | + | ||
5 | +include (DetectCPPZMQVersion) | ||
6 | + | ||
7 | +project(cppzmq VERSION ${DETECTED_CPPZMQ_VERSION}) | ||
8 | + | ||
9 | +if (NOT TARGET libzmq AND NOT TARGET libzmq-static) | ||
10 | + find_package(ZeroMQ QUIET) | ||
11 | + | ||
12 | + # libzmq autotools install: fallback to pkg-config | ||
13 | + if(NOT ZeroMQ_FOUND) | ||
14 | + message(STATUS "CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)") | ||
15 | + list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) | ||
16 | + find_package(ZeroMQ REQUIRED) | ||
17 | + endif() | ||
18 | + | ||
19 | + # TODO "REQUIRED" above should already cause a fatal failure if not found, but this doesn't seem to work | ||
20 | + if(NOT ZeroMQ_FOUND) | ||
21 | + message(FATAL_ERROR "ZeroMQ was not found, neither as a CMake package nor via pkg-config") | ||
22 | + endif() | ||
23 | + | ||
24 | + if (ZeroMQ_FOUND AND NOT (TARGET libzmq OR TARGET libzmq-static)) | ||
25 | + message(FATAL_ERROR "ZeroMQ version not supported!") | ||
26 | + endif() | ||
27 | +endif() | ||
28 | + | ||
29 | +if (EXISTS "${CMAKE_SOURCE_DIR}/.git") | ||
30 | + OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON) | ||
31 | +else () | ||
32 | + OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF) | ||
33 | +endif () | ||
34 | +if (ENABLE_DRAFTS) | ||
35 | + ADD_DEFINITIONS (-DZMQ_BUILD_DRAFT_API) | ||
36 | + set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1") | ||
37 | +else (ENABLE_DRAFTS) | ||
38 | + set (pkg_config_defines "") | ||
39 | +endif (ENABLE_DRAFTS) | ||
40 | + | ||
41 | +message(STATUS "cppzmq v${cppzmq_VERSION}") | ||
42 | + | ||
43 | +set(CPPZMQ_HEADERS | ||
44 | + zmq.hpp | ||
45 | + zmq_addon.hpp | ||
46 | +) | ||
47 | + | ||
48 | +foreach (target cppzmq cppzmq-static) | ||
49 | + add_library(${target} INTERFACE) | ||
50 | + target_include_directories(${target} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
51 | + $<INSTALL_INTERFACE:include>) | ||
52 | +endforeach() | ||
53 | + | ||
54 | +target_link_libraries(cppzmq INTERFACE libzmq) | ||
55 | +target_link_libraries(cppzmq-static INTERFACE libzmq-static) | ||
56 | + | ||
57 | +include(GNUInstallDirs) | ||
58 | +include(CMakePackageConfigHelpers) | ||
59 | + | ||
60 | +install(TARGETS cppzmq cppzmq-static | ||
61 | + EXPORT ${PROJECT_NAME}-targets) | ||
62 | + | ||
63 | +install(FILES ${CPPZMQ_HEADERS} | ||
64 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
65 | + | ||
66 | +# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share". | ||
67 | +set(CPPZMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for cppzmqConfig.cmake") | ||
68 | + | ||
69 | +configure_file(libzmq-pkg-config/FindZeroMQ.cmake | ||
70 | + libzmq-pkg-config/FindZeroMQ.cmake | ||
71 | + COPYONLY) | ||
72 | + | ||
73 | +export(EXPORT ${PROJECT_NAME}-targets | ||
74 | + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") | ||
75 | +configure_package_config_file(${PROJECT_NAME}Config.cmake.in | ||
76 | + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
77 | + INSTALL_DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}) | ||
78 | +# Workaround until ARCH_INDEPENDENT flag can be used with cmake 3.14. | ||
79 | +# The ConigVersion.cmake file contains checks for the architecture is was | ||
80 | +# generated on, which can cause problems for header only libraries | ||
81 | +# used with e.g. the Conan package manager. Since it is header only we | ||
82 | +# can/should omit those checks. | ||
83 | +set(CPPZMQ_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) | ||
84 | +set(CMAKE_SIZEOF_VOID_P "") # a simple unset is not sufficient | ||
85 | +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake | ||
86 | + VERSION ${CPPZMQ_VERSION} | ||
87 | + COMPATIBILITY AnyNewerVersion) | ||
88 | +set(CMAKE_SIZEOF_VOID_P ${CPPZMQ_SIZEOF_VOID_P}) | ||
89 | + | ||
90 | +install(EXPORT ${PROJECT_NAME}-targets | ||
91 | + FILE ${PROJECT_NAME}Targets.cmake | ||
92 | + DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}) | ||
93 | +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake | ||
94 | + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake | ||
95 | + DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}) | ||
96 | +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake | ||
97 | + DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config) | ||
98 | + | ||
99 | +option(CPPZMQ_BUILD_TESTS "Whether or not to build the tests" ON) | ||
100 | + | ||
101 | +if (CPPZMQ_BUILD_TESTS) | ||
102 | + enable_testing() | ||
103 | + add_subdirectory(tests) | ||
104 | + if (CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD EQUAL 98 AND CMAKE_CXX_STANDARD GREATER_EQUAL 11) | ||
105 | + add_subdirectory(examples) | ||
106 | + endif() | ||
107 | +endif() |
-
Please register or login to post a comment