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