8475a39598439b40ff2476504ae928167fd2b483
[metze/wireshark/wip.git] / extcap / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
6 #
7 # SPDX-License-Identifier: GPL-2.0-or-later
8 #
9
10 if(EXTCAP_ANDROIDDUMP_LIBPCAP)
11         set(ANDROIDDUMP_USE_LIBPCAP 1)
12 endif()
13
14 if(LIBSSH_FOUND)
15         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBSSH_LIBRARIES})
16         CHECK_FUNCTION_EXISTS(ssh_userauth_agent LIBSSH_USERAUTH_AGENT_FOUND)
17         if(LIBSSH_USERAUTH_AGENT_FOUND)
18                 set(HAVE_SSH_USERAUTH_AGENT 1)
19         endif()
20 endif()
21
22 # Ensure "run/extcap" exists
23 # add_custom_command(OUTPUT "${DATAFILE_DIR}/extcap"
24 #       COMMAND ${CMAKE_COMMAND} -E make_directory
25 #               "${DATAFILE_DIR}/extcap"
26 # )
27 # list(APPEND copy_data_files_depends "${DATAFILE_DIR}/extcap")
28
29
30 macro(set_extcap_executable_properties _executable)
31         set_target_properties(${_executable} PROPERTIES FOLDER "Executables/Extcaps")
32
33         set(PROGLIST ${PROGLIST} ${_executable})
34
35         if(WIN32)
36                 set_target_properties(${_executable} PROPERTIES
37                         LINK_FLAGS "${WS_LINK_FLAGS}"
38                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
39                         RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/run/Debug/extcap
40                         RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/run/Release/extcap
41                         RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/run/MinSizeRel/extcap
42                         RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/run/RelWithDebInfo/extcap
43                 )
44         else()
45                 set_target_properties(${_executable} PROPERTIES
46                         LINK_FLAGS "${WS_LINK_FLAGS}"
47                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
48                 )
49                 if(ENABLE_RPATH_ORIGIN)
50                         set_target_properties(${_executable} PROPERTIES
51                                 INSTALL_RPATH "\$ORIGIN/../.."
52                         )
53                 endif()
54                 if(ENABLE_APPLICATION_BUNDLE)
55                         if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
56                                 # Xcode
57                                 set_target_properties(${_executable} PROPERTIES
58                                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/MacOS/extcap
59                                 )
60                         else()
61                                 set_target_properties(${_executable} PROPERTIES
62                                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap
63                                 )
64                                 # Add a wrapper script which runs each executable from the
65                                 # correct location. This adds convenience but makes debugging
66                                 # more difficult.
67                                 file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
68                                 file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
69                                 file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap/${_executable} \"\$\@\"\n")
70                                 execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
71                         endif()
72                 endif()
73         endif()
74 endmacro()
75
76 add_custom_target(extcaps)
77
78 if(BUILD_androiddump)
79         if(EXTCAP_ANDROIDDUMP_LIBPCAP)
80                 if(HAVE_LIBPCAP)
81                         set(androiddump_LIBS
82                                 ui
83                                 ${GLIB2_LIBRARIES}
84                                 ${PCAP_LIBRARIES}
85                         )
86                 else()
87                         message(FATAL_ERROR "You are trying to build androiddump with libpcap but do not have it")
88                 endif()
89         else()
90                 set(androiddump_LIBS
91                         ui
92                         wiretap
93                         ${GLIB2_LIBRARIES}
94                         ${ZLIB_LIBRARIES}
95                         ${CMAKE_DL_LIBS}
96                 )
97         endif()
98         set(androiddump_FILES
99                 androiddump.c
100                 extcap-base.c
101         )
102
103         set_executable_resources(androiddump "Androiddump")
104         add_executable(androiddump ${androiddump_FILES})
105         # XXX Shouldn't we add wsutil to androiddump_LIBS instead?
106         set_extcap_executable_properties(androiddump)
107         target_link_libraries(androiddump ${androiddump_LIBS})
108         install(TARGETS androiddump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
109         add_dependencies(extcaps androiddump)
110 endif()
111
112 if(BUILD_sshdump AND LIBSSH_FOUND)
113         set(sshdump_LIBS
114                 wsutil
115                 ${GLIB2_LIBRARIES}
116                 ${CMAKE_DL_LIBS}
117                 ${LIBSSH_LIBRARIES}
118         )
119         set(sshdump_FILES
120                 sshdump.c
121                 extcap-base.c
122                 ssh-base.c
123         )
124
125         set_executable_resources(sshdump "Sshdump")
126         add_executable(sshdump ${sshdump_FILES})
127         set_extcap_executable_properties(sshdump)
128         target_link_libraries(sshdump ${sshdump_LIBS})
129         target_include_directories(sshdump PUBLIC ${LIBSSH_INCLUDE_DIR})
130         install(TARGETS sshdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
131         add_dependencies(extcaps sshdump)
132 elseif (BUILD_sshdump)
133         #message( WARNING "Cannot find libssh, cannot build sshdump" )
134 endif()
135
136 if(BUILD_ciscodump AND LIBSSH_FOUND)
137         set(ciscodump_LIBS
138                 writecap
139                 wsutil
140                 ${GLIB2_LIBRARIES}
141                 ${CMAKE_DL_LIBS}
142                 ${LIBSSH_LIBRARIES}
143         )
144         set(ciscodump_FILES
145                 ciscodump.c
146                 extcap-base.c
147                 ssh-base.c
148         )
149
150         set_executable_resources(ciscodump "Ciscodump")
151         add_executable(ciscodump ${ciscodump_FILES})
152         set_extcap_executable_properties(ciscodump)
153         target_link_libraries(ciscodump ${ciscodump_LIBS})
154         target_include_directories(ciscodump PUBLIC ${LIBSSH_INCLUDE_DIR})
155         install(TARGETS ciscodump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
156         add_dependencies(extcaps ciscodump)
157 elseif (BUILD_ciscodump)
158         #message( WARNING "Cannot find libssh, cannot build ciscodump" )
159 endif()
160
161 if(BUILD_dpauxmon AND HAVE_LIBNL3)
162         set(dpauxmon_LIBS
163                 ${GLIB2_LIBRARIES}
164                 ${CMAKE_DL_LIBS}
165                 wsutil
166                 writecap
167                 ${NL_LIBRARIES}
168         )
169         set(dpauxmon_FILES
170                 dpauxmon.c
171                 extcap-base.c
172         )
173
174         set_executable_resources(dpauxmon "dpauxmon")
175         add_executable(dpauxmon ${dpauxmon_FILES})
176         set_extcap_executable_properties(dpauxmon)
177         target_link_libraries(dpauxmon ${dpauxmon_LIBS})
178         target_include_directories(dpauxmon PUBLIC ${NL_INCLUDE_DIR})
179         install(TARGETS dpauxmon RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
180         add_dependencies(extcaps dpauxmon)
181 elseif (BUILD_dpauxmon)
182         #message( WARNING "Cannot find libnl3, cannot build dpauxmon" )
183 endif()
184
185 if(BUILD_udpdump)
186         set(udpdump_LIBS
187                 ${GLIB2_LIBRARIES}
188                 ${CMAKE_DL_LIBS}
189                 wsutil
190                 writecap
191         )
192         set(udpdump_FILES
193                 udpdump.c
194                 extcap-base.c
195         )
196
197         set_executable_resources(udpdump "udpdump")
198         add_executable(udpdump ${udpdump_FILES})
199         set_extcap_executable_properties(udpdump)
200         target_link_libraries(udpdump ${udpdump_LIBS})
201         install(TARGETS udpdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
202         add_dependencies(extcaps udpdump)
203 endif()
204
205 if(BUILD_randpktdump)
206         set(randpktdump_LIBS
207                 randpkt_core
208                 ui
209                 wiretap
210                 ${GLIB2_LIBRARIES}
211                 ${ZLIB_LIBRARIES}
212                 ${CMAKE_DL_LIBS}
213         )
214         set(randpktdump_FILES
215                 extcap-base.c
216                 randpktdump.c
217         )
218
219         set_executable_resources(randpktdump "randpktdump")
220         add_executable(randpktdump ${randpktdump_FILES})
221         # XXX Shouldn't we add wsutil to randpktdump_LIBS instead?
222         set_extcap_executable_properties(randpktdump)
223         target_link_libraries(randpktdump ${randpktdump_LIBS})
224         install(TARGETS randpktdump RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
225         add_dependencies(extcaps randpktdump)
226 endif()
227
228 if(BUILD_sdjournal AND SYSTEMD_FOUND)
229         set(sdjournal_LIBS
230                 ui
231                 wiretap
232                 writecap
233                 wsutil
234                 ${GLIB2_LIBRARIES}
235                 ${ZLIB_LIBRARIES}
236                 ${CMAKE_DL_LIBS}
237                 ${SYSTEMD_LIBRARIES}
238         )
239         set(sdjournal_FILES
240                 extcap-base.c
241                 sdjournal.c
242         )
243
244         set_executable_resources(sdjournal "sdjournal")
245         add_executable(sdjournal ${sdjournal_FILES})
246         set_extcap_executable_properties(sdjournal)
247         target_link_libraries(sdjournal ${sdjournal_LIBS})
248         install(TARGETS sdjournal RUNTIME DESTINATION ${EXTCAP_INSTALL_LIBDIR})
249         add_dependencies(extcaps sdjournal)
250 elseif (BUILD_sdjournal)
251         #message( WARNING "Cannot find libsystemd, cannot build sdjournal" )
252 endif()
253
254 set(CLEAN_C_FILES
255         ${dumpcap_FILES}
256         ${androiddump_FILES}
257         ${sshdump_FILES}
258         ${ciscodump_FILES}
259 )