aboutsummaryrefslogtreecommitdiffstats
path: root/extcap/CMakeLists.txt
blob: 398d712efec04aab7507aa54d3e1b41e71100939 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# CMakeLists.txt
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# SPDX-License-Identifier: GPL-2.0-or-later
#

if(EXTCAP_ANDROIDDUMP_LIBPCAP)
	set(ANDROIDDUMP_USE_LIBPCAP 1)
endif()

if(LIBSSH_FOUND)
	include(CMakePushCheckState)
	cmake_push_check_state()
	set(CMAKE_REQUIRED_INCLUDES ${LIBSSH_INCLUDE_DIRS})
	set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LIBRARIES})
	check_function_exists(ssh_userauth_agent LIBSSH_USERAUTH_AGENT_FOUND)
	cmake_pop_check_state()
	if(LIBSSH_USERAUTH_AGENT_FOUND)
		set(HAVE_SSH_USERAUTH_AGENT 1)
	endif()
endif()

# Ensure "run/extcap" exists
# add_custom_command(OUTPUT "${DATAFILE_DIR}/extcap"
# 	COMMAND ${CMAKE_COMMAND} -E make_directory
# 		"${DATAFILE_DIR}/extcap"
# )
# list(APPEND copy_data_files_depends "${DATAFILE_DIR}/extcap")


macro(set_extcap_executable_properties _executable)
	set_target_properties(${_executable} PROPERTIES
		LINK_FLAGS "${WS_LINK_FLAGS}"
		FOLDER "Executables/Extcaps"
		INSTALL_RPATH "${EXTCAP_INSTALL_RPATH}"
	)

	set(PROGLIST ${PROGLIST} ${_executable})

	if(WIN32)
		set_target_properties(${_executable} PROPERTIES
			RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
			RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/run/Debug/extcap
			RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/run/Release/extcap
			RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/run/MinSizeRel/extcap
			RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/run/RelWithDebInfo/extcap
		)
	else()
		set_target_properties(${_executable} PROPERTIES
			RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
		)
		if(ENABLE_APPLICATION_BUNDLE)
			if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
				# Xcode
				set_target_properties(${_executable} PROPERTIES
					RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/MacOS/extcap
				)
			else()
				set_target_properties(${_executable} PROPERTIES
					RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap
				)
				# Add a wrapper script which runs each executable from the
				# correct location. This adds convenience but makes debugging
				# more difficult.
				file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
				file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
				file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap/${_executable} \"\$\@\"\n")
				execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
			endif()
		endif()
	endif()
endmacro()

add_custom_target(extcaps)

add_library(extcap-base OBJECT extcap-base.c)
if(LIBSSH_FOUND)
	add_library(ssh-base OBJECT ssh-base.c)
	target_include_directories(ssh-base SYSTEM
		PRIVATE
			${LIBSSH_INCLUDE_DIRS}
	)
endif()

if(BUILD_androiddump)
	if(EXTCAP_ANDROIDDUMP_LIBPCAP)
		if(HAVE_LIBPCAP)
			set(androiddump_LIBS
				ui
				${GLIB2_LIBRARIES}
				${PCAP_LIBRARIES}
				${WIN_WS2_32_LIBRARY}
			)
		else()
			message(FATAL_ERROR "You are trying to build androiddump with libpcap but do not have it")
		endif()
	else()
		set(androiddump_LIBS
			ui
			wiretap
			${GLIB2_LIBRARIES}
			${ZLIB_LIBRARIES}
			${CMAKE_DL_LIBS}
			${WIN_WS2_32_LIBRARY}
		)
	endif()
	set(androiddump_FILES
		$<TARGET_OBJECTS:cli_main>
		$<TARGET_OBJECTS:extcap-base>
		androiddump.c
	)

	set_executable_resources(androiddump "Androiddump")
	add_executable(androiddump ${androiddump_FILES})
	set_extcap_executable_properties(androiddump)
	target_link_libraries(androiddump ${androiddump_LIBS})
	install(TARGETS androiddump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps androiddump)
endif()

if(BUILD_sshdump AND LIBSSH_FOUND)
	set(sshdump_LIBS
		wsutil
		${GLIB2_LIBRARIES}
		${CMAKE_DL_LIBS}
		${WIN_WS2_32_LIBRARY}
		${LIBSSH_LIBRARIES}
	)
	set(sshdump_FILES
		$<TARGET_OBJECTS:cli_main>
		$<TARGET_OBJECTS:extcap-base>
		$<TARGET_OBJECTS:ssh-base>
		sshdump.c
	)

	set_executable_resources(sshdump "Sshdump")
	add_executable(sshdump ${sshdump_FILES})
	set_extcap_executable_properties(sshdump)
	target_link_libraries(sshdump ${sshdump_LIBS})
	target_include_directories(sshdump SYSTEM PRIVATE ${LIBSSH_INCLUDE_DIRS})
	install(TARGETS sshdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps sshdump)
