771add6ac7fedaceaf27661cfddb50068d7f8841
[metze/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-funnel.c
580         tap-gsm_astat.c
581         tap-h225counter.c
582         tap-h225rassrt.c
583         tap-hosts.c
584         tap-httpstat.c
585         tap-icmpstat.c
586         tap-icmpv6stat.c
587         tap-iostat.c
588         tap-iousers.c
589         tap-macltestat.c
590         tap-mgcpstat.c
591         tap-megacostat.c
592         tap-protocolinfo.c
593         tap-protohierstat.c
594         tap-radiusstat.c
595         tap-rlcltestat.c
596         tap-rpcstat.c
597         tap-rpcprogs.c
598         tap-rtp.c
599         tap-rtspstat.c
600         tap-scsistat.c
601         tap-sctpchunkstat.c
602         tap-sipstat.c
603         tap-smbsids.c
604         tap-smbstat.c
605         tap-stats_tree.c
606         tap-sv.c
607         tap-wspstat.c
608 )
609
610 set(INSTALL_DIRS
611         diameter
612         docbook
613         dtds
614         help
615         radius
616         tpncp
617         wimaxasncp
618 )
619
620 set(INSTALL_FILES
621         ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
622         COPYING
623         ${CMAKE_BINARY_DIR}/capinfos.html
624         cfilters
625         colorfilters
626         dfilters
627         ${CMAKE_BINARY_DIR}/dftest.html
628         ${CMAKE_BINARY_DIR}/dumpcap.html
629         ${CMAKE_BINARY_DIR}/editcap.html
630         ${CMAKE_BINARY_DIR}/idl2wrs.html
631         ipmap.html
632         manuf
633         ${CMAKE_BINARY_DIR}/mergecap.html
634         pdml2html.xsl
635         ${CMAKE_BINARY_DIR}/randpkt.html
636         ${CMAKE_BINARY_DIR}/rawshark.html
637         services
638         smi_modules
639         ${CMAKE_BINARY_DIR}/text2pcap.html
640         ${CMAKE_BINARY_DIR}/tshark.html
641         ${CMAKE_BINARY_DIR}/wireshark-filter.html
642         ${CMAKE_BINARY_DIR}/wireshark.html
643         docbook/ws.css
644 )
645
646 set(LIBEPAN_LIBS
647 #               @NSL_LIBS@      # -lnsl
648 #               @SOCKET_LIBS@   # -lsocket
649 #               @SSL_LIBS@      # -lcrypto
650                 epan
651 #               $(plugin_ldadd) # in case of static
652                 ${PCAP_LIBRARIES}
653                 ${CARES_LIBRARIES}
654                 ${ADNS_LIBRARIES}
655                 ${KERBEROS_LIBRARIES}
656                 ${LUA_LIBRARIES}
657                 ${PYTHON_LIBRARIES}
658                 ${GEOIP_LIBRARIES}
659                 ${GCRYPT_LIBRARIES}
660                 ${GNUTLS_LIBRARIES}
661                 ${SMI_LIBRARIES}
662                 ${ZLIB_LIBRARIES}
663                 ${M_LIBRARIES}
664 )
665
666 if(BUILD_wireshark AND GTK_FOUND)
667         set(wireshark_LIBS
668                 ui
669                 ${GTK2_LIBRARIES}
670                 ${GTK3_LIBRARIES}
671                 ${GTHREAD2_LIBRARIES}
672                 codecs
673                 ${PORTAUDIO_LIBRARIES}
674                 ${LIBEPAN_LIBS}
675                 ${APPLE_CORE_SERVICES_LIBRARY}
676                 ${APPLE_COCOA_LIBRARY}
677         )
678         set(wireshark_FILES
679                 airpcap_loader.c
680                 alert_box.c
681                 capture.c
682                 capture_info.c
683                 capture_opts.c
684                 capture_sync.c
685                 color_filters.c
686                 file.c
687                 fileset.c
688                 filters.c
689                 g711.c
690                 merge.c
691                 proto_hier_stats.c
692                 summary.c
693                 tempfile.c
694                 u3.c
695                 ${SHARK_COMMON_CAPTURE_SRC}
696                 ${WIRESHARK_COMMON_SRC}
697         )
698         add_executable(wireshark ${wireshark_FILES})
699         add_dependencies(wireshark svnversion)
700         set_target_properties(wireshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
701         target_link_libraries(wireshark ${wireshark_LIBS})
702         install(TARGETS wireshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
703 endif()
704
705 if(BUILD_tshark)
706         set(tshark_LIBS
707                 ${LIBEPAN_LIBS}
708                 ${APPLE_COCOA_LIBRARY}
709         )
710         set(tshark_FILES
711                 capture_opts.c
712                 capture_sync.c
713                 tempfile.c
714                 tshark-tap-register.c
715                 tshark.c
716                 ${TSHARK_TAP_SRC}
717                 ${SHARK_COMMON_CAPTURE_SRC}
718                 ${WIRESHARK_COMMON_SRC}
719         )
720         add_executable(tshark ${tshark_FILES})
721         add_dependencies(tshark svnversion)
722         set_target_properties(tshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
723         target_link_libraries(tshark ${tshark_LIBS})
724         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
725 endif()
726
727 if(BUILD_rawshark AND PCAP_FOUND)
728         set(rawshark_LIBS
729                 ${LIBEPAN_LIBS}
730                 ${APPLE_COCOA_LIBRARY}
731         )
732         set(rawshark_FILES
733                 ${WIRESHARK_COMMON_SRC}
734                 rawshark.c
735         )
736         add_executable(rawshark ${rawshark_FILES})
737         add_dependencies(rawshark svnversion)
738         set_target_properties(rawshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
739         target_link_libraries(rawshark ${rawshark_LIBS})
740         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
741 endif()
742
743 if(BUILD_dftest)
744         set(dftest_LIBS
745                 ${LIBEPAN_LIBS}
746         )
747         set(dftest_FILES
748                 dftest.c
749                 util.c
750         )
751         add_executable(dftest ${dftest_FILES})
752         set_target_properties(dftest PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
753         target_link_libraries(dftest ${dftest_LIBS})
754         install(TARGETS dftest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
755 endif()
756
757 if(BUILD_randpkt)
758         set(randpkt_LIBS
759                 wiretap
760                 ${M_LIBRARIES}
761                 ${PCAP_LIBRARIES}
762 #               @SOCKET_LIBS@
763 #               @NSL_LIBS@
764                 ${CARES_LIBRARIES}
765                 ${ADNS_LIBRARIES}
766                 ${ZLIB_LIBRARIES}
767         )
768         set(randpkt_FILES
769                 randpkt.c
770         )
771         add_executable(randpkt ${randpkt_FILES})
772         set_target_properties(randpkt PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
773         target_link_libraries(randpkt ${randpkt_LIBS})
774         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
775 endif()
776
777 if(BUILD_text2pcap)
778         set(text2pcap_LIBS
779                 wiretap
780                 ${M_LIBRARIES}
781                 ${ZLIB_LIBRARIES}
782         )
783         set(text2pcap_CLEAN_FILES
784                 text2pcap.c
785         )
786         set(text2pcap_FILES
787                 ${text2pcap_CLEAN_FILES}
788         )
789         add_lex_files(text2pcap_FILES
790                 text2pcap-scanner.l
791         )
792         add_executable(text2pcap ${text2pcap_FILES})
793         add_dependencies(text2pcap svnversion)
794         set_target_properties(text2pcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
795         target_link_libraries(text2pcap ${text2pcap_LIBS})
796         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
797 endif()
798
799 if(BUILD_mergecap)
800         set(mergecap_LIBS
801                 wiretap
802                 ${ZLIB_LIBRARIES}
803         )
804         set(mergecap_FILES
805                 mergecap.c
806                 merge.c
807                 svnversion.h
808         )
809         add_executable(mergecap ${mergecap_FILES})
810         add_dependencies(mergecap svnversion)
811         set_target_properties(mergecap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
812         target_link_libraries(mergecap ${mergecap_LIBS})
813         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
814 endif()
815
816 if(BUILD_capinfos)
817         set(capinfos_LIBS
818                 wiretap
819                 ${ZLIB_LIBRARIES}
820                 ${GCRYPT_LIBRARIES}
821                 ${APPLE_COCOA_LIBRARY}
822         )
823         set(capinfos_FILES
824                 capinfos.c
825                 ${WTAP_PLUGIN_SOURCES}
826         )
827         add_executable(capinfos ${capinfos_FILES})
828         add_dependencies(capinfos svnversion)
829         set_target_properties(capinfos PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
830         target_link_libraries(capinfos ${capinfos_LIBS})
831         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
832 endif()
833
834 if(BUILD_editcap)
835         set(editcap_LIBS
836                 wiretap
837                 ${ZLIB_LIBRARIES}
838         )
839         set(editcap_FILES
840                 editcap.c
841                 epan/crypt/crypt-md5.c
842                 epan/nstime.c
843                 ${WTAP_PLUGIN_SOURCES}
844         )
845         add_executable(editcap ${editcap_FILES})
846         add_dependencies(editcap svnversion)
847         set_target_properties(editcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
848         target_link_libraries(editcap ${editcap_LIBS})
849         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
850 endif()
851
852 if(BUILD_dumpcap AND PCAP_FOUND)
853         set(dumpcap_LIBS
854 #               @INET_NTOP_LO@
855                 wsutil
856                 ${PCAP_LIBRARIES}
857                 ${CAP_LIBRARIES}
858 #               @SOCKET_LIBS@
859 #               @NSL_LIBS@
860                 ${GLIB2_LIBRARIES}
861                 ${GTHREAD2_LIBRARIES}
862                 ${ZLIB_LIBRARIES}
863                 ${APPLE_COCOA_LIBRARY}
864         )
865         set(dumpcap_FILES
866                 svnversion.h
867                 capture_opts.c
868                 capture-pcap-util.c
869                 capture_stop_conditions.c
870                 clopts_common.c
871                 conditions.c
872                 dumpcap.c
873                 pcapio.c
874                 ringbuffer.c
875                 sync_pipe_write.c
876                 tempfile.c
877                 version_info.c
878                 ${PLATFORM_SRC}
879         )
880         add_executable(dumpcap ${dumpcap_FILES})
881         add_dependencies(dumpcap svnversion)
882         set_target_properties(dumpcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
883         target_link_libraries(dumpcap ${dumpcap_LIBS})
884         install(TARGETS dumpcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
885 endif()
886
887 ADD_CUSTOM_COMMAND(
888         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
889         COMMAND ${PERL}
890                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
891                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
892                 < ${CMAKE_SOURCE_DIR}/AUTHORS
893                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
894         DEPENDS
895                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
896                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
897                 ${CMAKE_SOURCE_DIR}/AUTHORS
898 )
899
900 ADD_CUSTOM_COMMAND(
901         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
902                 ${CMAKE_BINARY_DIR}/wireshark.pod
903         COMMAND ${PERL}
904                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
905                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
906                 < ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
907                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
908         COMMAND cat
909                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
910                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
911                 > ${CMAKE_BINARY_DIR}/wireshark.pod
912         DEPENDS
913                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
914                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
915                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
916                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
917 )
918
919 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
920 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dftest 1 )
921 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
922 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
923 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
924 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
925 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpkt 1 )
926 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
927 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
928 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
929 pod2manhtml( wireshark 1 )
930 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/wireshark-filter 4 )
931
932 add_custom_target(
933         auxiliary ALL
934         DEPENDS
935                 AUTHORS-SHORT
936                 capinfos.html
937                 dftest.html
938                 dumpcap.html
939                 editcap.html
940                 idl2wrs.html
941                 mergecap.html
942                 randpkt.html
943                 rawshark.html
944                 text2pcap.html
945                 tshark.html
946                 wireshark.html
947                 wireshark-filter.html
948 )
949
950 set(MAN1_FILES
951         ${CMAKE_BINARY_DIR}/capinfos.1
952         ${CMAKE_BINARY_DIR}/dftest.1
953         ${CMAKE_BINARY_DIR}/dumpcap.1
954         ${CMAKE_BINARY_DIR}/editcap.1
955         ${CMAKE_BINARY_DIR}/idl2wrs.1
956         ${CMAKE_BINARY_DIR}/mergecap.1
957         ${CMAKE_BINARY_DIR}/randpkt.1
958         ${CMAKE_BINARY_DIR}/rawshark.1
959         ${CMAKE_BINARY_DIR}/text2pcap.1
960         ${CMAKE_BINARY_DIR}/tshark.1
961         ${CMAKE_BINARY_DIR}/wireshark.1
962 )
963
964 set(MAN4_FILES
965         ${CMAKE_BINARY_DIR}/wireshark-filter.4
966 )
967
968 set(CLEAN_FILES
969         ${wireshark_FILES}
970         ${tshark_FILES}
971         ${rawshark_FILES}
972         ${dftest_FILES}
973         ${randpkt_FILES}
974         ${text2pcap_CLEAN_FILES}
975         ${mergecap_FILES}
976         ${capinfos_FILES}
977         ${editcap_FILES}
978         ${dumpcap_FILES}
979 )
980
981 if (WERROR)
982         set_source_files_properties(
983                 ${CLEAN_FILES}
984                 PROPERTIES
985                 COMPILE_FLAGS -Werror
986         )
987 endif()
988
989 install(
990         FILES
991                 ${INSTALL_FILES}
992         DESTINATION
993                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
994 )
995
996 install(
997         FILES
998                 ${MAN1_FILES}
999         DESTINATION
1000                 ${CMAKE_INSTALL_MANDIR}/man1
1001 )
1002
1003 install(
1004         FILES
1005                 ${MAN4_FILES}
1006         DESTINATION
1007                 ${CMAKE_INSTALL_MANDIR}/man4
1008 )
1009
1010 install(
1011         DIRECTORY
1012                 ${INSTALL_DIRS}
1013         DIRECTORY_PERMISSIONS
1014                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
1015                 GROUP_EXECUTE GROUP_READ
1016                 WORLD_EXECUTE WORLD_READ
1017         DESTINATION
1018                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
1019         PATTERN ".svn" EXCLUDE
1020         PATTERN "Makefile.*" EXCLUDE
1021         PATTERN "faq.py" EXCLUDE
1022 )