Replace "svn" with "git" all over the place.
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #
23
24 project(Wireshark C CXX)
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 # Policy since 2.6.1
31 cmake_policy(SET CMP0008 NEW)
32 # Policy since 2.6.3
33 # Backward compatibility for versions < 2.6.3
34 cmake_policy(SET CMP0011 OLD)
35 # Policy since 2.8.1
36 #cmake_policy(SET CMP0015 NEW)
37 # Policy since 2.8.11
38 if( ${CMAKE_MAJOR_VERSION} GREATER 2 OR ${CMAKE_MINOR_VERSION} GREATER 8 OR
39         (${CMAKE_MINOR_VERSION} EQUAL 8 AND ${CMAKE_PATCH_VERSION} GREATER 10) )
40         # Don't: Automatically link Qt executable to qtmain target on Windows
41         cmake_policy(SET CMP0020 OLD)
42 endif()
43
44 # This cannot be implemented via option(...)
45 if( NOT CMAKE_BUILD_TYPE )
46         set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
47                 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
48                 FORCE)
49 endif()
50 message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
51 message(STATUS "${CMAKE_BUILD_TYPE}: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
52
53 # set(PROJECT_MAJOR_VERSION 1)
54 # set(PROJECT_MINOR_VERSION 9)
55 # set(PROJECT_PATCH_VERSION 0)
56 # set(PROJECT_VERSION_EXTENSION "-rc5")
57 # If not set, copy over Wireshark version from configure.ac
58 if(NOT PROJECT_MAJOR_VERSION)
59         file(STRINGS
60                 ${CMAKE_SOURCE_DIR}/configure.ac
61                 PROJECT_MAJOR_VERSION_TMP
62                 REGEX "^m4_define\\(\\[?version_major\\]?, *\\[?[0-9]+\\]?\\)"
63         )
64         file(STRINGS
65                 ${CMAKE_SOURCE_DIR}/configure.ac
66                 PROJECT_MINOR_VERSION_TMP
67                 REGEX "^m4_define\\(\\[?version_minor\\]?, *\\[?[0-9]+\\]?\\)"
68         )
69         file(STRINGS
70                 ${CMAKE_SOURCE_DIR}/configure.ac
71                 PROJECT_PATCH_VERSION_TMP
72                 REGEX "^m4_define\\(\\[?version_micro\\]?, *\\[?[0-9]+\\]?\\)"
73         )
74         # XXX pull VERSION_EXTENSION out of configure.ac ?
75
76         string(REGEX REPLACE "m4_define\\(\\[?version_major\\]?, *\\[?([0-9]+)\\]?\\)"
77                 "\\1"
78                 PROJECT_MAJOR_VERSION
79                 ${PROJECT_MAJOR_VERSION_TMP}
80         )
81         string(REGEX REPLACE "m4_define\\(\\[?version_minor\\]?, *\\[?([0-9]+)\\]?\\)"
82                 "\\1"
83                 PROJECT_MINOR_VERSION
84                 ${PROJECT_MINOR_VERSION_TMP}
85         )
86         string(REGEX REPLACE "m4_define\\(\\[?version_micro\\]?, *\\[?([0-9]+)\\]?\\)"
87                 "\\1"
88                 PROJECT_PATCH_VERSION
89                 ${PROJECT_PATCH_VERSION_TMP}
90         )
91 endif()
92
93
94 if(PROJECT_VERSION_EXTENSION)
95         set(PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION})
96 else()
97         set(PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION})
98 endif()
99
100 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
101
102 #Where to find local cmake scripts
103 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
104 include(UseLemon)
105 include(UseMakeDissectorReg)
106 include(UseMakeTapReg)
107 include(UseAsn2Wrs)
108
109 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
110
111 # Enable with: "make VERBOSE=1"
112 set(CMAKE_VERBOSE_MAKEFILE OFF)
113
114 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
115 include(CMakeInstallDirs)
116
117 include_directories(
118         ${CMAKE_BINARY_DIR}
119         ${CMAKE_SOURCE_DIR}
120         ${CMAKE_SOURCE_DIR}/epan
121         ${CMAKE_SOURCE_DIR}/filetap
122         ${CMAKE_SOURCE_DIR}/tools/lemon
123         ${CMAKE_SOURCE_DIR}/wiretap
124 )
125
126 #Where to put executables and libraries in the build tree
127 if(NOT ARCHIVE_OUTPUT_PATH)
128         set(ARCHIVE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
129                    "Single output directory for building all archives.")
130 endif()
131 if(NOT EXECUTABLE_OUTPUT_PATH)
132         set(EXECUTABLE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
133                    "Single output directory for building all executables.")
134 endif()
135 if(NOT LIBRARY_OUTPUT_PATH)
136         set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
137                    "Single output directory for building all libraries.")
138 endif()
139
140 include( CMakeOptions.txt )
141 if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
142         set( DUMPCAP_SETUID "SETUID" )
143 else()
144         set( DUMPCAP_SETUID )
145 endif()
146 if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
147         DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
148         message( WARNING "Capabilities are only supported on Linux" )
149         set( DUMPCAP_INSTALL_OPTION )
150 endif()
151
152 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
153         if (MSVC10)
154                 set(MSC_VER_REQUIRED 1600)
155         elseif(MSVC11)
156                 set(MSC_VER_REQUIRED 1700)
157         elseif(MSVC12)
158                 set(MSC_VER_REQUIRED 1800)
159         else()
160                 message(FATAL_ERROR "You are using an unsupported version of MSVC")
161         endif()
162         set(LOCAL_CFLAGS
163                 /Zi
164                 /W3
165                 /MDd
166                 /DWIN32_LEAN_AND_MEAN
167                 "/DMSC_VER_REQUIRED=${MSC_VER_REQUIRED}"
168                 /D_CRT_SECURE_NO_DEPRECATE
169                 /D_CRT_NONSTDC_NO_DEPRECATE
170                 /MP
171                 # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
172                 # This avoids conflicts with the C++ standard library.
173                 /DNOMINMAX
174         )
175
176         if(NOT WIN64)
177                 set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/D_BIND_TO_CURRENT_CRT_VERSION=1")
178         endif()
179
180         # Additional compiler warnings to be treated as "Level 3"
181         #  when compiling Wireshark sources. (Selected from "level 4" warnings).
182         ## 4295: array is too small to include a terminating null character
183         set(WARNINGS_CFLAGS "/w34295")
184
185         # FIXME: WINPCAP_VERSION cannot be determined from source or executable.
186         set(WINPCAP_VERSION "unknown")
187         set(WIRESHARK_C_FLAGS
188                 "/DWINPCAP_VERSION=${WINPCAP_VERSION}"
189                 ${LOCAL_CFLAGS}
190                 ${WARNINGS_CFLAGS}
191         )
192 else()
193         set(WIRESHARK_C_FLAGS
194                 # -O<X> and -g get set by the CMAKE_BUILD_TYPE
195                 -Wall
196                 -W
197                 -Wextra
198                 -Wendif-labels
199                 -Wpointer-arith
200                 -Warray-bounds
201                 -Wformat-security
202                 -Wvla
203                 -Waddress
204                 -Wattributes
205                 -Wdiv-by-zero
206                 -Wignored-qualifiers
207                 -Wno-overlength-strings
208                 -Wwrite-strings
209                 -Wno-long-long
210                 -Wpragmas
211         )
212
213         set(WIRESHARK_C_ONLY_FLAGS
214                 # The following are C only, not C++
215                 -Wc++-compat
216                 -Wdeclaration-after-statement
217                 -Wshadow
218                 -Wno-pointer-sign
219                 -Wold-style-definition
220                 -Wstrict-prototypes
221                 -Wlogical-op
222                 -Wjump-misses-init
223                 # The Qt headers generate a ton of shortening errors on 64-bit systems
224                 # so only enable this for C for now.
225                 -Wshorten-64-to-32
226         )
227
228         set(WIRESHARK_CPP_ONLY_FLAGS
229         )
230
231         set(WIRESHARK_EXTRA_C_FLAGS
232                 -pedantic
233                 -Woverflow
234                 -fstrict-overflow -Wstrict-overflow=4
235                 -Wunreachable-code
236                 -Wunsafe-loop-optimizations
237                 -Wcast-align
238                 -Wcast-qual
239                 -Wformat-security
240                 -Wredundant-decls
241                 -Wheader-guard
242                 -fwrapv
243                 -fno-strict-overflow
244                 -fno-delete-null-pointer-checks
245                 # All the registration functions block these for now.
246                 -Wmissing-declarations
247         )
248
249         set(WIRESHARK_EXTRA_C_ONLY_FLAGS
250                 # The following are C only, not C++
251                 -Wbad-function-cast
252                 # All the registration functions block these for now.
253                 -Wmissing-prototypes
254         )
255
256         set(WIRESHARK_EXTRA_CPP_ONLY_FLAGS
257         )
258
259         # With clang some tests don't fail properly during testing but only
260         # during real compiles
261
262         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
263                 set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS}
264                         -Qunused-arguments
265                         #-fcolor-diagnostics
266         )
267         else()
268                 set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS}
269                         -fexcess-precision=fast
270                 )
271
272                 set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS}
273                 )
274         endif()
275
276         if(ENABLE_EXTRA_GCC_CHECKS)   # This overrides -Werror
277                 set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS} ${WIRESHARK_EXTRA_C_FLAGS})
278                 set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS} ${WIRESHARK_EXTRA_C_ONLY_FLAGS})
279                 set(WIRESHARK_CPP_ONLY_FLAGS ${WIRESHARK_CPP_ONLY_FLAGS} ${WIRESHARK_EXTRA_CPP_ONLY_FLAGS})
280         endif()
281
282         add_definitions(
283                 -DG_DISABLE_DEPRECATED
284                 -DG_DISABLE_SINGLE_INCLUDES
285         )
286 endif()
287
288 set( C_FLAG_TESTS ${WIRESHARK_C_FLAGS} ${WIRESHARK_C_ONLY_FLAGS} )
289 set( CPP_FLAG_TESTS ${WIRESHARK_C_FLAGS} ${WIRESHARK_CPP_ONLY_FLAGS} )
290
291 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
292 include(CheckCCompilerFlag)
293 include(CheckCXXCompilerFlag)
294
295 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_GCC_CHECKS)
296         check_c_compiler_flag(-Werror=unknown-warning-option WERR_UNKNOWN)
297         check_c_compiler_flag(-Werror WERROR)
298 else()
299         unset(WERR_UNKNOWN)
300         unset(WERROR)
301 endif()
302 # string of additional compile command line flags for check_c_compiler_flag
303 if(WERR_UNKNOWN)
304         set(CMAKE_REQUIRED_FLAGS -Werror=unknown-warning-option )
305 endif()
306
307 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
308 foreach(THIS_FLAG ${C_FLAG_TESTS})
309         string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
310         set(${F} ${THIS_FLAG})
311         set(V C_${F}_VALID)
312         message(STATUS "Checking for c-compiler flag: ${THIS_FLAG}")
313         check_c_compiler_flag(${${F}} ${V})
314         if (${${V}})
315                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${F}}")
316         endif()
317 endforeach()
318 foreach(THIS_FLAG ${CPP_FLAG_TESTS})
319         string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
320         set(${F} ${THIS_FLAG})
321         set(V CPP_${F}_VALID)
322         message(STATUS "Checking for c++-compiler flag: ${THIS_FLAG}")
323         check_cxx_compiler_flag(${${F}} ${V})
324         if (${${V}})
325                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${F}}")
326         endif()
327 endforeach()
328 message(STATUS "C-Flags: ${CMAKE_C_FLAGS}\nCXX-Flags: ${CMAKE_CXX_FLAGS}")
329
330 check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
331 if(FVHIDDEN)
332         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
333 else() # TODO add alternate compiler flags for hiding symbols
334         message(WARNING "Hiding shared library symbols is not supported by the compiler."
335                 " All shared library symbols will be exported.")
336 endif()
337
338 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
339         set (C_UNUSED "__attribute__((unused))" )
340 else()
341         set (C_UNUSED "" )
342 endif()
343
344
345 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
346         # Set in Makefile.nmake
347         set(WIRESHARK_LD_FLAGS
348                 /LARGEADDRESSAWARE
349         )
350 else()
351         set(WIRESHARK_LD_FLAGS
352                 -Wl,--as-needed
353                 # -flto
354                 # -fwhopr
355                 # -fwhole-program
356         )
357 endif()
358
359 include(CheckCLinkerFlag)
360 set(C 0)
361 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
362 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
363         set(F WS_LD_FLAG_${C})
364         set(${F} ${THIS_FLAG})
365         set(V WS_LD_FLAG_VALID${C})
366         check_c_linker_flag(${${F}} ${V})
367         if (${${V}})
368                 set(WS_LINK_FLAGS ${WS_LINK_FLAGS} ${${F}})
369         endif()
370         math(EXPR C "${C} + 1")
371 endforeach()
372
373 if(ENABLE_STATIC)
374   set(LINK_MODE_LIB STATIC)
375   set(LINK_MODE_MODULE STATIC)
376 else()
377   set(LINK_MODE_LIB SHARED)
378   set(LINK_MODE_MODULE MODULE)
379 endif()
380
381 if(APPLE AND EXISTS /usr/local/opt/gettext)
382         # GLib on OS X requires libintl. Homebrew installs gettext (and
383         # libintl) in /usr/local/opt/gettext
384         include_directories(/usr/local/opt/gettext/include)
385         link_directories(/usr/local/opt/gettext/lib)
386 endif()
387
388 # The packagelist is doing some magic:  If we add XXX to the packagelist, we
389 # - may optionally set XXX_OPTIONS to pass to the find_package command
390 # - will call FindXXX.cmake
391 # - return found libraries in XXX_LIBRARIES
392 # - return found include in XXX_INCLUDE_DIRS
393 # - set HAVE_XXX
394
395 #The minimum package list
396 set(PACKAGELIST Gettext GLIB2 GMODULE2 GTHREAD2 M LEX YACC Perl SED SH PythonInterp)
397 set(GLIB2_FIND_REQUIRED)
398 set(GLIB2_MIN_VERSION 2.14.0)
399 set(GTHREAD2_REQUIRED)
400 set(M_REQUIRED)
401 set(PythonInterp_FIND_VERSION 2)
402 set(Python_ADDITIONAL_VERSIONS 3)
403
404 set(PACKAGELIST ${PACKAGELIST} HtmlViewer)
405
406 if(ENABLE_PCAP)
407         set(PACKAGELIST ${PACKAGELIST} PCAP)
408 endif()
409
410 if(ENABLE_AIRPCAP)
411         set(PACKAGELIST ${PACKAGELIST} AIRPCAP)
412 endif()
413
414 # Build the GTK-GUI?
415 if(BUILD_wireshark)
416         if(ENABLE_GTK3)
417                 set(PACKAGELIST ${PACKAGELIST} GTK3)
418         else()
419                 set(PACKAGELIST ${PACKAGELIST} GTK2)
420                 set(GTK2_OPTIONS COMPONENTS gtk)
421                 set(GTK2_FIND_VERSION 2.12)
422                 set(GTK2_DEBUG false)
423         endif()
424 endif()
425
426 # Build the Qt GUI?
427 if(BUILD_qtshark)
428         if(ENABLE_QT5)
429                 set(PACKAGELIST ${PACKAGELIST} Qt5Widgets Qt5PrintSupport Qt5LinguistTools)
430                 if (APPLE)
431                         set(PACKAGELIST ${PACKAGELIST} Qt5MacExtras)
432                 endif()
433                 set(QT_VERSION 5)
434                 # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
435                 # somewhere. The if WIN32 in this place is annoying as well.
436                 if( WIN32 )
437                         set( QT5_BASE_PATH "$ENV{QT5_BASE_DIR}" )
438                         set( CMAKE_PREFIX_PATH "${QT5_BASE_PATH}" )
439                         # Used for the creation of setpath.bat
440                         set( QT5_DLL_PATH "${CMAKE_PREFIX_PATH}/bin/dummy" )
441                         set( WS_ALL_LIBS ${WS_ALL_LIBS} ${QT5_DLL_PATH} )
442                 endif()
443         else()
444                 set(PACKAGELIST ${PACKAGELIST} Qt4)
445                 # set(Qt4_OPTIONS 4.7.1 REQUIRED QtCore QtGui)
446                 set(QT_VERSION 4)
447         endif()
448 endif()
449
450 # SMI SNMP
451 if(ENABLE_SMI)
452         set(PACKAGELIST ${PACKAGELIST} SMI)
453 endif()
454
455 # GNU crypto
456 if(ENABLE_GCRYPT)
457         set(PACKAGELIST ${PACKAGELIST} GCRYPT)
458 endif()
459
460 # GNU SSL/TLS support
461 if(ENABLE_GNUTLS)
462         set(PACKAGELIST ${PACKAGELIST} GNUTLS)
463 endif()
464
465 # Kerberos
466 if(ENABLE_KERBEROS)
467         set(PACKAGELIST ${PACKAGELIST} KERBEROS)
468 endif()
469
470 # Portable audio
471 if(ENABLE_PORTAUDIO AND BUILD_wireshark)
472         set(PACKAGELIST ${PACKAGELIST} PORTAUDIO)
473 endif()
474
475
476 # Prefer c-ares over adns
477 if(ENABLE_CARES) # C Asynchronouse resolver
478         set(PACKAGELIST ${PACKAGELIST} CARES)
479 elseif(ENABLE_ADNS) # Gnu asynchronous DNS
480         set(PACKAGELIST ${PACKAGELIST} ADNS)
481 endif()
482
483 # Zlib compression
484 if(ENABLE_ZLIB)
485         set(PACKAGELIST ${PACKAGELIST} ZLIB)
486 endif()
487
488 # Lua 5.1 dissectors
489 if(ENABLE_LUA)
490         set(PACKAGELIST ${PACKAGELIST} LUA)
491 endif()
492
493 # GeoIP address resolving
494 if(ENABLE_GEOIP)
495         set(PACKAGELIST ${PACKAGELIST} GEOIP)
496 endif()
497
498 if(ENABLE_NETLINK)
499         set(PACKAGELIST ${PACKAGELIST} NL)
500 endif()
501
502 # Capabilities
503 if(ENABLE_CAP)
504         set(PACKAGELIST ${PACKAGELIST} CAP SETCAP)
505 endif()
506
507 if(ENABLE_PYTHON)
508         set(PACKAGELIST ${PACKAGELIST} PythonLibs)
509 endif()
510
511 set(PACKAGELIST ${PACKAGELIST} YAPP)
512
513 set(PACKAGELIST ${PACKAGELIST} POD)
514
515 if(ENABLE_GUIDES)
516         set(PACKAGELIST ${PACKAGELIST} DOXYGEN)
517 endif()
518
519 set(PROGLIST text2pcap mergecap capinfos captype editcap reordercap dumpcap)
520
521 #Sort the package list
522 list(SORT PACKAGELIST)
523 message(STATUS "Packagelist: ${PACKAGELIST}")
524 #Let's loop the package list
525 foreach(PACKAGE ${PACKAGELIST})
526         if(${PACKAGE} STREQUAL "Qt4")
527                 set(PACKAGE_VAR "QT")
528         elseif(${PACKAGE} STREQUAL "PythonInterp")
529                 set(PACKAGE_VAR "PYTHON")
530         elseif(${PACKAGE} STREQUAL "PythonLibs")
531                 set(PACKAGE_VAR "PYTHON")
532         else()
533                 set(PACKAGE_VAR ${PACKAGE})
534         endif()
535         if(${PACKAGE}_OPTIONS)
536                 find_package(${PACKAGE} ${${PACKAGE}_OPTIONS})
537         elseif(${PACKAGE}_REQUIRED)
538                 find_package(${PACKAGE} REQUIRED)
539         else()
540                 find_package(${PACKAGE})
541         endif()
542         message(${PACKAGE_VAR}_FOUND)
543         if (${PACKAGE_VAR}_FOUND)
544                 set(HAVE_LIB${PACKAGE_VAR} 1)
545                 include_directories(${${PACKAGE_VAR}_INCLUDE_DIRS})
546                 set(WS_ALL_LIBS ${WS_ALL_LIBS} ${${PACKAGE_VAR}_LIBRARIES})
547                 message(STATUS "${PACKAGE} includes: ${${PACKAGE_VAR}_INCLUDE_DIRS}")
548                 message(STATUS "${PACKAGE} libs: ${${PACKAGE_VAR}_LIBRARIES}")
549                 if (${PACKAGE}_DEFINITIONS)
550                         message(STATUS "${PACKAGE} definitions: ${${PACKAGE_VAR}_DEFINITIONS}")
551                 endif()
552                 if (${PACKAGE_VAR}_EXECUTABLE)
553                         message(STATUS "${PACKAGE} executable: ${${PACKAGE_VAR}_EXECUTABLE}")
554                 endif()
555         endif()
556 endforeach()
557
558 # Provide Windows system lib names
559 include( UseWinLibs )
560
561 # Create file to set paths to run binaries from build dir
562 WSExtendPath( "${WS_ALL_LIBS}" "${CMAKE_BINARY_DIR}/setpath.bat" )
563
564 #packaging
565 include(CPackConfig.txt)
566
567 if(HAVE_LIBPYTHON)
568         set(HAVE_PYTHON 1)
569         set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${CPACK_PACKAGE_VERSION}")
570 endif()
571 if(HAVE_LIBLUA)
572         set(HAVE_LUA_H 1)
573         set(HAVE_LUA 1)
574 endif()
575 if(HAVE_LIBKERBEROS)
576         set(HAVE_KERBEROS 1)
577         # HAVE_HEIMDAL_KERBEROS
578         set(HAVE_MIT_KERBEROS 1)
579         set(HAVE_KEYTYPE_ARCFOUR_56 1)
580 endif()
581 if(HAVE_LIBGEOIP)
582         set(HAVE_GEOIP 1)
583 endif()
584 if(HAVE_LIBCARES)
585         set(HAVE_C_ARES 1)
586 endif()
587 if(HAVE_LIBADNS)
588         set(HAVE_GNU_ADNS 1)
589 endif()
590 if(HAVE_LIBNL AND HAVE_AIRPCAP)
591         message(ERROR "Airpcap and Libnl support are mutually exclusive")
592 endif()
593 # No matter which version of GTK is present
594 if(GTK2_FOUND OR GTK3_FOUND)
595         set(GTK_FOUND ON)
596 endif()
597 # That's the name autofoo uses
598 if(HAVE_LIBZLIB)
599         set(HAVE_LIBZ 1)
600         # Always include the "true" zlib includes first. This works around a
601         # bug in the Windows setup of GTK[23] which has a faulty zconf.h.
602         include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
603 endif()
604 if (Qt5Widgets_FOUND)
605         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
606         if (Qt5_POSITION_INDEPENDENT_CODE)
607                 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
608         endif()
609         set (QT_FOUND ON)
610         set (QT_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES})
611         if(Qt5MacExtras_FOUND)
612                 set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MacExtras_LIBRARIES})
613                 # That's the name autofoo uses
614                 set(QT_MACEXTRAS_LIB 1)
615         endif()
616 # If Qt4: QT_LIBRARIES and QT_INCLUDES are not set above. They require extra magic
617 elseif(QT_FOUND)
618         include(${QT_USE_FILE})
619         include_directories(${QT_INCLUDE_DIR})
620         message(STATUS "QT includes: ${QT_INCLUDE_DIR}")
621         message(STATUS "QT libs: ${QT_LIBRARIES}")
622 endif()
623 include(ConfigureChecks.cmake)
624
625 #Big or little endian ?
626 include(TestBigEndian)
627 test_big_endian(WORDS_BIGENDIAN)
628
629 set(DATAFILE_DIR "${CMAKE_INSTALL_PREFIX}/share/${CPACK_PACKAGE_NAME}")
630
631 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
632
633 if(ENABLE_PLUGINS)
634         set(HAVE_PLUGINS 1)
635         set(PLUGIN_DIR="${DATAFILE_DIR}/plugins/${CPACK_PACKAGE_VERSION}")
636         set(PLUGIN_SRC_DIRS
637                 plugins/docsis
638                 plugins/ethercat
639                 plugins/gryphon
640                 plugins/irda
641                 plugins/m2m
642                 plugins/mate
643                 plugins/opcua
644                 plugins/profinet
645                 plugins/stats_tree
646                 plugins/unistim
647                 plugins/wimax
648                 plugins/wimaxasncp
649                 plugins/wimaxmacphy
650         )
651 # It seems this stuff doesn't build with autofoo either...
652 #       if(YAPP_FOUND)
653 #               set(PLUGIN_SRC_DIRS
654 #                       ${PLUGIN_SRC_DIRS}
655 #                       plugins/tpg
656 #               )
657 #       endif()
658 else()
659         set(PLUGIN_SRC_DIRS )
660 endif()
661
662 foreach(PLUGIN_DIR ${PLUGIN_SRC_DIRS})
663         add_subdirectory( ${PLUGIN_DIR} )
664 endforeach()
665
666 add_subdirectory( asn1 EXCLUDE_FROM_ALL )
667 add_subdirectory( codecs )
668 add_subdirectory( epan )
669 add_subdirectory( filetap )
670 add_subdirectory( tools/lemon )
671 add_subdirectory( ui )
672 add_subdirectory( wiretap )
673 add_subdirectory( wsutil )
674
675 add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libfiletap dumpabi-libwiretap dumpabi-libwsutil color.h)
676
677 if(ENABLE_ECHLD)
678         add_subdirectory( echld )
679 endif()
680
681 if(BUILD_wireshark AND GTK_FOUND)
682         add_subdirectory( ui/gtk )
683 endif()
684
685 if(BUILD_qtshark AND QT_FOUND)
686         add_subdirectory( ui/qt )
687 endif()
688
689
690 # Basedir where to install guides
691 set(DOC_DIR "$ENV{docdir}" CACHE FILEPATH "Installation directory for ug and dg pdfs.")
692 message(STATUS "docdir: ${DOC_DIR}")
693
694 if(ENABLE_GUIDES)
695         add_subdirectory( docbook )
696 endif()
697
698 if(ENABLE_PCAP_NG_DEFAULT)
699         set(PCAP_NG_DEFAULT 1)
700 endif()
701
702 # Large file support (e.g. make off_t 64 bit if supported)
703 include(gmxTestLargeFiles)
704 gmx_test_large_files(GMX_LARGEFILES)
705
706 add_definitions( -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\" )
707
708 if(APPLE)
709         #
710         # We assume that APPLE means OS X so that we have the OS X
711         # frameworks.
712         #
713         set(HAVE_OS_X_FRAMEWORKS 1)
714         FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
715         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
716         FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
717 endif()
718
719 if(WIN32)
720         set(WS_MSVC_NORETURN "__declspec(noreturn)")
721
722         # Disable deprecation
723         if(MSVC80 OR MSVC90)
724                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
725         endif()
726 else()
727         set(WS_MSVC_NORETURN " ")
728 endif()
729
730 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
731 if( ENABLE_GUIDES )
732         configure_file(
733                 ${CMAKE_SOURCE_DIR}/doxygen_global.cfg
734                 ${CMAKE_BINARY_DIR}/doxygen_global.cfg
735         )
736         configure_file(
737                 ${CMAKE_SOURCE_DIR}/ui/qt/doxygen.cfg.in
738                 ${CMAKE_BINARY_DIR}/ui/qt/doxygen.cfg
739         )
740         configure_file(
741                 ${CMAKE_SOURCE_DIR}/ui/gtk/doxygen.cfg.in
742                 ${CMAKE_BINARY_DIR}/ui/gtk/doxygen.cfg
743         )
744         configure_file(
745                 ${CMAKE_SOURCE_DIR}/ui/doxygen.cfg.in
746                 ${CMAKE_BINARY_DIR}/ui/doxygen.cfg
747         )
748         configure_file(
749                 ${CMAKE_SOURCE_DIR}/epan/doxygen.cfg.in
750                 ${CMAKE_BINARY_DIR}/epan/doxygen.cfg
751         )
752         configure_file(
753                 ${CMAKE_SOURCE_DIR}/doxygen.cfg.in
754                 ${CMAKE_BINARY_DIR}/doxygen.cfg
755         )
756 endif()
757
758 set( configure_input "Built with CMake ${CMAKE_VERSION}" )
759 set( VERSION ${PROJECT_VERSION} )
760
761 configure_file(
762         ${CMAKE_SOURCE_DIR}/packaging/macosx/Info.plist.in
763         ${CMAKE_BINARY_DIR}/packaging/macosx/Info.plist
764         @ONLY)
765
766 include(FeatureSummary)
767 #SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ]
768 #FEATURE_SUMMARY(WHAT ALL) Requires removal of our local copy of FeatureSummary
769 PRINT_ENABLED_FEATURES()
770 PRINT_DISABLED_FEATURES()
771
772 link_directories(
773         ${CMAKE_BINARY_DIR}/ui
774         ${CMAKE_BINARY_DIR}/ui/gtk
775         ${CMAKE_BINARY_DIR}/ui/qt
776         ${CMAKE_BINARY_DIR}/codecs
777         ${CMAKE_BINARY_DIR}/epan
778         ${CMAKE_BINARY_DIR}/filetap
779         ${CMAKE_BINARY_DIR}/wiretap
780         ${CMAKE_BINARY_DIR}/wsutil
781 )
782
783 ADD_CUSTOM_TARGET(
784         gitversion ALL
785         COMMAND ${PERL_EXECUTABLE}
786                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
787                 ${CMAKE_CURRENT_SOURCE_DIR}
788         DEPENDS
789                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
790 )
791 set_target_properties(gitversion PROPERTIES FOLDER "Auxiliary")
792
793 ADD_CUSTOM_COMMAND(
794         OUTPUT  version.h
795         COMMAND ${PERL_EXECUTABLE}
796                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
797                 ${CMAKE_CURRENT_SOURCE_DIR}
798         DEPENDS
799                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
800 )
801
802 if(UNIX)
803         set(PLATFORM_PCAP_SRC
804                 capture-pcap-util-unix.c
805         )
806 endif()
807
808 if(WIN32)
809         set(PLATFORM_PCAP_SRC
810                 capture_win_ifnames.c
811                 capture-wpcap.c
812                 capture_wpcap_packet.c
813         )
814         set(PLATFORM_UI_SRC
815                 ui/win32/console_win32.c
816                 ui/win32/file_dlg_win32.c
817                 ui/win32/print_win32.c
818         )
819 endif()
820
821 # sources common for wireshark, tshark, and rawshark
822 set(SHARK_COMMON_SRC
823         ${PLATFORM_PCAP_SRC}
824         capture-pcap-util.c
825         cfile.c
826         cfutils.c
827         clopts_common.c
828         frame_tvbuff.c
829         version.h
830         sync_pipe_write.c
831         version_info.c
832 )
833
834 # sources common for wireshark and tshark, but not rawshark;
835 # these are for programs that capture traffic by running dumpcap
836 set(SHARK_COMMON_CAPTURE_SRC
837         capture_ifinfo.c
838         capture_sync.c
839         capture_ui_utils.c
840 )
841
842 set(TSHARK_TAP_SRC
843         ui/cli/tap-afpstat.c
844         ui/cli/tap-ansi_astat.c
845         ui/cli/tap-bootpstat.c
846         ui/cli/tap-camelcounter.c
847         ui/cli/tap-camelsrt.c
848         ui/cli/tap-comparestat.c
849         ui/cli/tap-dcerpcstat.c
850         ui/cli/tap-diameter-avp.c
851         ui/cli/tap-expert.c
852         ui/cli/tap-follow.c
853         ui/cli/tap-funnel.c
854         ui/cli/tap-gsm_astat.c
855         ui/cli/tap-h225counter.c
856         ui/cli/tap-h225rassrt.c
857         ui/cli/tap-hosts.c
858         ui/cli/tap-httpstat.c
859         ui/cli/tap-icmpstat.c
860         ui/cli/tap-icmpv6stat.c
861         ui/cli/tap-iostat.c
862         ui/cli/tap-iousers.c
863         ui/cli/tap-macltestat.c
864         ui/cli/tap-mgcpstat.c
865         ui/cli/tap-megacostat.c
866         ui/cli/tap-protocolinfo.c
867         ui/cli/tap-protohierstat.c
868         ui/cli/tap-radiusstat.c
869         ui/cli/tap-rlcltestat.c
870         ui/cli/tap-rpcstat.c
871         ui/cli/tap-rpcprogs.c
872         ui/cli/tap-rtp.c
873         ui/cli/tap-rtspstat.c
874         ui/cli/tap-scsistat.c
875         ui/cli/tap-sctpchunkstat.c
876         ui/cli/tap-sipstat.c
877         ui/cli/tap-smbsids.c
878         ui/cli/tap-smbstat.c
879         ui/cli/tap-stats_tree.c
880         ui/cli/tap-sv.c
881         ui/cli/tap-wspstat.c
882 )
883
884 set(INSTALL_DIRS
885         diameter
886         dtds
887         help
888         radius
889         tpncp
890         wimaxasncp
891 )
892
893 set(INSTALL_FILES
894         ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
895         COPYING
896         ${CMAKE_BINARY_DIR}/capinfos.html
897         ${CMAKE_BINARY_DIR}/captype.html
898         cfilters
899         colorfilters
900         dfilters
901         ${CMAKE_BINARY_DIR}/dftest.html
902         ${CMAKE_BINARY_DIR}/dumpcap.html
903         ${CMAKE_BINARY_DIR}/editcap.html
904         ${CMAKE_BINARY_DIR}/asn2deb.html
905         ${CMAKE_BINARY_DIR}/idl2deb.html
906         ${CMAKE_BINARY_DIR}/idl2wrs.html
907         ipmap.html
908         manuf
909         ${CMAKE_BINARY_DIR}/mergecap.html
910         pdml2html.xsl
911         ${CMAKE_BINARY_DIR}/randpkt.html
912         ${CMAKE_BINARY_DIR}/rawshark.html
913         ${CMAKE_BINARY_DIR}/reordercap.html
914         services
915         smi_modules
916         ${CMAKE_BINARY_DIR}/text2pcap.html
917         ${CMAKE_BINARY_DIR}/tshark.html
918         ${CMAKE_BINARY_DIR}/wireshark-filter.html
919         ${CMAKE_BINARY_DIR}/wireshark.html
920         docbook/ws.css
921 )
922
923 set(LIBEPAN_LIBS
924 #               @NSL_LIBS@      # -lnsl
925 #               @SOCKET_LIBS@   # -lsocket
926 #               @SSL_LIBS@      # -lcrypto
927                 epan
928 #               $(plugin_ldadd) # in case of static
929                 ${AIRPCAP_LIBRARIES}
930                 ${PCAP_LIBRARIES}
931                 ${CARES_LIBRARIES}
932                 ${ADNS_LIBRARIES}
933                 ${KERBEROS_LIBRARIES}
934                 ${LUA_LIBRARIES}
935                 ${PYTHON_LIBRARIES}
936                 ${GEOIP_LIBRARIES}
937                 ${GCRYPT_LIBRARIES}
938                 ${GNUTLS_LIBRARIES}
939                 ${SMI_LIBRARIES}
940                 ${ZLIB_LIBRARIES}
941                 ${M_LIBRARIES}
942 )
943
944 if( (BUILD_wireshark AND GTK_FOUND) OR (BUILD_qtshark AND QT_FOUND) )
945         set(wireshark_FILES
946                 airpcap_loader.c
947                 capture.c
948                 capture_info.c
949                 capture_opts.c
950                 color_filters.c
951                 file.c
952                 fileset.c
953                 filters.c
954                 iface_monitor.c
955                 proto_hier_stats.c
956                 summary.c
957                 ws80211_utils.c
958                 ${SHARK_COMMON_CAPTURE_SRC}
959                 ${SHARK_COMMON_SRC}
960                 ${PLATFORM_UI_SRC}
961         )
962 endif()
963
964 if(BUILD_wireshark AND GTK_FOUND)
965         set(wireshark_LIBS
966                 gtkui
967                 ui
968                 ${GTK2_LIBRARIES}
969                 ${GTK3_LIBRARIES}
970                 ${GTHREAD2_LIBRARIES}
971                 codecs
972                 ${PORTAUDIO_LIBRARIES}
973                 ${LIBEPAN_LIBS}
974                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
975                 ${APPLE_CORE_SERVICES_LIBRARY}
976                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
977                 ${NL_LIBRARIES}
978                 ${WIN_COMCTL32_LIBRARY}
979         )
980         # qtshark and wireshark share wireshark_FILES
981
982         add_executable(wireshark ${wireshark_FILES})
983         add_dependencies(wireshark gitversion)
984         set_target_properties(wireshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
985         set_target_properties(wireshark PROPERTIES FOLDER "Executables")
986         target_link_libraries(wireshark ${wireshark_LIBS})
987         install(TARGETS wireshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
988 endif()
989
990 if(BUILD_qtshark AND QT_FOUND)
991         set(qtshark_LIBS
992                 qtui
993                 ui
994                 ${QT_LIBRARIES}
995                 ${GTHREAD2_LIBRARIES}
996                 codecs
997                 ${LIBEPAN_LIBS}
998                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
999                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1000                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1001                 ${NL_LIBRARIES}
1002         )
1003         # qtshark and wireshark share wireshark_FILES
1004
1005         add_executable(qtshark ${wireshark_FILES})
1006         add_dependencies(qtshark gitversion)
1007         set_target_properties(qtshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1008         set_target_properties(qtshark PROPERTIES FOLDER "Executables")
1009         target_link_libraries(qtshark ${qtshark_LIBS})
1010         install(TARGETS qtshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1011 endif()
1012
1013 register_tap_files(tshark-tap-register.c
1014                 tshark-taps
1015         ${TSHARK_TAP_SRC}
1016 )
1017
1018 if(BUILD_tshark)
1019         set(tshark_LIBS
1020                 ui
1021                 ${LIBEPAN_LIBS}
1022                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1023                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1024         )
1025         set(tshark_FILES
1026                 capture_opts.c
1027                 tshark-tap-register.c
1028                 tshark.c
1029                 ${TSHARK_TAP_SRC}
1030                 ${SHARK_COMMON_CAPTURE_SRC}
1031                 ${SHARK_COMMON_SRC}
1032         )
1033         add_executable(tshark ${tshark_FILES})
1034         add_dependencies(tshark gitversion)
1035         set_target_properties(tshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1036         set_target_properties(tshark PROPERTIES FOLDER "Executables")
1037         target_link_libraries(tshark ${tshark_LIBS})
1038         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1039 endif()
1040
1041 if(BUILD_tfshark)
1042         set(tfshark_LIBS
1043                 filetap
1044                 ui
1045                 ${LIBEPAN_LIBS}
1046                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1047                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1048         )
1049         set(tfshark_FILES
1050                 tfshark.c
1051                 tshark-tap-register.c
1052                 ${TSHARK_TAP_SRC}
1053                 ${SHARK_COMMON_SRC}
1054         )
1055         add_executable(tfshark ${tfshark_FILES})
1056         add_dependencies(tfshark gitversion)
1057         set_target_properties(tfshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1058         set_target_properties(tfshark PROPERTIES FOLDER "Executables")
1059         target_link_libraries(tfshark ${tfshark_LIBS})
1060         install(TARGETS tfshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1061 endif()
1062
1063 if(BUILD_rawshark AND PCAP_FOUND)
1064         set(rawshark_LIBS
1065                 ${LIBEPAN_LIBS}
1066                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1067                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1068         )
1069         set(rawshark_FILES
1070                 ${SHARK_COMMON_SRC}
1071                 rawshark.c
1072                 ui/util.c
1073         )
1074         add_executable(rawshark ${rawshark_FILES})
1075         add_dependencies(rawshark gitversion)
1076         set_target_properties(rawshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1077         set_target_properties(rawshark PROPERTIES FOLDER "Executables")
1078         target_link_libraries(rawshark ${rawshark_LIBS})
1079         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1080 endif()
1081
1082 if(BUILD_dftest)
1083         set(dftest_LIBS
1084                 ${LIBEPAN_LIBS}
1085         )
1086         set(dftest_FILES
1087                 dftest.c
1088                 ui/util.c
1089         )
1090         add_executable(dftest ${dftest_FILES})
1091         set_target_properties(dftest PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1092         set_target_properties(dftest PROPERTIES FOLDER "Executables")
1093         target_link_libraries(dftest ${dftest_LIBS})
1094         install(TARGETS dftest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1095 endif()
1096
1097 if(BUILD_randpkt)
1098         set(randpkt_LIBS
1099                 wiretap
1100                 wsutil
1101                 ${M_LIBRARIES}
1102                 ${PCAP_LIBRARIES}
1103 #               @SOCKET_LIBS@
1104 #               @NSL_LIBS@
1105                 ${CARES_LIBRARIES}
1106                 ${ADNS_LIBRARIES}
1107                 ${ZLIB_LIBRARIES}
1108         )
1109         set(randpkt_FILES
1110                 randpkt.c
1111         )
1112         add_executable(randpkt ${randpkt_FILES})
1113         set_target_properties(randpkt PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1114         set_target_properties(randpkt PROPERTIES FOLDER "Executables")
1115         target_link_libraries(randpkt ${randpkt_LIBS})
1116         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1117 endif()
1118
1119 if(BUILD_text2pcap)
1120         set(text2pcap_LIBS
1121                 wsutil
1122                 ${M_LIBRARIES}
1123                 ${ZLIB_LIBRARIES}
1124         )
1125         set(text2pcap_CLEAN_FILES
1126                 text2pcap.c
1127                 pcapio.c
1128         )
1129         set(text2pcap_FILES
1130                 ${text2pcap_CLEAN_FILES}
1131         )
1132         add_lex_files(text2pcap_FILES
1133                 text2pcap-scanner.l
1134         )
1135         add_executable(text2pcap ${text2pcap_FILES})
1136         add_dependencies(text2pcap gitversion)
1137         set_target_properties(text2pcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1138         set_target_properties(text2pcap PROPERTIES FOLDER "Executables")
1139         target_link_libraries(text2pcap ${text2pcap_LIBS})
1140         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1141 endif()
1142
1143 if(BUILD_mergecap)
1144         set(mergecap_LIBS
1145                 wiretap
1146                 ${ZLIB_LIBRARIES}
1147                 ${CMAKE_DL_LIBS}
1148         )
1149         set(mergecap_FILES
1150                 mergecap.c
1151                 version.h
1152         )
1153         add_executable(mergecap ${mergecap_FILES})
1154         add_dependencies(mergecap gitversion)
1155         set_target_properties(mergecap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1156         set_target_properties(mergecap PROPERTIES FOLDER "Executables")
1157         target_link_libraries(mergecap ${mergecap_LIBS})
1158         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1159 endif()
1160
1161 if(BUILD_reordercap)
1162         set(reordercap_LIBS
1163                 wiretap
1164                 ${ZLIB_LIBRARIES}
1165                 ${CMAKE_DL_LIBS}
1166         )
1167         set(reordercap_FILES
1168                 reordercap.c
1169                 version.h
1170         )
1171         add_executable(reordercap ${reordercap_FILES})
1172         add_dependencies(reordercap gitversion)
1173         set_target_properties(reordercap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1174         set_target_properties(reordercap PROPERTIES FOLDER "Executables")
1175         target_link_libraries(reordercap ${reordercap_LIBS})
1176         install(TARGETS reordercap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1177 endif()
1178
1179 if(BUILD_capinfos)
1180         set(capinfos_LIBS
1181                 wiretap
1182                 wsutil
1183                 ${ZLIB_LIBRARIES}
1184                 ${GCRYPT_LIBRARIES}
1185                 ${CMAKE_DL_LIBS}
1186         )
1187         set(capinfos_FILES
1188                 capinfos.c
1189         )
1190         add_executable(capinfos ${capinfos_FILES})
1191         add_dependencies(capinfos gitversion)
1192         set_target_properties(capinfos PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1193         set_target_properties(capinfos PROPERTIES FOLDER "Executables")
1194         target_link_libraries(capinfos ${capinfos_LIBS})
1195         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1196 endif()
1197
1198 if(BUILD_captype)
1199         set(captype_LIBS
1200                 wiretap
1201                 wsutil
1202                 ${ZLIB_LIBRARIES}
1203                 ${CMAKE_DL_LIBS}
1204         )
1205         set(captype_FILES
1206                 captype.c
1207         )
1208         add_executable(captype ${captype_FILES})
1209         add_dependencies(captype gitversion)
1210         set_target_properties(captype PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1211         set_target_properties(captype PROPERTIES FOLDER "Executables")
1212         target_link_libraries(captype ${captype_LIBS})
1213         install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1214 endif()
1215
1216 if(BUILD_editcap)
1217         set(editcap_LIBS
1218                 wiretap
1219                 ${ZLIB_LIBRARIES}
1220                 ${CMAKE_DL_LIBS}
1221         )
1222         set(editcap_FILES
1223                 editcap.c
1224         )
1225         add_executable(editcap ${editcap_FILES})
1226         add_dependencies(editcap gitversion)
1227         set_target_properties(editcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1228         set_target_properties(editcap PROPERTIES FOLDER "Executables")
1229         target_link_libraries(editcap ${editcap_LIBS})
1230         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1231 endif()
1232
1233 if(BUILD_dumpcap AND PCAP_FOUND)
1234         set(dumpcap_LIBS
1235                 wsutil
1236                 ${PCAP_LIBRARIES}
1237                 ${CAP_LIBRARIES}
1238 #               @SOCKET_LIBS@
1239 #               @NSL_LIBS@
1240                 ${GLIB2_LIBRARIES}
1241                 ${GTHREAD2_LIBRARIES}
1242                 ${ZLIB_LIBRARIES}
1243                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1244                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1245                 ${NL_LIBRARIES}
1246         )
1247         set(dumpcap_FILES
1248                 version.h
1249                 capture_opts.c
1250                 capture-pcap-util.c
1251                 capture_stop_conditions.c
1252                 cfutils.c
1253                 clopts_common.c
1254                 conditions.c
1255                 dumpcap.c
1256                 pcapio.c
1257                 ringbuffer.c
1258                 sync_pipe_write.c
1259                 version_info.c
1260                 ws80211_utils.c
1261                 ${PLATFORM_PCAP_SRC}
1262         )
1263         add_executable(dumpcap ${dumpcap_FILES})
1264         add_dependencies(dumpcap gitversion)
1265         set_target_properties(dumpcap PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1266         set_target_properties(dumpcap PROPERTIES FOLDER "Executables")
1267         target_link_libraries(dumpcap ${dumpcap_LIBS})
1268         install(TARGETS dumpcap
1269                         RUNTIME
1270                         DESTINATION ${CMAKE_INSTALL_BINDIR}
1271                         PERMISSIONS ${DUMPCAP_SETUID}
1272                                 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1273                                 GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
1274         )
1275         if(DUMPCAP_INSTALL_OPTION STREQUAL "capabilities")
1276                 install( CODE "execute_process(
1277                         COMMAND
1278                                 ${SETCAP_EXECUTABLE}
1279                                 cap_net_raw,cap_net_admin+ep
1280                                 ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/dumpcap${CMAKE_EXECUTABLE_SUFFIX}
1281                         RESULT_VARIABLE
1282                                 _SETCAP_RESULT
1283                         )
1284                         if( _SETCAP_RESULT )
1285                                 message( WARNING \"setcap failed (${_SETCAP_RESULT}).\")
1286                         endif()"
1287                 )
1288         endif()
1289 endif()
1290
1291 ADD_CUSTOM_COMMAND(
1292         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
1293         COMMAND ${PERL_EXECUTABLE}
1294                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
1295                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
1296                 < ${CMAKE_SOURCE_DIR}/AUTHORS
1297                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
1298         DEPENDS
1299                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
1300                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
1301                 ${CMAKE_SOURCE_DIR}/AUTHORS
1302 )
1303
1304 ADD_CUSTOM_COMMAND(
1305         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
1306                 ${CMAKE_BINARY_DIR}/wireshark.pod
1307         COMMAND ${PERL_EXECUTABLE}
1308                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
1309                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
1310                 < ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
1311                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
1312         COMMAND cat
1313                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
1314                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
1315                 > ${CMAKE_BINARY_DIR}/wireshark.pod
1316         DEPENDS
1317                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
1318                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
1319                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
1320                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
1321 )
1322
1323 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
1324 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/captype 1 )
1325 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dftest 1 )
1326 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
1327 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
1328 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/asn2deb 1 )
1329 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2deb 1 )
1330 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
1331 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
1332 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpkt 1 )
1333 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
1334 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/reordercap 1 )
1335 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
1336 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
1337 pod2manhtml( ${CMAKE_BINARY_DIR}/wireshark 1 )
1338 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/wireshark-filter 4 )
1339
1340 add_custom_target(
1341         auxiliary ALL
1342         DEPENDS
1343                 AUTHORS-SHORT
1344                 capinfos.html
1345                 captype.html
1346                 dftest.html
1347                 dumpcap.html
1348                 editcap.html
1349                 asn2deb.html
1350                 idl2deb.html
1351                 idl2wrs.html
1352                 mergecap.html
1353                 randpkt.html
1354                 rawshark.html
1355                 reordercap.html
1356                 text2pcap.html
1357                 tshark.html
1358                 wireshark.html
1359                 wireshark-filter.html
1360 )
1361 set_target_properties(auxiliary PROPERTIES FOLDER "Docs")
1362
1363 set(MAN1_FILES
1364         ${CMAKE_BINARY_DIR}/capinfos.1
1365         ${CMAKE_BINARY_DIR}/captype.1
1366         ${CMAKE_BINARY_DIR}/dftest.1
1367         ${CMAKE_BINARY_DIR}/dumpcap.1
1368         ${CMAKE_BINARY_DIR}/editcap.1
1369         ${CMAKE_BINARY_DIR}/idl2wrs.1
1370         ${CMAKE_BINARY_DIR}/mergecap.1
1371         ${CMAKE_BINARY_DIR}/randpkt.1
1372         ${CMAKE_BINARY_DIR}/rawshark.1
1373         ${CMAKE_BINARY_DIR}/reordercap.1
1374         ${CMAKE_BINARY_DIR}/text2pcap.1
1375         ${CMAKE_BINARY_DIR}/tshark.1
1376         ${CMAKE_BINARY_DIR}/wireshark.1
1377 )
1378
1379 set(MAN4_FILES
1380         ${CMAKE_BINARY_DIR}/wireshark-filter.4
1381 )
1382
1383 set(CLEAN_FILES
1384         ${wireshark_FILES}
1385         ${tshark_FILES}
1386         ${rawshark_FILES}
1387         ${dftest_FILES}
1388         ${randpkt_FILES}
1389         ${text2pcap_CLEAN_FILES}
1390         ${mergecap_FILES}
1391         ${capinfos_FILES}
1392         ${captype_FILES}
1393         ${editcap_FILES}
1394         ${dumpcap_FILES}
1395 )
1396
1397 if (WERROR)
1398         set_source_files_properties(
1399                 ${CLEAN_FILES}
1400                 PROPERTIES
1401                 COMPILE_FLAGS -Werror
1402         )
1403 endif()
1404
1405 install(
1406         FILES
1407                 ${INSTALL_FILES}
1408         DESTINATION
1409                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
1410 )
1411
1412 install(
1413         FILES
1414                 ${MAN1_FILES}
1415         DESTINATION
1416                 ${CMAKE_INSTALL_MANDIR}/man1
1417 )
1418
1419 install(
1420         FILES
1421                 ${MAN4_FILES}
1422         DESTINATION
1423                 ${CMAKE_INSTALL_MANDIR}/man4
1424 )
1425
1426 install(
1427         DIRECTORY
1428                 ${INSTALL_DIRS}
1429         DIRECTORY_PERMISSIONS
1430                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
1431                 GROUP_EXECUTE GROUP_READ
1432                 WORLD_EXECUTE WORLD_READ
1433         DESTINATION
1434                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
1435         PATTERN ".git" EXCLUDE
1436         PATTERN ".svn" EXCLUDE
1437         PATTERN "Makefile.*" EXCLUDE
1438         PATTERN "faq.py" EXCLUDE
1439 )
1440
1441 include( UseCheckAPI )
1442 CHECKAPI(
1443                   ${TSHARK_TAP_SRC}
1444                   ${wireshark_FILES}
1445 )
1446
1447 if(DOC_DIR)
1448         message(STATUS "Docdir install: ${DOC_DIR}")
1449         INSTALL(
1450                 DIRECTORY
1451                         ${CMAKE_BINARY_DIR}/docbook/
1452                 DIRECTORY_PERMISSIONS
1453                         OWNER_EXECUTE OWNER_WRITE OWNER_READ
1454                         GROUP_EXECUTE GROUP_READ
1455                         WORLD_EXECUTE WORLD_READ
1456                 DESTINATION
1457                         ${DOC_DIR}/guides
1458                 FILES_MATCHING
1459                 PATTERN "*.pdf"
1460         )
1461 endif()