Beginnings of enabling static builds. Still to do:
[obnox/wireshark/wip.git] / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # $Id$
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 #
23
24 project(Wireshark C)
25
26 cmake_minimum_required(VERSION 2.6)
27
28 #Where to find local cmake scripts
29 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
30 INCLUDE(UseLemon)
31 INCLUDE(UseMakeDissectorReg)
32 INCLUDE(UseMakeTapReg)
33
34 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
35
36 # Disable this later. Alternative: "make VERBOSE=1"
37 set(CMAKE_VERBOSE_MAKEFILE ON)
38
39 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
40 include(CMakeInstallDirs)
41
42 include_directories(
43         ${CMAKE_BINARY_DIR}
44         ${CMAKE_SOURCE_DIR}
45         ${CMAKE_SOURCE_DIR}/epan
46         ${CMAKE_SOURCE_DIR}/tools/lemon
47         ${CMAKE_SOURCE_DIR}/wiretap
48 )
49
50 #Where to put libraries
51 if(NOT LIBRARY_OUTPUT_PATH)
52         set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/lib CACHE INTERNAL
53                    "Single output directory for building all libraries.")
54 endif()
55
56 option(BUILD_wireshark   "Build the GUI version of Wireshark" ON)
57 option(BUILD_tshark      "Build tshark" ON)
58 option(BUILD_rawshark    "Build rawshark" ON)
59 option(BUILD_dumpcap     "Build dumpcap" ON)
60 option(BUILD_text2pcap   "Build text2pcap" ON)
61 option(BUILD_mergecap    "Build mergecap" ON)
62 option(BUILD_editcap     "Build editcap" ON)
63 option(BUILD_capinfos    "Build capinfos" ON)
64 option(BUILD_randpkt     "Build randpkt" ON)
65 option(BUILD_dftest      "Build dftest" ON)
66 option(AUTOGEN_dcerpc    "Autogenerate dcerpc dissectors" OFF)
67 option(AUTOGEN_pidl      "Autogenerate pidl dissectors" OFF)
68
69 option(DISABLE_WERROR    "Do not treat Warnings as errors" OFF)
70 option(ENABLE_EXTRA_GCC_CHECKS "Do additional -W checks in GCC (disables -Werror)" OFF)
71 option(ENABLE_AIRPCAP    "Enable Airpcap support" ON)
72 option(ENABLE_STATIC     "Build a static version of Wireshark (not yet working)" OFF)
73 option(ENABLE_PLUGINS    "Build with plugins" ON)
74 # todo
75 option(ENABLE_GUIDES     "Build Guides (not yet implemented)" OFF)
76
77 option(ENABLE_ADNS       "Build with adns support" ON)
78 option(ENABLE_PCRE       "Build with pcre support" ON)
79 option(ENABLE_PORTAUDIO  "Build with portaudio support" ON)
80 option(ENABLE_Z          "Build with zlib compression support" ON)
81 option(ENABLE_LUA        "Build with lua dissector support" ON)
82 option(ENABLE_PYTHON     "Build with python dissector support" ON)
83 option(ENABLE_SMI        "Build with smi snmp support" ON)
84 option(ENABLE_GNUTLS     "Build with GNU TLS support" ON)
85 option(ENABLE_GCRYPT     "Build with GNU crypto support" ON)
86 option(ENABLE_GEOIP      "Build with GeoIP support" ON)
87 option(ENABLE_CAP        "Build with posix capabilities support" ON)
88 option(ENABLE_CARES      "Build with c_ares support" ON)
89 # todo Mostly hardcoded
90 option(ENABLE_KERBEROS   "Build with Kerberos support" ON)
91
92
93 set(WIRESHARK_C_FLAGS
94         -O2
95         -Wall
96         -W
97         -Wextra
98         -Wdeclaration-after-statement
99         -Wendif-labels
100         -Wpointer-arith
101         -Wno-pointer-sign
102         -Warray-bounds
103         -Wcast-align
104         -Wformat-security
105 )
106
107 set(WIRESHARK_EXTRA_C_FLAGS
108         -pedantic
109         -Woverflow
110         -Wlogical-op
111         -Wno-overlength-strings
112         -fstrict-overflow -Wstrict-overflow=4
113         -Wunreachable-code
114         -Wunsafe-loop-optimizations
115         -Wno-long-long
116         -Wbad-function-cast
117         -Wcast-qual
118         -Waddress
119         -Warray-bounds
120         -Wattributes
121         -Wdiv-by-zero
122         -Wformat-security
123         -Wignored-qualifiers
124         -Wpragmas
125         -Wredundant-decls
126         -Wvla
127         -Wc++-compat
128         -Wjump-misses-init
129         # packet-ncp2222.inc prevents this from going into all warnings
130         -Wwrite-strings
131         -Wstrict-prototypes
132         -Wmissing-declarations
133         # Problem with packet-afs.c
134         -Wshadow
135         # More cleanup needed for this on LP64
136         -Wshorten-64-to-32
137 )
138
139 if(ENABLE_EXTRA_GCC_CHECKS)   # This overrides -Werror
140         set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS} ${WIRESHARK_EXTRA_C_FLAGS})
141 endif()
142
143 add_definitions(
144         -DHAVE_CONFIG_H
145         -DPACKAGE=\"wireshark\"
146         -DNEW_PACKET_LIST
147 )
148
149 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
150 include(CheckCCompilerFlag)
151 set(C 0)
152 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
153 foreach(THIS_FLAG ${WIRESHARK_C_FLAGS})
154         set(F WS_C_FLAG_${C})
155         set(${F} ${THIS_FLAG})
156         set(V WS_C_FLAG_VALID${C})
157         check_c_compiler_flag(${${F}} ${V})
158         if (${${V}})
159                 add_definitions(${${F}})
160         endif()
161         math(EXPR C "${C} + 1")
162 endforeach()
163
164 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_GCC_CHECKS)
165         check_c_compiler_flag(-Werror WERROR)
166 else()
167         set(WERROR 0)
168 endif()
169
170 if(CMAKE_COMPILER_IS_GNUCC)
171         add_definitions( -D_U_=__attribute__\(\(unused\)\) )
172 else()
173         add_definitions( -D_U_=\"\" )
174 endif()
175
176 # todo
177 # Same for linker flags, but it looks like it's do-it-yourself here
178 # AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,--as-needed])
179 # AC_WIRESHARK_GCC_LDFLAGS_CHECK([-flto])
180 # AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhopr])
181 # AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhole-program])
182
183 if(ENABLE_STATIC)
184   set(LINK_MODE_LIB STATIC)
185   set(LINK_MODE_MODULE STATIC)
186 else()
187   set(LINK_MODE_LIB SHARED)
188   set(LINK_MODE_MODULE MODULE)
189 endif()
190
191 #The minimum package list
192 set(PACKAGELIST GLIB2 PCAP M LEX YACC Perl SH PythonInterp HtmlViewer ${PACKAGELIST})
193
194 #Build the gui ?
195 if(BUILD_wireshark)
196         set(PACKAGELIST GTK2 ${PACKAGELIST})
197 endif()
198
199 # SMI SNMP
200 if(ENABLE_SMI)
201         set(PACKAGELIST SMI ${PACKAGELIST})
202 endif()
203
204 # GNU crypto
205 if(ENABLE_GCRYPT)
206         set(PACKAGELIST GCRYPT ${PACKAGELIST})
207 endif()
208
209 # GNU SSL/TLS support
210 if(ENABLE_GNUTLS)
211         set(PACKAGELIST GNUTLS ${PACKAGELIST})
212 endif()
213
214 # Regular expressions lib
215 if(ENABLE_PCRE)
216         set(PACKAGELIST PCRE ${PACKAGELIST})
217 endif()
218
219 # Kerberos
220 if(ENABLE_KERBEROS)
221         set(PACKAGELIST KERBEROS ${PACKAGELIST})
222 endif()
223
224 # Portable audio
225 if(ENABLE_PORTAUDIO)
226         set(PACKAGELIST PORTAUDIO ${PACKAGELIST})
227 endif()
228
229
230 # Prefer c-ares over adns
231 if(ENABLE_CARES)        # C Asynchronouse resolver
232         set(PACKAGELIST CARES ${PACKAGELIST})
233 elseif(ENABLE_ADNS)     # Gnu asynchronous DNS
234         set(PACKAGELIST ADNS ${PACKAGELIST})
235 endif()
236
237 # Zlib compression
238 if(ENABLE_Z)
239         set(PACKAGELIST Z ${PACKAGELIST})
240 endif()
241
242 # Lua 5.1 dissectors
243 if(ENABLE_LUA)
244         set(PACKAGELIST LUA ${PACKAGELIST})
245 endif()
246
247 # GeoIP address resolving
248 if(ENABLE_GEOIP)
249         set(PACKAGELIST GEOIP ${PACKAGELIST})
250 endif()
251
252 # Capabilities
253 if(ENABLE_CAP)
254         set(PACKAGELIST CAP ${PACKAGELIST})
255 endif()
256
257 if(ENABLE_PYTHON)
258         set(PACKAGELIST PYTHON ${PACKAGELIST})
259 endif()
260
261 set(PROGLIST text2pcap mergecap capinfos editcap dumpcap)
262
263 #Let's loop the package list
264 foreach(PACKAGE ${PACKAGELIST})
265         find_package(${PACKAGE} REQUIRED)
266         message(${PACKAGE}_FOUND)
267         if (${PACKAGE}_FOUND)
268                 set(HAVE_LIB${PACKAGE} 1)
269                 include_directories(${${PACKAGE}_INCLUDE_DIRS})
270                 message(STATUS "${PACKAGE} includes: ${${PACKAGE}_INCLUDE_DIRS}")
271                 message(STATUS "${PACKAGE} libs: ${${PACKAGE}_LIBRARIES}")
272         endif()
273 endforeach()
274
275 find_package(YAPP)
276
277 if(HAVE_LIBPYTHON)
278         set(HAVE_PYTHON 1)
279         set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${CPACK_PACKAGE_VERSION}")
280 endif()
281 if(HAVE_LIBLUA)
282         set(HAVE_LUA_H 1)
283         set(HAVE_LUA_5_1 1)
284 endif()
285 if(HAVE_LIBKERBEROS)
286         set(HAVE_KERBEROS 1)
287         # HAVE_HEIMDAL_KERBEROS
288         set(HAVE_MIT_KERBEROS 1)
289         set(HAVE_KEYTYPE_ARCFOUR_56 1)
290 endif()
291 if(HAVE_LIBGEOIP)
292         set(HAVE_GEOIP 1)
293 endif()
294 if(HAVE_LIBCARES)
295         set(HAVE_C_ARES 1)
296 endif()
297 if(HAVE_LIBADNS)
298         set(HAVE_GNU_ADNS 1)
299 endif()
300 if(ENABLE_AIRPCAP)
301         set(HAVE_AIRPCAP 1)
302 endif()
303
304 include(ConfigureChecks.cmake)
305
306 #Big or little endian ?
307 include(TestBigEndian)
308 test_big_endian(WORDS_BIGENDIAN)
309
310 #packaging
311 set(CPACK_PACKAGE_NAME wireshark)
312 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "capture packet")
313 set(CPACK_PACKAGE_VENDOR "wireshark")
314 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
315 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
316 set(CPACK_PACKAGE_VERSION_MAJOR "1")
317 set(CPACK_PACKAGE_VERSION_MINOR "3")
318 set(CPACK_PACKAGE_VERSION_PATCH "2")
319 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
320
321 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
322 set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr")
323 set(CPACK_GENERATOR "TGZ")
324 set(CPACK_SOURCE_GENERATOR "TGZ")
325
326 set(DATAFILE_DIR "${CMAKE_INSTALL_PREFIX}/share/${CPACK_PACKAGE_NAME}")
327
328 if(ENABLE_PLUGINS)
329         set(HAVE_PLUGINS 1)
330         set(PLUGIN_DIR="${DATAFILE_DIR}/plugins/${CPACK_PACKAGE_VERSION}")
331         set(PLUGIN_SRC_DIRS
332                 plugins/asn1
333                 plugins/docsis
334                 plugins/ethercat
335                 plugins/giop
336                 plugins/gryphon
337                 plugins/irda
338                 plugins/m2m
339                 plugins/mate
340                 plugins/opcua
341                 plugins/profinet
342                 plugins/sercosiii
343                 plugins/stats_tree
344                 plugins/unistim
345                 plugins/wimax
346                 plugins/wimaxasncp
347         )
348 # It seems this stuff doesn't build with autofoo either...
349 #       if(YAPP_FOUND)
350 #               set(PLUGIN_SRC_DIRS
351 #                       ${PLUGIN_SRC_DIRS}
352 #                       plugins/tpg
353 #               )
354 #       endif()
355 else()
356         set(PLUGIN_SRC_DIRS )
357 endif()
358
359 foreach(PLUGIN_DIR ${PLUGIN_SRC_DIRS})
360         add_subdirectory( ${PLUGIN_DIR} )
361 endforeach()
362
363 add_subdirectory( codecs )
364 add_subdirectory( epan )
365 add_subdirectory( gtk )
366 add_subdirectory( tools/lemon )
367 add_subdirectory( wiretap )
368 add_subdirectory( wsutil )
369
370 if(ENABLE_GUIDES)
371 # todo
372 #       add_subdirectory( docbook )
373 endif()
374
375 #Platform specific
376 if(UNIX)
377         set(WS_VAR_IMPORT "extern")
378 endif()
379
380 if(APPLE)
381 #TODO verify that APPLE implies HAVE_OS_X_FRAMEWORKS
382         set(HAVE_OS_X_FRAMEWORKS 1)
383         FIND_LIBRARY (APPLE_CORE_SERVICES_LIBRARY CoreServices)
384         FIND_LIBRARY (APPLE_COCOA_LIBRARY Cocoa)
385 endif()
386
387 if(WIN32)
388         add_definitions(-D_NEED_VAR_IMPORT_)
389         set(WS_VAR_IMPORT "__declspec(dllimport) extern")
390
391         # Disable deprecation
392         if(MSVC80 OR MSVC90)
393                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
394         endif()
395 endif()
396
397 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
398
399 include(FeatureSummary)
400 #SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ]
401 PRINT_ENABLED_FEATURES()
402 PRINT_DISABLED_FEATURES()
403
404 link_directories(
405         gtk
406         codecs
407         epan
408         wiretap
409         wsutil
410 )
411
412 ADD_CUSTOM_COMMAND(
413         OUTPUT svnversion.h
414         COMMAND ${PERL}
415                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
416                 ${CMAKE_CURRENT_SOURCE_DIR}
417         DEPENDS
418                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
419 )
420
421 register_tap_files(tshark-tap-register.c
422         ${TSHARK_TAP_SRC}
423 )
424
425 ADD_CUSTOM_COMMAND(
426         OUTPUT ps.c
427         COMMAND ${PYTHON_EXECUTABLE}
428           ${CMAKE_CURRENT_SOURCE_DIR}/tools/rdps.py
429           ${CMAKE_CURRENT_SOURCE_DIR}/print.ps
430           ps.c
431         DEPENDS
432           ${CMAKE_CURRENT_SOURCE_DIR}/tools/rdps.py
433           ${CMAKE_CURRENT_SOURCE_DIR}/print.ps
434 )
435
436 if(UNIX)
437         set(PLATFORM_SRC
438                 capture-pcap-util-unix.c
439         )
440 endif()
441
442 if(WIN32)
443         set(PLATFORM_SRC
444                 capture-wpcap.c capture_wpcap_packet.c
445         )
446 endif()
447
448 set(WTAP_PLUGIN_SOURCES
449         epan/plugins.c
450         epan/report_err.c
451         epan/filesystem.c
452 )
453
454 set(WIRESHARK_COMMON_SRC
455         ${PLATFORM_SRC}
456         capture_errs.c
457         capture-pcap-util.c
458         capture_ui_utils.c
459         cfile.c
460         clopts_common.c
461         disabled_protos.c
462         packet-range.c
463         print.c
464         ps.c
465         sync_pipe_write.c
466         timestats.c
467         util.c
468         tap-megaco-common.c
469         tap-rtp-common.c
470         version_info.c
471 )
472
473 set(TSHARK_TAP_SRC
474         tap-afpstat.c
475         tap-ansi_astat.c
476         tap-bootpstat.c
477         tap-camelcounter.c
478         tap-camelsrt.c
479         tap-comparestat.c
480         tap-dcerpcstat.c
481         tap-funnel.c
482         tap-gsm_astat.c
483         tap-h225counter.c
484         tap-h225rassrt.c
485         tap-httpstat.c
486         tap-iostat.c
487         tap-iousers.c
488         tap-mgcpstat.c
489         tap-megacostat.c
490         tap-protocolinfo.c
491         tap-protohierstat.c
492         tap-radiusstat.c
493         tap-rpcstat.c
494         tap-rpcprogs.c
495         tap-rtp.c
496         tap-sctpchunkstat.c
497         tap-sipstat.c
498         tap-smbsids.c
499         tap-smbstat.c
500         tap-stats_tree.c
501         tap-wspstat.c
502 )
503
504 set(INSTALL_DIRS
505         diameter
506         dtds
507         help
508         radius
509         tpncp
510         wimaxasncp
511 )
512
513 set(INSTALL_FILES
514         ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
515         COPYING
516         ${CMAKE_BINARY_DIR}/capinfos.html
517         cfilters
518         colorfilters
519         dfilters
520         ${CMAKE_BINARY_DIR}/dumpcap.html
521         ${CMAKE_BINARY_DIR}/editcap.html
522         ${CMAKE_BINARY_DIR}/idl2wrs.html
523         ipmap.html
524         manuf
525         ${CMAKE_BINARY_DIR}/mergecap.html
526         ${CMAKE_BINARY_DIR}/rawshark.html
527         services
528         smi_modules
529         ${CMAKE_BINARY_DIR}/text2pcap.html
530         ${CMAKE_BINARY_DIR}/tshark.html
531         ${CMAKE_BINARY_DIR}/wireshark-filter.html
532         ${CMAKE_BINARY_DIR}/wireshark.html
533         docbook/ws.css
534 )
535
536 set(LIBEPAN_LIBS
537 #               @GETOPT_O@      # wsgetopt.c
538 #               @INET_ATON_LO@  # epan/inet_aton.c
539 #               @INET_NTOP_LO@  # inet_ntop.c
540 #               @INET_PTON_LO@  # inet_pton.c
541 #               @NSL_LIBS@      # -lnsl
542 #               @SOCKET_LIBS@   # -lsocket
543 #               @SSL_LIBS@      # -lcrypto
544 #               @STRERROR_O@    # strerror.c
545 #               @STRNCASECMP_O@ # strncasecmp.c
546 #               @STRPTIME_O@    # strptime.c
547                 epan
548 #               $(plugin_ldadd) # in case of static
549                 ${PCRE_LIBRARIES}
550                 ${PCAP_LIBRARIES}
551                 ${CARES_LIBRARIES}
552                 ${ADNS_LIBRARIES}
553                 ${KERBEROS_LIBRARIES}
554                 ${LUA_LIBRARIES}
555                 ${PYTHON_LIBRARIES}
556                 ${GEOIP_LIBRARIES}
557                 ${GCRYPT_LIBRARIES}
558                 ${GNUTLS_LIBRARIES}
559                 ${SMI_LIBRARIES}
560                 ${Z_LIBRARIES}
561                 ${M_LIBRARIES}
562 )
563
564 if(BUILD_wireshark)
565         set(wireshark_LIBS
566                 ui
567                 ${GTK2_LIBRARIES}
568                 codecs
569                 ${PORTAUDIO_LIBRARIES}
570                 ${LIBEPAN_LIBS}
571                 ${APPLE_CORE_SERVICES_LIBRARY}
572                 ${APPLE_COCOA_LIBRARY}
573         )
574         set(wireshark_FILES
575                 airpcap_loader.c
576                 alert_box.c
577                 capture.c
578                 capture_info.c
579                 capture_opts.c
580                 capture_sync.c
581                 color_filters.c
582                 file.c
583                 fileset.c
584                 filters.c
585                 g711.c
586                 merge.c
587                 proto_hier_stats.c
588                 summary.c
589                 tempfile.c
590                 ${WIRESHARK_COMMON_SRC}
591         )
592         add_executable(wireshark ${wireshark_FILES})
593         target_link_libraries(wireshark ${wireshark_LIBS})
594         install(TARGETS wireshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
595 endif()
596
597 if(BUILD_tshark)
598         set(tshark_LIBS
599                 ${LIBEPAN_LIBS}
600                 ${APPLE_COCOA_LIBRARY}
601         )
602         set(tshark_FILES
603                 capture_opts.c
604                 capture_sync.c
605                 tempfile.c
606                 tshark-tap-register.c
607                 tshark.c
608                 ${TSHARK_TAP_SRC}
609                 ${WIRESHARK_COMMON_SRC}
610         )
611         add_executable(tshark ${tshark_FILES})
612         target_link_libraries(tshark ${tshark_LIBS})
613         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
614 endif()
615
616 if(BUILD_rawshark)
617         set(rawshark_LIBS
618                 ${LIBEPAN_LIBS}
619                 ${APPLE_COCOA_LIBRARY}
620         )
621         set(rawshark_FILES
622                 ${WIRESHARK_COMMON_SRC}
623                 rawshark.c
624         )
625         add_executable(rawshark ${rawshark_FILES})
626         target_link_libraries(rawshark ${rawshark_LIBS})
627         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
628 endif()
629
630 if(BUILD_dftest)
631         set(dftest_LIBS
632                 ${LIBEPAN_LIBS}
633         )
634         set(dftest_FILES
635                 dftest.c
636                 util.c
637         )
638         add_executable(dftest ${dftest_FILES})
639         target_link_libraries(dftest ${dftest_LIBS})
640         install(TARGETS dftest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
641 endif()
642
643 if(BUILD_randpkt)
644         set(randpkt_LIBS
645                 wiretap
646                 ${M_LIBRARIES}
647                 ${PCAP_LIBRARIES}
648 #               @SOCKET_LIBS@
649 #               @NSL_LIBS@
650                 ${CARES_LIBRARIES}
651                 ${ADNS_LIBRARIES}
652                 ${Z_LIBRARIES}
653         )
654         set(randpkt_FILES
655                 randpkt.c
656         )
657         add_executable(randpkt ${randpkt_FILES})
658         target_link_libraries(randpkt ${randpkt_LIBS})
659         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
660 endif()
661
662 if(BUILD_text2pcap)
663         set(text2pcap_LIBS
664                 wiretap
665                 ${M_LIBRARIES}
666                 ${Z_LIBRARIES}
667         )
668         set(text2pcap_FILES
669                 text2pcap.c
670         )
671         set(text2pcap_CLEAN_FILES
672                 ${text2pcap_FILES}
673         )
674         add_lex_files(text2pcap_FILES
675                 text2pcap-scanner.l
676         )
677         add_executable(text2pcap ${text2pcap_FILES})
678         target_link_libraries(text2pcap ${text2pcap_LIBS})
679         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
680 endif()
681
682 if(BUILD_mergecap)
683         set(mergecap_LIBS
684                 wiretap
685                 ${Z_LIBRARIES}
686         )
687         set(mergecap_FILES
688                 mergecap.c
689                 merge.c
690                 svnversion.h
691         )
692         add_executable(mergecap ${mergecap_FILES})
693         target_link_libraries(mergecap ${mergecap_LIBS})
694         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
695 endif()
696
697 if(BUILD_capinfos)
698         set(capinfos_LIBS
699                 wiretap
700                 ${Z_LIBRARIES}
701                 ${APPLE_COCOA_LIBRARY}
702         )
703         set(capinfos_FILES
704                 capinfos.c
705                 ${WTAP_PLUGIN_SOURCES}
706         )
707         add_executable(capinfos ${capinfos_FILES})
708         target_link_libraries(capinfos ${capinfos_LIBS})
709         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
710 endif()
711
712 if(BUILD_editcap)
713         set(editcap_LIBS
714                 wiretap
715                 ${Z_LIBRARIES}
716         )
717         set(editcap_FILES
718                 editcap.c
719                 epan/crypt/crypt-md5.c
720                 epan/nstime.c
721                 ${WTAP_PLUGIN_SOURCES}
722         )
723         add_executable(editcap ${editcap_FILES})
724         target_link_libraries(editcap ${editcap_LIBS})
725         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
726 endif()
727
728 if(BUILD_dumpcap)
729         set(dumpcap_LIBS
730                 wiretap
731 #               @INET_NTOP_LO@
732                 ${PCAP_LIBRARIES}
733                 ${CAP_LIBRARIES}
734 #               @SOCKET_LIBS@
735 #               @NSL_LIBS@
736                 ${GCRYPT_LIBRARIES}
737                 ${GNUTLS_LIBRARIES}
738                 ${Z_LIBRARIES}
739                 ${APPLE_COCOA_LIBRARY}
740         )
741         set(dumpcap_FILES
742                 svnversion.h
743                 capture_opts.c
744                 capture-pcap-util.c
745                 capture_stop_conditions.c
746                 clopts_common.c
747                 conditions.c
748                 dumpcap.c
749                 pcapio.c
750                 ringbuffer.c
751                 sync_pipe_write.c
752                 tempfile.c
753                 version_info.c
754                 ${PLATFORM_SRC}
755         )
756         add_executable(dumpcap ${dumpcap_FILES})
757         target_link_libraries(dumpcap ${dumpcap_LIBS})
758         install(TARGETS dumpcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
759 endif()
760
761 ADD_CUSTOM_COMMAND(
762         OUTPUT  AUTHORS-SHORT
763         COMMAND ${PERL}
764                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
765                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
766                 < ${CMAKE_SOURCE_DIR}/AUTHORS
767                 > AUTHORS-SHORT
768         DEPENDS
769                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
770                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
771                 ${CMAKE_SOURCE_DIR}/AUTHORS
772 )
773
774 ADD_CUSTOM_COMMAND(
775         OUTPUT  AUTHORS-SHORT-FORMAT
776                 wireshark.pod
777         COMMAND ${PERL}
778                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
779                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
780                 < AUTHORS-SHORT
781                 > AUTHORS-SHORT-FORMAT
782         COMMAND cat
783                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
784                 AUTHORS-SHORT-FORMAT
785                 > wireshark.pod
786         DEPENDS
787                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
788                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
789                 AUTHORS-SHORT
790                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
791 )
792
793 ADD_CUSTOM_COMMAND(
794         OUTPUT  wireshark-filter.pod
795         COMMAND tshark
796                 -G fields |
797                 ${PERL}
798                 ${CMAKE_SOURCE_DIR}/doc/dfilter2pod.pl
799                 ${CMAKE_SOURCE_DIR}/doc/wireshark-filter.pod.template
800                 > wireshark-filter.pod
801         DEPENDS
802                 ${CMAKE_SOURCE_DIR}/doc/dfilter2pod.pl
803                 ${CMAKE_SOURCE_DIR}/doc/wireshark-filter.pod.template
804                 tshark
805 )
806
807 find_package(POD)
808
809 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
810 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
811 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
812 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
813 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
814 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
815 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
816 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
817 pod2manhtml( wireshark 1 )
818 pod2manhtml( wireshark-filter 4 )
819
820 add_custom_target(
821         auxiliary ALL
822         DEPENDS
823                 AUTHORS-SHORT
824                 capinfos.html
825                 dumpcap.html
826                 editcap.html
827                 idl2wrs.html
828                 mergecap.html
829                 rawshark.html
830                 text2pcap.html
831                 tshark.html
832                 wireshark.html
833                 wireshark-filter.html
834 )
835
836 set(MAN1_FILES
837         ${CMAKE_BINARY_DIR}/capinfos.1
838         ${CMAKE_BINARY_DIR}/dumpcap.1
839         ${CMAKE_BINARY_DIR}/editcap.1
840         ${CMAKE_BINARY_DIR}/idl2wrs.1
841         ${CMAKE_BINARY_DIR}/mergecap.1
842         ${CMAKE_BINARY_DIR}/rawshark.1
843         ${CMAKE_BINARY_DIR}/text2pcap.1
844         ${CMAKE_BINARY_DIR}/tshark.1
845         ${CMAKE_BINARY_DIR}/wireshark.1
846 )
847
848 set(MAN4_FILES
849         ${CMAKE_BINARY_DIR}/wireshark-filter.4
850 )
851
852 set(CLEAN_FILES
853         ${wireshark_FILES}
854         ${tshark_FILES}
855         ${rawshark_FILES}
856         ${dftest_FILES}
857         ${randpkt_FILES}
858         ${text2pcap_CLEAN_FILES}
859         ${mergecap_FILES}
860         ${capinfos_FILES}
861         ${editcap_FILES}
862         ${dumpcap_FILES}
863 )
864
865 if (WERROR)
866         set_source_files_properties(
867                 ${CLEAN_FILES}
868                 PROPERTIES
869                 COMPILE_FLAGS -Werror
870         )
871 endif()
872
873 install(
874         FILES
875                 ${INSTALL_FILES}
876         DESTINATION
877                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
878 )
879
880 install(
881         FILES
882                 ${MAN1_FILES}
883         DESTINATION
884                 ${CMAKE_INSTALL_MANDIR}/man1
885 )
886
887 install(
888         FILES
889                 ${MAN4_FILES}
890         DESTINATION
891                 ${CMAKE_INSTALL_MANDIR}/man4
892 )
893
894 install(
895         DIRECTORY
896                 ${INSTALL_DIRS}
897         DIRECTORY_PERMISSIONS
898                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
899                 GROUP_EXECUTE GROUP_READ
900                 WORLD_EXECUTE WORLD_READ
901         DESTINATION
902                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
903         PATTERN ".svn" EXCLUDE
904         PATTERN "Makefile.*" EXCLUDE
905         PATTERN "faq.py" EXCLUDE
906 )