Use val_to_str_const().
[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 set(CMAKE_BACKWARDS_COMPATIBILITY 2.6)
28
29 # Needs to be set after cmake_minimum_required or cmake_policy(VERSION)
30 if(COMMAND cmake_policy)
31         # Backward compatibility for versions < 2.6.3
32         cmake_policy(SET CMP0011 OLD)
33 #       cmake_policy(SET CMP0015 NEW)
34 endif(COMMAND cmake_policy)
35
36 # set(PROJECT_VERSION "1.3.4-rc5")
37 # set(PROJECT_VERSION "1.3.4rc5")
38 # set(PROJECT_VERSION "1.3.4")
39 # If not set, copy over Wireshark version from configure.in AC_INIT
40 if(NOT PROJECT_VERSION)
41         file(STRINGS
42                 ${CMAKE_SOURCE_DIR}/configure.in
43                 VERSIONLINE
44                 REGEX "\\(wireshark, .*\\)"
45         )
46         string(REGEX REPLACE ".*\\(wireshark, (.*)\\).*"
47                 "\\1"
48                 PROJECT_VERSION
49                 ${VERSIONLINE}
50         )
51 endif()
52 string(REGEX REPLACE "([0-9]+)\\..*"
53         "\\1"
54         PROJECT_MAJOR_VERSION
55         ${PROJECT_VERSION}
56 )
57 string(REGEX REPLACE ".*\\.([0-9]+)\\..*"
58         "\\1"
59         PROJECT_MINOR_VERSION
60         ${PROJECT_VERSION}
61 )
62 string(REGEX REPLACE ".*\\..*\\.([0-9]+).*"
63         "\\1"
64         PROJECT_PATCH_VERSION
65         ${PROJECT_VERSION}
66 )
67 string(REGEX REPLACE ".*\\..*\\.[0-9]+(.*)"
68         "\\1"
69         PROJECT_VERSION_EXTENSION
70         ${PROJECT_VERSION}
71 )
72 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
73
74 #Where to find local cmake scripts
75 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
76 INCLUDE(UseLemon)
77 INCLUDE(UseMakeDissectorReg)
78 INCLUDE(UseMakeTapReg)
79
80 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
81
82 # Enable with: "make VERBOSE=1"
83 set(CMAKE_VERBOSE_MAKEFILE OFF)
84
85 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
86 include(CMakeInstallDirs)
87
88 include_directories(
89         ${CMAKE_BINARY_DIR}
90         ${CMAKE_SOURCE_DIR}
91         ${CMAKE_SOURCE_DIR}/epan
92         ${CMAKE_SOURCE_DIR}/tools/lemon
93         ${CMAKE_SOURCE_DIR}/wiretap
94 )
95
96 #Where to put libraries
97 if(NOT LIBRARY_OUTPUT_PATH)
98         set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/lib CACHE INTERNAL
99                    "Single output directory for building all libraries.")
100 endif()
101
102
103 include(CMakeOptions.txt)
104
105
106 set(WIRESHARK_C_FLAGS
107         -O2
108         -Wall
109         -W
110         -Wextra
111         -Wdeclaration-after-statement
112         -Wendif-labels
113         -Wpointer-arith
114         -Wno-pointer-sign
115         -Warray-bounds
116         -Wcast-align
117         -Wformat-security
118         -Wold-style-definition
119         -fexcess-precision=fast
120 )
121
122 set(WIRESHARK_EXTRA_C_FLAGS
123         -pedantic
124         -Woverflow
125         -Wlogical-op
126         -Wno-overlength-strings
127         -fstrict-overflow -Wstrict-overflow=4
128         -Wunreachable-code
129         -Wunsafe-loop-optimizations
130         -Wno-long-long
131         -Wbad-function-cast
132         -Wcast-qual
133         -Waddress
134         -Warray-bounds
135         -Wattributes
136         -Wdiv-by-zero
137         -Wformat-security
138         -Wignored-qualifiers
139         -Wpragmas
140         -Wredundant-decls
141         -Wvla
142         -Wc++-compat
143         -Wjump-misses-init
144         # packet-ncp2222.inc prevents this from going into all warnings
145         -Wwrite-strings
146         # GLib blocks this for now.
147         -Wstrict-prototypes
148         # All the registration functions block these for now.
149         -Wmissing-prototypes
150         -Wmissing-declarations
151         # Problem with packet-afs.c
152         -Wshadow
153         # More cleanup needed for this on LP64
154         -Wshorten-64-to-32
155 )
156
157 if(ENABLE_EXTRA_GCC_CHECKS)   # This overrides -Werror
158         set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS} ${WIRESHARK_EXTRA_C_FLAGS})
159 endif()
160
161 add_definitions(
162         -DHAVE_CONFIG_H
163         -DG_DISABLE_DEPRECATED
164 )
165
166 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
167 include(CheckCCompilerFlag)
168 set(C 0)
169 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
170 foreach(THIS_FLAG ${WIRESHARK_C_FLAGS})
171         set(F WS_C_FLAG_${C})
172         set(${F} ${THIS_FLAG})
173         set(V WS_C_FLAG_VALID${C})
174         check_c_compiler_flag(${${F}} ${V})
175         if (${${V}})
176                 add_definitions(${${F}})
177         endif()
178         math(EXPR C "${C} + 1")
179 endforeach()
180
181 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_GCC_CHECKS)
182         check_c_compiler_flag(-Werror WERROR)
183 else()
184         set(WERROR 0)
185 endif()
186
187 if(CMAKE_COMPILER_IS_GNUCC)
188         add_definitions( -D_U_=__attribute__\(\(unused\)\) )
189 else()
190         add_definitions( -D_U_=\"\" )
191 endif()
192
193 set(WIRESHARK_LD_FLAGS
194         -Wl,--as-needed
195         # -flto
196         # -fwhopr
197         # -fwhole-program
198 )
199
200 include(CheckCLinkerFlag)
201 set(C 0)
202 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
203 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
204         set(F WS_LD_FLAG_${C})
205         set(${F} ${THIS_FLAG})
206         set(V WS_LD_FLAG_VALID${C})
207         check_c_linker_flag(${${F}} ${V})
208         if (${${V}})
209                 set(WS_LINK_FLAGS ${WS_LINK_FLAGS} ${${F}})
210         endif()
211         math(EXPR C "${C} + 1")
212 endforeach()
213
214 if(ENABLE_STATIC)
215   set(LINK_MODE_LIB STATIC)
216   set(LINK_MODE_MODULE STATIC)
217 else()
218   set(LINK_MODE_LIB SHARED)
219   set(LINK_MODE_MODULE MODULE)
220 endif()
221
222 # The packagelist is doing some magic:  If we add XXX to the packagelist, we
223 # - may optionally set XXX_OPTIONS to pass to the find_package command
224 # - will call FindXXX.cmake
225 # - return found libraries in XXX_LIBRARIES
226 # - return found include in XXX_INCLUDE_DIRS
227 # - set HAVE_XXX
228
229 #The minimum package list
230 set(PACKAGELIST GLIB2 GMODULE2 M LEX YACC Perl SH PythonInterp)
231 set(GLIB2_FIND_REQUIRED)
232 set(GLIB2_MIN_VERSION 2.14.0)
233 set(PCAP_REQUIRED)
234 set(M_REQUIRED)
235
236 set(PACKAGELIST ${PACKAGELIST} HtmlViewer)
237
238 if(ENABLE_PCAP)
239         set(PACKAGELIST ${PACKAGELIST} PCAP)
240 endif()
241
242 #Build the gui ?
243 if(BUILD_wireshark)
244         if(ENABLE_GTK3)
245                 set(PACKAGELIST ${PACKAGELIST} GTK3)
246                 set(ENABLE_UI_MANAGER ON)
247         else()
248                 set(PACKAGELIST ${PACKAGELIST} GTK2)
249                 set(GTK2_OPTIONS COMPONENTS gtk)
250                 set(GTK2_FIND_VERSION 2.12)
251                 set(GTK2_DEBUG false)
252         endif()
253         if(ENABLE_THREADS)
254                 set(PACKAGELIST ${PACKAGELIST} GTHREAD2)
255         endif()
256 endif()
257
258 if(BUILD_dumpcap)
259         set(PACKAGELIST ${PACKAGELIST} GTHREAD2)
260         set(GHTREAD2_REQUIRED)
261 endif()
262
263 # SMI SNMP
264 if(ENABLE_SMI)
265         set(PACKAGELIST ${PACKAGELIST} SMI)
266 endif()
267
268 # GNU crypto
269 if(ENABLE_GCRYPT)
270         set(PACKAGELIST ${PACKAGELIST} GCRYPT)
271 endif()
272
273 # GNU SSL/TLS support
274 if(ENABLE_GNUTLS)
275         set(PACKAGELIST ${PACKAGELIST} GNUTLS)
276 endif()
277
278 # Kerberos
279 if(ENABLE_KERBEROS)
280         set(PACKAGELIST ${PACKAGELIST} KERBEROS)
281 endif()
282
283 # Portable audio
284 if(ENABLE_PORTAUDIO)
285         set(PACKAGELIST ${PACKAGELIST} PORTAUDIO)
286 endif()
287
288
289 # Prefer c-ares over adns
290 if(ENABLE_CARES)        # C Asynchronouse resolver
291         set(PACKAGELIST ${PACKAGELIST} CARES)
292 elseif(ENABLE_ADNS)     # Gnu asynchronous DNS
293         set(PACKAGELIST ${PACKAGELIST} ADNS)
294 endif()
295
296 # Zlib compression
297 if(ENABLE_ZLIB)
298         set(PACKAGELIST ${PACKAGELIST} ZLIB)
299 endif()
300
301 # Lua 5.1 dissectors
302 if(ENABLE_LUA)
303         set(PACKAGELIST ${PACKAGELIST} LUA)
304 endif()
305
306 # GeoIP address resolving
307 if(ENABLE_GEOIP)
308         set(PACKAGELIST ${PACKAGELIST} GEOIP)
309 endif()
310
311 # Capabilities
312 if(ENABLE_CAP)
313         set(PACKAGELIST ${PACKAGELIST} CAP)
314 endif()
315
316 if(ENABLE_PYTHON)
317         set(PACKAGELIST ${PACKAGELIST} PYTHON)
318 endif()
319
320 set(PACKAGELIST ${PACKAGELIST} YAPP)
321
322 set(PACKAGELIST ${PACKAGELIST} POD)
323
324
325 set(PROGLIST text2pcap mergecap capinfos editcap dumpcap)
326
327 #Let's loop the package list
328 foreach(PACKAGE ${PACKAGELIST})
329         if(${PACKAGE}_OPTIONS)
330                 find_package(${PACKAGE} ${${PACKAGE}_OPTIONS})
331         elseif(${PACKAGE}_REQUIRED)
332                 find_package(${PACKAGE} REQUIRED)
333         else()
334                 find_package(${PACKAGE})
335         endif()
336         message(${PACKAGE}_FOUND)
337         if (${PACKAGE}_FOUND)
338                 set(HAVE_LIB${PACKAGE} 1)
339                 include_directories(${${PACKAGE}_INCLUDE_DIRS})
340                 message(STATUS "${PACKAGE} includes: ${${PACKAGE}_INCLUDE_DIRS}")
341                 message(STATUS "${PACKAGE} libs: ${${PACKAGE}_LIBRARIES}")
342         endif()
343 endforeach()
344
345 #packaging
346 include(CPackConfig.txt)
347
348 if(HAVE_LIBPYTHON)
349         set(HAVE_PYTHON 1)
350         set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${CPACK_PACKAGE_VERSION}")
351 endif()
352 if(HAVE_LIBLUA)
353         set(HAVE_LUA_H 1)
354         set(HAVE_LUA_5_1 1)
355 endif()
356 if(HAVE_LIBKERBEROS)
357         set(HAVE_KERBEROS 1)
358         # HAVE_HEIMDAL_KERBEROS
359         set(HAVE_MIT_KERBEROS 1)
360         set(HAVE_KEYTYPE_ARCFOUR_56 1)
361 endif()
362 if(HAVE_LIBGEOIP)
363         set(HAVE_GEOIP 1)
364 endif()
365 if(HAVE_LIBCARES)
366         set(HAVE_C_ARES 1)
367 endif()
368 if(HAVE_LIBADNS)
369         set(HAVE_GNU_ADNS 1)
370 endif()
371 if(ENABLE_AIRPCAP)
372         set(HAVE_AIRPCAP 1)
373 endif()
374 # No matter which version of GTK is present
375 if(GTK2_FOUND OR GTK3_FOUND)
376         set(GTK_FOUND ON)
377 endif()
378 # That's the name autofoo uses
379 if(HAVE_LIBZLIB)
380         set(HAVE_LIBZ 1)
381 endif()
382
383 include(ConfigureChecks.cmake)
384
385 #Big or little endian ?
386 include(TestBigEndian)
387 test_big_endian(WORDS_BIGENDIAN)
388
389 set(DATAFILE_DIR "${CMAKE_INSTALL_PREFIX}/share/${CPACK_PACKAGE_NAME}")
390
391 if(ENABLE_PLUGINS)
392         set(HAVE_PLUGINS 1)
393         set(PLUGIN_DIR="${DATAFILE_DIR}/plugins/${CPACK_PACKAGE_VERSION}")
394         set(PLUGIN_SRC_DIRS
395                 plugins/asn1
396                 plugins/docsis
397                 plugins/ethercat
398                 plugins/giop
399                 plugins/gryphon
400                 plugins/irda
401                 plugins/m2m
402                 plugins/mate
403                 plugins/opcua
404                 plugins/profinet
405                 plugins/stats_tree
406                 plugins/unistim
407                 plugins/wimax
408                 plugins/wimaxasncp
409         )
410 # It seems this stuff doesn't build with autofoo either...
411 #       if(YAPP_FOUND)
412 #               set(PLUGIN_SRC_DIRS
413 #                       ${PLUGIN_SRC_DIRS}
414 #                       plugins/tpg
415 #               )
416 #       endif()
417 else()
418         set(PLUGIN_SRC_DIRS )
419 endif()
420
421 foreach(PLUGIN_DIR ${PLUGIN_SRC_DIRS})
422         add_subdirectory( ${PLUGIN_DIR} )
423 endforeach()
424
425 add_subdirectory( codecs )
426 add_subdirectory( epan )
427 add_subdirectory( tools/lemon )
428 add_subdirectory( wiretap )
429 add_subdirectory( wsutil )
430
431 if(BUILD_wireshark AND GTK_FOUND)
432         add_subdirectory( gtk )
433         if (ENABLE_UI_MANAGER)
434                 set(MAIN_MENU_USE_UIMANAGER 1)
435         endif()
436 endif()
437
438 # Basedir where to install guides
439 set(DOC_DIR "$ENV{docdir}")
440 message(STATUS "docdir: ${DOC_DIR}")
441
442 if(ENABLE_GUIDES)
443         add_subdirectory( docbook )
444 endif()
445
446 if(ENABLE_PCAP_NG_DEFAULT)
447         set(PCAP_NG_DEFAULT 1)
448 endif()
449
450 if(ENABLE_THREADS)
451         set(USE_THREADS 1)
452 endif()
453
454 #Platform specific
455 if(UNIX)
456         set(WS_VAR_IMPORT "extern")
457 endif()
458
459 if(APPLE)
460 #TODO verify that APPLE implies HAVE_OS_X_FRAMEWORKS
461         set(HAVE_OS_X_FRAMEWORKS 1)
462         FIND_LIBRARY (APPLE_CORE_SERVICES_LIBRARY CoreServices)
463         FIND_LIBRARY (APPLE_COCOA_LIBRARY Cocoa)
464 endif()
465
466 if(WIN32)
467         add_definitions(-D_NEED_VAR_IMPORT_)
468         set(WS_VAR_IMPORT "__declspec(dllimport) extern")
469         set(WS_MSVC_NORETURN "__declspec(noreturn)")
470
471         # Disable deprecation
472         if(MSVC80 OR MSVC90)
473                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
474         endif()
475 else()
476         set(WS_MSVC_NORETURN " ")
477 endif()
478
479 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
480
481 include(FeatureSummary)
482 #SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ]
483 PRINT_ENABLED_FEATURES()
484 PRINT_DISABLED_FEATURES()
485
486 link_directories(
487         ${CMAKE_BINARY_DIR}/gtk
488         ${CMAKE_BINARY_DIR}/codecs
489         ${CMAKE_BINARY_DIR}/epan
490         ${CMAKE_BINARY_DIR}/wiretap
491         ${CMAKE_BINARY_DIR}/wsutil
492 )
493
494 ADD_CUSTOM_TARGET(
495         svnversion ALL
496         COMMAND ${PERL}
497                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
498                 ${CMAKE_CURRENT_SOURCE_DIR}
499         DEPENDS
500                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
501 )
502
503 ADD_CUSTOM_COMMAND(
504         OUTPUT  svnversion.h
505         COMMAND ${PERL}
506                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
507                 ${CMAKE_CURRENT_SOURCE_DIR}
508         DEPENDS
509                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
510 )
511
512 register_tap_files(tshark-tap-register.c
513         ${TSHARK_TAP_SRC}
514 )
515
516 ADD_CUSTOM_COMMAND(
517         OUTPUT  ps.c
518         COMMAND ${PYTHON_EXECUTABLE}
519                 ${CMAKE_CURRENT_SOURCE_DIR}/tools/rdps.py
520                 ${CMAKE_CURRENT_SOURCE_DIR}/print.ps
521                 ps.c
522         DEPENDS
523                 ${CMAKE_CURRENT_SOURCE_DIR}/tools/rdps.py
524                 ${CMAKE_CURRENT_SOURCE_DIR}/print.ps
525 )
526
527 if(UNIX)
528         set(PLATFORM_SRC
529                 capture-pcap-util-unix.c
530         )
531 endif()
532
533 if(WIN32)
534         set(PLATFORM_SRC
535                 capture-wpcap.c capture_wpcap_packet.c
536         )
537 endif()
538
539 set(WTAP_PLUGIN_SOURCES
540         epan/plugins.c
541         epan/report_err.c
542         epan/filesystem.c
543 )
544
545 set(SHARK_COMMON_CAPTURE_SRC
546         capture_errs.c
547         capture_ifinfo.c
548         capture_ui_utils.c
549 )
550
551 set(WIRESHARK_COMMON_SRC
552         ${PLATFORM_SRC}
553         capture-pcap-util.c
554         cfile.c
555         clopts_common.c
556         disabled_protos.c
557         frame_data_sequence.c
558         packet-range.c
559         print.c
560         ps.c
561         svnversion.h
562         sync_pipe_write.c
563         timestats.c
564         util.c
565         tap-megaco-common.c
566         tap-rtp-common.c
567         version_info.c
568 )
569
570 set(TSHARK_TAP_SRC
571         tap-afpstat.c
572         tap-ansi_astat.c
573         tap-bootpstat.c
574         tap-camelcounter.c
575         tap-camelsrt.c
576         tap-comparestat.c
577         tap-dcerpcstat.c
578         tap-diameter-avp.c
579         tap-expert.c
580         tap-funnel.c
581         tap-gsm_astat.c
582         tap-h225counter.c
583         tap-h225rassrt.c
584         tap-hosts.c
585         tap-httpstat.c
586         tap-icmpstat.c
587         tap-icmpv6stat.c
588         tap-iostat.c
589         tap-iousers.c
590         tap-macltestat.c
591         tap-mgcpstat.c
592         tap-megacostat.c
593         tap-protocolinfo.c
594         tap-protohierstat.c
595         tap-radiusstat.c
596         tap-rlcltestat.c
597         tap-rpcstat.c
598         tap-rpcprogs.c
599         tap-rtp.c
600         tap-rtspstat.c
601         tap-scsistat.c
602         tap-sctpchunkstat.c
603         tap-sipstat.c
604         tap-smbsids.c
605         tap-smbstat.c
606         tap-stats_tree.c
607         tap-sv.c
608         tap-wspstat.c
609 )
610
611 set(INSTALL_DIRS
612         diameter
613         docbook
614         dtds
615         help
616         radius
617         tpncp
618         wimaxasncp
619 )
620
621 set(INSTALL_FILES
622         ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
623         COPYING
624         ${CMAKE_BINARY_DIR}/capinfos.html
625         cfilters
626         colorfilters
627         dfilters
628         ${CMAKE_BINARY_DIR}/dftest.html
629         ${CMAKE_BINARY_DIR}/dumpcap.html
630         ${CMAKE_BINARY_DIR}/editcap.html
631         ${CMAKE_BINARY_DIR}/idl2wrs.html
632         ipmap.html
633         manuf
634         ${CMAKE_BINARY_DIR}/mergecap.html
635         pdml2html.xsl
636         ${CMAKE_BINARY_DIR}/randpkt.html
637         ${CMAKE_BINARY_DIR}/rawshark.html
638         services
639         smi_modules
640         ${CMAKE_BINARY_DIR}/text2pcap.html
641         ${CMAKE_BINARY_DIR}/tshark.html
642         ${CMAKE_BINARY_DIR}/wireshark-filter.html
643         ${CMAKE_BINARY_DIR}/wireshark.html
644         docbook/ws.css
645 )
646
647 set(LIBEPAN_LIBS
648 #               @NSL_LIBS@      # -lnsl
649 #               @SOCKET_LIBS@   # -lsocket
650 #               @SSL_LIBS@      # -lcrypto
651                 epan
652 #               $(plugin_ldadd) # in case of static
653                 ${PCAP_LIBRARIES}
654                 ${CARES_LIBRARIES}
655                 ${ADNS_LIBRARIES}
656                 ${KERBEROS_LIBRARIES}
657                 ${LUA_LIBRARIES}
658                 ${PYTHON_LIBRARIES}
659                 ${GEOIP_LIBRARIES}
660                 ${GCRYPT_LIBRARIES}
661                 ${GNUTLS_LIBRARIES}
662                 ${SMI_LIBRARIES}
663                 ${ZLIB_LIBRARIES}
664                 ${M_LIBRARIES}
665 )
666
667 if(BUILD_wireshark AND GTK_FOUND)
668         set(wireshark_LIBS
669                 ui
670                 ${GTK2_LIBRARIES}
671                 ${GTK3_LIBRARIES}
672                 ${GTHREAD2_LIBRARIES}
673                 codecs
674                 ${PORTAUDIO_LIBRARIES}
675                 ${LIBEPAN_LIBS}
676                 ${APPLE_CORE_SERVICES_LIBRARY}
677                 ${APPLE_COCOA_LIBRARY}
678         )
679         set(wireshark_FILES
680                 airpcap_loader.c
681                 alert_box.c
682                 capture.c
683                 capture_info.c
684                 capture_opts.c
685                 capture_sync.c
686                 color_filters.c
687                 file.c
688                 fileset.c
689                 filters.c
690                 g711.c
691                 merge.c
692                 proto_hier_stats.c
693                 summary.c
694                 tempfile.c
695                 u3.c
696                 ${SHARK_COMMON_CAPTURE_SRC}
697                 ${WIRESHARK_COMMON_SRC}
698         )
699         add_executable(wireshark ${wireshark_FILES})
700         add_dependencies(wireshark svnversion)
701         set_target_properties(wireshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
702         target_link_libraries(wireshark ${wireshark_LIBS})
703         install(TARGETS wireshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
704 endif()
705
706 if(BUILD_tshark)
707         set(tshark_LIBS
708                 ${LIBEPAN_LIBS}
709                 ${APPLE_COCOA_LIBRARY}
710         )
711         set(tshark_FILES
712                 capture_opts.c
713                 capture_sync.c
714                 tempfile.c
715                 tshark-tap-register.c
716                 tshark.c
717                 ${TSHARK_TAP_SRC}
718                 ${SHARK_COMMON_CAPTURE_SRC}
719                 ${WIRESHARK_COMMON_SRC}
720         )
721         add_executable(tshark ${tshark_FILES})
722         add_dependencies(tshark svnversion)
723         set_target_properties(tshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
724         target_link_libraries(tshark ${tshark_LIBS})
725         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
726 endif()
727
728 if(BUILD_rawshark AND PCAP_FOUND)
729         set(rawshark_LIBS
730                 ${LIBEPAN_LIBS}
731                 ${APPLE_COCOA_LIBRARY}
732         )
733         set(rawshark_FILES
734                 ${WIRESHARK_COMMON_SRC}
735                 rawshark.c
736         )
737         add_executable(rawshark ${rawshark_FILES})
738         add_dependencies(rawshark svnversion)
739         set_target_properties(rawshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
740         target_link_libraries(rawshark ${rawshark_LIBS})
741         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
742 endif()
743
744 if(BUILD_dftest)
745         set(dftest_LIBS
746                 ${LIBEPAN_LIBS}
747         )
748         set(dftest_FILES
749                 dftest.c
750                 util.c
751         )
752         add_executable(dftest ${dftest_FILES})
753         set_target_properties(dftest PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
754         target_link_libraries(dftest ${dftest_LIBS})
755         install(TARGETS dftest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
756 endif()
757
758 if(BUILD_randpkt)
759         set(randpkt_LIBS
760                 wiretap
761                 ${M_LIBRARIES}
762                 ${PCAP_LIBRARIES}
763 #               @SOCKET_LIBS@
764 #               @NSL_LIBS@
765                 ${CARES_LIBRARIES}
766                 ${ADNS_LIBRARIES}
767                 ${ZLIB_LIBRARIES}
768         )
769         set(randpkt_FILES
770                 randpkt.c
771         )
772         add_executable(randpkt ${randpkt_FILES})
773         set_target_properties(randpkt PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
774         target_link_libraries(randpkt ${randpkt_LIBS})
775         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
776 endif()
777
778 if(BUILD_text2pcap)
779         set(text2pcap_LIBS
780                 wiretap
781                 ${M_LIBRARIES}
782                 ${ZLIB_LIBRARIES}
783         )
784         set(text2pcap_CLEAN_FILES
785                 text2pcap.c
786         )
787         set(text2pcap_FILES
788                 ${text2pcap_CLEAN_FILES}
789         )
790         add_lex_files(text2pcap_FILES
791                 text2pcap-scanner.l
792         )
793         add_executable(text2pcap ${text2pcap_FILES})
794         add_dependencies(text2pcap svnversion)
795         set_target_properties(text2pcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
796         target_link_libraries(text2pcap ${text2pcap_LIBS})
797         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
798 endif()
799
800 if(BUILD_mergecap)
801         set(mergecap_LIBS
802                 wiretap
803                 ${ZLIB_LIBRARIES}
804         )
805         set(mergecap_FILES
806                 mergecap.c
807                 merge.c
808                 svnversion.h
809         )
810         add_executable(mergecap ${mergecap_FILES})
811         add_dependencies(mergecap svnversion)
812         set_target_properties(mergecap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
813         target_link_libraries(mergecap ${mergecap_LIBS})
814         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
815 endif()
816
817 if(BUILD_capinfos)
818         set(capinfos_LIBS
819                 wiretap
820                 ${ZLIB_LIBRARIES}
821                 ${GCRYPT_LIBRARIES}
822                 ${APPLE_COCOA_LIBRARY}
823         )
824         set(capinfos_FILES
825                 capinfos.c
826                 ${WTAP_PLUGIN_SOURCES}
827         )
828         add_executable(capinfos ${capinfos_FILES})
829         add_dependencies(capinfos svnversion)
830         set_target_properties(capinfos PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
831         target_link_libraries(capinfos ${capinfos_LIBS})
832         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
833 endif()
834
835 if(BUILD_editcap)
836         set(editcap_LIBS
837                 wiretap
838                 ${ZLIB_LIBRARIES}
839         )
840         set(editcap_FILES
841                 editcap.c
842                 epan/crypt/crypt-md5.c
843                 epan/nstime.c
844                 ${WTAP_PLUGIN_SOURCES}
845         )
846         add_executable(editcap ${editcap_FILES})
847         add_dependencies(editcap svnversion)
848         set_target_properties(editcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
849         target_link_libraries(editcap ${editcap_LIBS})
850         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
851 endif()
852
853 if(BUILD_dumpcap AND PCAP_FOUND)
854         set(dumpcap_LIBS
855 #               @INET_NTOP_LO@
856                 wsutil
857                 ${PCAP_LIBRARIES}
858                 ${CAP_LIBRARIES}
859 #               @SOCKET_LIBS@
860 #               @NSL_LIBS@
861                 ${GLIB2_LIBRARIES}
862                 ${GTHREAD2_LIBRARIES}
863                 ${ZLIB_LIBRARIES}
864                 ${APPLE_COCOA_LIBRARY}
865         )
866         set(dumpcap_FILES
867                 svnversion.h
868                 capture_opts.c
869                 capture-pcap-util.c
870                 capture_stop_conditions.c
871                 clopts_common.c
872                 conditions.c
873                 dumpcap.c
874                 pcapio.c
875                 ringbuffer.c
876                 sync_pipe_write.c
877                 tempfile.c
878                 version_info.c
879                 ${PLATFORM_SRC}
880         )
881         add_executable(dumpcap ${dumpcap_FILES})
882         add_dependencies(dumpcap svnversion)
883         set_target_properties(dumpcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
884         target_link_libraries(dumpcap ${dumpcap_LIBS})
885         install(TARGETS dumpcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
886 endif()
887
888 ADD_CUSTOM_COMMAND(
889         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
890         COMMAND ${PERL}
891                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
892                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
893                 < ${CMAKE_SOURCE_DIR}/AUTHORS
894                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
895         DEPENDS
896                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
897                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
898                 ${CMAKE_SOURCE_DIR}/AUTHORS
899 )
900
901 ADD_CUSTOM_COMMAND(
902         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
903                 ${CMAKE_BINARY_DIR}/wireshark.pod
904         COMMAND ${PERL}
905                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
906                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
907                 < ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
908                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
909         COMMAND cat
910                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
911                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
912                 > ${CMAKE_BINARY_DIR}/wireshark.pod
913         DEPENDS
914                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
915                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
916                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
917                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
918 )
919
920 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
921 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dftest 1 )
922 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
923 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
924 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
925 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
926 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpkt 1 )
927 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
928 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
929 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
930 pod2manhtml( wireshark 1 )
931 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/wireshark-filter 4 )
932
933 add_custom_target(
934         auxiliary ALL
935         DEPENDS
936                 AUTHORS-SHORT
937                 capinfos.html
938                 dftest.html
939                 dumpcap.html
940                 editcap.html
941                 idl2wrs.html
942                 mergecap.html
943                 randpkt.html
944                 rawshark.html
945                 text2pcap.html
946                 tshark.html
947                 wireshark.html
948                 wireshark-filter.html
949 )
950
951 set(MAN1_FILES
952         ${CMAKE_BINARY_DIR}/capinfos.1
953         ${CMAKE_BINARY_DIR}/dftest.1
954         ${CMAKE_BINARY_DIR}/dumpcap.1
955         ${CMAKE_BINARY_DIR}/editcap.1
956         ${CMAKE_BINARY_DIR}/idl2wrs.1
957         ${CMAKE_BINARY_DIR}/mergecap.1
958         ${CMAKE_BINARY_DIR}/randpkt.1
959         ${CMAKE_BINARY_DIR}/rawshark.1
960         ${CMAKE_BINARY_DIR}/text2pcap.1
961         ${CMAKE_BINARY_DIR}/tshark.1
962         ${CMAKE_BINARY_DIR}/wireshark.1
963 )
964
965 set(MAN4_FILES
966         ${CMAKE_BINARY_DIR}/wireshark-filter.4
967 )
968
969 set(CLEAN_FILES
970         ${wireshark_FILES}
971         ${tshark_FILES}
972         ${rawshark_FILES}
973         ${dftest_FILES}
974         ${randpkt_FILES}
975         ${text2pcap_CLEAN_FILES}
976         ${mergecap_FILES}
977         ${capinfos_FILES}
978         ${editcap_FILES}
979         ${dumpcap_FILES}
980 )
981
982 if (WERROR)
983         set_source_files_properties(
984                 ${CLEAN_FILES}
985                 PROPERTIES
986                 COMPILE_FLAGS -Werror
987         )
988 endif()
989
990 install(
991         FILES
992                 ${INSTALL_FILES}
993         DESTINATION
994                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
995 )
996
997 install(
998         FILES
999                 ${MAN1_FILES}
1000         DESTINATION
1001                 ${CMAKE_INSTALL_MANDIR}/man1
1002 )
1003
1004 install(
1005         FILES
1006                 ${MAN4_FILES}
1007         DESTINATION
1008                 ${CMAKE_INSTALL_MANDIR}/man4
1009 )
1010
1011 install(
1012         DIRECTORY
1013                 ${INSTALL_DIRS}
1014         DIRECTORY_PERMISSIONS
1015                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
1016                 GROUP_EXECUTE GROUP_READ
1017                 WORLD_EXECUTE WORLD_READ
1018         DESTINATION
1019                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
1020         PATTERN ".svn" EXCLUDE
1021         PATTERN "Makefile.*" EXCLUDE
1022         PATTERN "faq.py" EXCLUDE
1023 )