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