-
Notifications
You must be signed in to change notification settings - Fork 51
/
CMakeLists.txt
178 lines (166 loc) · 5.29 KB
/
CMakeLists.txt
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
cmake_minimum_required(VERSION 3.4)
project(QtZeroConf VERSION 0.1.0)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(PUBLIC_HEADERS
qzeroconfservice.h
qzeroconfglobal.h
qzeroconf.h
)
add_library(QtZeroConf
${PUBLIC_HEADERS}
qzeroconfservice.cpp
)
include(GNUInstallDirs)
if(BUILD_SHARED_LIBS)
target_compile_definitions(QtZeroConf PRIVATE QT_BUILD_ZEROCONF_LIB)
set_target_properties(QtZeroConf PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 0)
else()
target_compile_definitions(QtZeroConf PUBLIC QZEROCONF_STATIC)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
find_library(avahi-client-lib avahi-client REQUIRED)
find_library(avahi-common-lib avahi-common REQUIRED)
find_path(avahi-client-includes avahi-client/client.h REQUIRED)
find_path(avahi-common-includes avahi-common/defs.h REQUIRED)
target_sources(QtZeroConf PRIVATE
avahi-qt/qt-watch_p.h
avahi-qt/qt-watch.cpp
avahiclient.cpp
)
target_include_directories(QtZeroConf PRIVATE ${avahi-client-includes} ${avahi-common-includes})
list(APPEND ${PUBLIC_HEADERS}
avahi-qt/qt-watch.h
)
target_link_libraries(QtZeroConf PRIVATE ${avahi-client-lib} ${avahi-common-lib})
endif()
if(APPLE)
target_sources(QtZeroConf PRIVATE
bonjour_p.h
bonjour.cpp
)
find_library(CoreServices CoreServices)
target_link_libraries(QtZeroConf PUBLIC ${CoreServices})
endif()
target_include_directories(QtZeroConf PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/QtZeroConf>
)
target_link_libraries(QtZeroConf PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)
if(WIN32)
target_sources(QtZeroConf PRIVATE
bonjour_p.h
bonjour.cpp
bonjour-sdk/dnssd_clientlib.c
bonjour-sdk/dnssd_clientstub.c
bonjour-sdk/dnssd_ipc.c
)
target_link_libraries(QtZeroConf PUBLIC ws2_32)
if(MSVC)
target_link_libraries(QtZeroConf PUBLIC "legacy_stdio_definitions.lib")
endif()
target_compile_definitions(QtZeroConf PRIVATE
-DWIN32
-D_USRDLL
-DMDNS_DEBUGMSGS=0
-DWIN32_LEAN_AND_MEAN
-DUSE_TCP_LOOPBACK
-D_NO_CRT_STDIO_INLINE
-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1
-DNOT_HAVE_SA_LEN)
target_include_directories(QtZeroConf PRIVATE "${CMAKE_CURRENT_LIST_DIR}/bonjour-sdk")
endif()
if(ANDROID_AVAHI)
set(ACM "${CMAKE_CURRENT_LIST_DIR}/avahi-common")
set(ACR "${CMAKE_CURRENT_LIST_DIR}/avahi-core")
target_sources(QtZeroConf PRIVATE
qzeroconf.h
avahi-qt/qt-watch.h
avahi-qt/qt-watch_p.h
avahicore.cpp
avahi-qt/qt-watch.cpp
${ACM}/address.c
${ACM}/alternative.c
${ACM}/domain.c
${ACM}/error.c
${ACM}/i18n.c
${ACM}/malloc.c
${ACM}/rlist.c
${ACM}/simple-watch.c
${ACM}/strlst.c
${ACM}/thread-watch.c
${ACM}/timeval.c
${ACM}/utf8.c
${ACR}/addr-util.c
${ACR}/announce.c
${ACR}/browse.c
${ACR}/browse-dns-server.c
${ACR}/browse-domain.c
${ACR}/browse-service.c
${ACR}/browse-service-type.c
${ACR}/cache.c
${ACR}/dns.c
${ACR}/domain-util.c
${ACR}/entry.c
${ACR}/fdutil.c
${ACR}/hashmap.c
${ACR}/iface.c
${ACR}/iface-linux.c
${ACR}/log.c
${ACR}/multicast-lookup.c
${ACR}/netlink.c
${ACR}/prioq.c
${ACR}/probe-sched.c
${ACR}/querier.c
${ACR}/query-sched.c
${ACR}/resolve-address.c
${ACR}/resolve-host-name.c
${ACR}/resolve-service.c
${ACR}/response-sched.c
${ACR}/rr.c
${ACR}/rrlist.c
${ACR}/server.c
${ACR}/socket.c
${ACR}/timeeventq.c
${ACR}/util.c
${ACR}/wide-area.c
)
list(APPEND ${PUBLIC_HEADERS}
avahi-qt/qt-watch.h
)
target_compile_definitions(QtZeroConf PRIVATE HAVE_STRLCPY GETTEXT_PACKAGE HAVE_NETLINK)
elseif(ANDROID)
target_sources(QtZeroConf PRIVATE
qzeroconf.h
androidnsd_p.h
androidnsd.cpp
)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)
target_link_libraries(QtZeroConf PUBLIC Qt${QT_VERSION_MAJOR}::Gui)
if (QT_VERSION_MAJOR EQUAL 5)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS AndroidExtras)
target_link_libraries(QtZeroConf PUBLIC Qt${QT_VERSION_MAJOR}::AndroidExtras)
endif ()
endif()
# install
set(INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "Installation directory for cmake config files")
set_target_properties(QtZeroConf PROPERTIES PUBLIC_HEADER
"${PUBLIC_HEADERS}"
)
install(TARGETS QtZeroConf
EXPORT QtZeroConfConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
export(TARGETS QtZeroConf
FILE ${CMAKE_CURRENT_BINARY_DIR}/QtZeroConfConfig.cmake
)
install(EXPORT QtZeroConfConfig
DESTINATION ${INSTALL_CMAKEDIR}
)
if(BUILD_EXAMPLE)
add_subdirectory(example)
endif()