elseif (BUILD_sshdump)
	#message( WARNING "Cannot find libssh, cannot build sshdump" )
endif()

if(BUILD_ciscodump AND LIBSSH_FOUND)
	set(ciscodump_LIBS
		writecap
		wsutil
		${GLIB2_LIBRARIES}
		${CMAKE_DL_LIBS}
		${WIN_WS2_32_LIBRARY}
		${LIBSSH_LIBRARIES}
	)
	set(ciscodump_FILES
		$<TARGET_OBJECTS:cli_main>
		$<TARGET_OBJECTS:extcap-base>
		$<TARGET_OBJECTS:ssh-base>
		ciscodump.c
	)

	set_executable_resources(ciscodump "Ciscodump")
	add_executable(ciscodump ${ciscodump_FILES})
	set_extcap_executable_properties(ciscodump)
	target_link_libraries(ciscodump ${ciscodump_LIBS})
	target_include_directories(ciscodump SYSTEM PRIVATE ${LIBSSH_INCLUDE_DIRS})
	install(TARGETS ciscodump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps ciscodump)
elseif (BUILD_ciscodump)
	#message( WARNING "Cannot find libssh, cannot build ciscodump" )
endif()

if(BUILD_dpauxmon AND HAVE_LIBNL3)
	set(dpauxmon_LIBS
		${GLIB2_LIBRARIES}
		${CMAKE_DL_LIBS}
		wsutil
		writecap
		${NL_LIBRARIES}
	)
	set(dpauxmon_FILES
		$<TARGET_OBJECTS:extcap-base>
		dpauxmon.c
	)

	set_executable_resources(dpauxmon "dpauxmon")
	add_executable(dpauxmon ${dpauxmon_FILES})
	set_extcap_executable_properties(dpauxmon)
	target_link_libraries(dpauxmon ${dpauxmon_LIBS})
	target_include_directories(dpauxmon SYSTEM PRIVATE ${NL_INCLUDE_DIRS})
	install(TARGETS dpauxmon RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps dpauxmon)
elseif (BUILD_dpauxmon)
	#message( WARNING "Cannot find libnl3, cannot build dpauxmon" )
endif()

if(BUILD_udpdump)
	set(udpdump_LIBS
		wsutil
		${GLIB2_LIBRARIES}
		${CMAKE_DL_LIBS}
		${WIN_WS2_32_LIBRARY}
		wsutil
		writecap
	)
	set(udpdump_FILES
		$<TARGET_OBJECTS:cli_main>
		$<TARGET_OBJECTS:extcap-base>
		udpdump.c
	)

	set_executable_resources(udpdump "udpdump")
	add_executable(udpdump ${udpdump_FILES})
	set_extcap_executable_properties(udpdump)
	target_link_libraries(udpdump ${udpdump_LIBS})
	install(TARGETS udpdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps udpdump)
endif()

if(BUILD_randpktdump)
	set(randpktdump_LIBS
		randpkt_core
		wiretap
		wsutil
		${GLIB2_LIBRARIES}
		${ZLIB_LIBRARIES}
		${CMAKE_DL_LIBS}
		${WIN_WS2_32_LIBRARY}
	)
	set(randpktdump_FILES
		$<TARGET_OBJECTS:cli_main>
		$<TARGET_OBJECTS:extcap-base>
		randpktdump.c
	)

	set_executable_resources(randpktdump "randpktdump")
	add_executable(randpktdump ${randpktdump_FILES})
	set_extcap_executable_properties(randpktdump)
	target_link_libraries(randpktdump ${randpktdump_LIBS})
	install(TARGETS randpktdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps randpktdump)
endif()

if(BUILD_sdjournal AND SYSTEMD_FOUND)
	set(sdjournal_LIBS
		wiretap
		writecap
		wsutil
		${GLIB2_LIBRARIES}
		${ZLIB_LIBRARIES}
		${CMAKE_DL_LIBS}
		${SYSTEMD_LIBRARIES}
	)
	set(sdjournal_FILES
		$<TARGET_OBJECTS:extcap-base>
		sdjournal.c
	)

	set_executable_resources(sdjournal "sdjournal")
	add_executable(sdjournal ${sdjournal_FILES})
	set_extcap_executable_properties(sdjournal)
	target_link_libraries(sdjournal ${sdjournal_LIBS})
	target_include_directories(sdjournal SYSTEM PRIVATE ${SYSTEMD_INCLUDE_DIRS})
	install(TARGETS sdjournal RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
	add_dependencies(extcaps sdjournal)
endif()

#
# Editor modelines  -  https://www.wireshark.org/tools/modelines.html
#
# Local variables:
# c-basic-offset: 8
# tab-width: 8
# indent-tabs-mode: t
# End:
#
# vi: set shiftwidth=8 tabstop=8 noexpandtab:
# :indentSize=8:tabSize=8:noTabs=false:
#