Newer
Older
uindra
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# - Try to find ZeroMQ
#
# Usage:
#
# find_package(ZeroMQ [version] [REQUIRED|QUIET])
#
# Any (optional) [version] given to find_package() will be tested
#
# Once done this will define
#
# ZeroMQ_FOUND - System has ZeroMQ
# ZeroMQ_VERSION - ZeroMQ version
#
# and the IMPORTED target libzmq will be defined, with the required
# INTERFACE definitions to find zmq_compat.h etc. etc.
#
# target_link_libraries(MyTarget [PRIVATE|PUBLIC|INTERFACE] libzmq)
#
# should be sufficient to compile and link any code using the ZeroMQ C++ bindings.
#
# 'zmq_compat.h'
#
# We provide this utility header in order to handle deprecation warnings when using
# newer versions of ZeroMQ. It defines the following symbols:
#
#~~~{.cpp}
#define ZMQ_SETSOCKOPT_DEPRECATED
#define ZMQ_USE_SEND_FLAGS
#define ZMQ_USE_RECV_WITH_REFERENCE
#~~~
#
# The target libzmq contains the necessary include_directory path.
# The file will be automatically installed in CMAKE_INSTALL_PKGINCDIR (if defined), or in
# CMAKE_INSTALL_INCLUDEDIR
#
# NOTES:
#
# - By default the usual system directories are searched before all others
#
# - Any installation path in CMAKE_PREFIX_PATH will take precedence over system directories
#
# - Or you can set either of the following with the installation path :
#
# ZeroMQ_DIR
# ZeroMQ_ROOT
#
# CMake minimum version 3.12 required to use ZeroMQ_ROOT in find_path/library
cmake_minimum_required(VERSION 3.12)
if(NOT ZeroMQ_FOUND)
if(ZeroMQ_DIR)
find_path (ZeroMQ_INCLUDE_DIR
NAMES zmq.hpp
PATHS ${ZeroMQ_DIR}/include
NO_DEFAULT_PATH
)
find_library (ZeroMQ_LIBRARY
NAMES zmq
PATHS ${ZeroMQ_DIR}/lib ${ZeroMQ_DIR}/lib64
NO_DEFAULT_PATH
)
else(ZeroMQ_DIR)
find_path (ZeroMQ_INCLUDE_DIR
NAMES zmq.hpp
)
find_library (ZeroMQ_LIBRARY
NAMES zmq
)
endif(ZeroMQ_DIR)
if((NOT ZeroMQ_INCLUDE_DIR) OR (NOT ZeroMQ_LIBRARY))
## load in pkg-config support
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
## use pkg-config to get hints for 0mq locations
pkg_check_modules(PC_ZeroMQ QUIET libzmq)
## use the hint from above to find where 'zmq.hpp' is located
find_path(ZeroMQ_INCLUDE_DIR
NAMES zmq.hpp
PATHS ${PC_ZeroMQ_INCLUDE_DIRS}
)
## use the hint from above to find the location of libzmq
find_library(ZeroMQ_LIBRARY
NAMES zmq
PATHS ${PC_ZeroMQ_LIBRARY_DIRS}
)
endif(PkgConfig_FOUND)
endif((NOT ZeroMQ_INCLUDE_DIR) OR (NOT ZeroMQ_LIBRARY))
if(ZeroMQ_INCLUDE_DIR AND ZeroMQ_LIBRARY)
# get libzmq version from zmq.h header file
file(READ "${ZeroMQ_INCLUDE_DIR}/zmq.h" _ZMQ_H_CONTENTS)
string(REGEX REPLACE ".*#define ZMQ_VERSION_MAJOR ([0-9]+).*" "\\1" DETECTED_ZMQ_VERSION_MAJOR "${_ZMQ_H_CONTENTS}")
string(REGEX REPLACE ".*#define ZMQ_VERSION_MINOR ([0-9]+).*" "\\1" DETECTED_ZMQ_VERSION_MINOR "${_ZMQ_H_CONTENTS}")
string(REGEX REPLACE ".*#define ZMQ_VERSION_PATCH ([0-9]+).*" "\\1" DETECTED_ZMQ_VERSION_PATCH "${_ZMQ_H_CONTENTS}")
set(ZeroMQ_VERSION "${DETECTED_ZMQ_VERSION_MAJOR}.${DETECTED_ZMQ_VERSION_MINOR}.${DETECTED_ZMQ_VERSION_PATCH}")
endif(ZeroMQ_INCLUDE_DIR AND ZeroMQ_LIBRARY)
include ( FindPackageHandleStandardArgs )
# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args (ZeroMQ
VERSION_VAR ZeroMQ_VERSION
REQUIRED_VARS ZeroMQ_LIBRARY ZeroMQ_INCLUDE_DIR
)
if(NOT TARGET libzmq)
# Create IMPORTED targets with all correct attributes
add_library(libzmq SHARED IMPORTED)
set_property(TARGET libzmq APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
get_filename_component(ZeroMQ_LIB_SO ${ZeroMQ_LIBRARY} NAME)
set_target_properties(libzmq PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ZeroMQ_INCLUDE_DIR}"
INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
IMPORTED_LOCATION_NOCONFIG "${ZeroMQ_LIBRARY}"
IMPORTED_SONAME_NOCONFIG "${ZeroMQ_LIB_SO}"
)
endif()
# Install zmq_compat.h if it exists
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/zmq_compat.h)
if(CMAKE_INSTALL_PKGINCDIR)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/zmq_compat.h DESTINATION ${CMAKE_INSTALL_PKGINCDIR})
elseif(CMAKE_INSTALL_INCLUDEDIR)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/zmq_compat.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
endif()
endif(NOT ZeroMQ_FOUND)