Revert "On OS X, add the Qt -Wl,-rpath hack in CMake, as we do with autotools."
[metze/wireshark/wip.git] / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 project(Wireshark C CXX)
23
24 message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
25 if(WIN32)
26         # Needed for proper Qt linking. See
27         # http://www.cmake.org/cmake/help/v3.0/policy/CMP0020.html
28         # 3.1.3 is the currently supported version
29         cmake_minimum_required(VERSION 3.1.3)
30 else()
31         cmake_minimum_required(VERSION 2.8.3)
32 endif()
33
34 # Needs to be set after cmake_minimum_required or cmake_policy(VERSION)
35 # Policy since 2.6.1
36 cmake_policy(SET CMP0008 NEW)
37 # Policy since 2.6.3
38 # Backward compatibility for versions < 2.6.3
39 cmake_policy(SET CMP0011 OLD)
40 # Policy since 2.8.1
41 cmake_policy(SET CMP0015 NEW)
42
43 #Where to find local cmake scripts
44 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
45
46 # Set old behaviour for LOCATION property
47 if (POLICY CMP0026)
48         cmake_policy(SET CMP0026 OLD)
49 endif()
50
51 # Set old behaviour for variable quoting
52 if (POLICY CMP0054)
53         cmake_policy(SET CMP0054 OLD)
54 endif()
55
56 # Set old behaviour for MACOSX_RPATH
57 if (POLICY CMP0042)
58         cmake_policy(SET CMP0042 OLD)
59 endif()
60
61 # If our target platform is enforced by our generator, set
62 # WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
63 # %WIRESHARK_TARGET_PLATFORM%.
64
65 if(WIN32)
66         find_package(PowerShell REQUIRED)
67
68         if("${CMAKE_GENERATOR}" MATCHES "Win64")
69                 set(WIRESHARK_TARGET_PLATFORM win64)
70         elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
71                 set(WIRESHARK_TARGET_PLATFORM win32)
72         else()
73                 set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
74         endif()
75
76         if ("${WIRESHARK_TARGET_PLATFORM}" MATCHES "win64")
77                 set(PROCESSOR_ARCHITECTURE amd64)
78         else()
79                 set(PROCESSOR_ARCHITECTURE x86)
80         endif()
81
82         # Sanity check
83         if(DEFINED ENV{PLATFORM})
84                 string(TOLOWER $ENV{PLATFORM} _vs_platform)
85         else()
86                 set(_vs_platform "[undefined]") # x86
87         endif()
88         if(
89                 (_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
90                 OR
91                 (_vs_platform STREQUAL "[undefined]" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win32")
92         )
93                 message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
94                         " doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
95         endif()
96         message(STATUS "Building for ${WIRESHARK_TARGET_PLATFORM} using ${CMAKE_GENERATOR}")
97
98         # Determine where the 3rd party libraries will be
99         if( DEFINED ENV{WIRESHARK_LIB_DIR} )
100                 # The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR.
101                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR )
102         elseif( DEFINED ENV{WIRESHARK_BASE_DIR} )
103                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR )
104                 set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" )
105         else()
106                 # Don't know what to do
107                 message(FATAL_ERROR "Neither WIRESHARK_BASE_DIR or WIRESHARK_LIB_DIR are defined")
108         endif()
109
110         # Download third-party libraries
111         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
112         file (TO_NATIVE_PATH ${_PROJECT_LIB_DIR} _ws_lib_dir)
113         if(MSVC12)
114                 set(_vsversion_args "12")
115         elseif(MSVC11)
116                 set(_vsversion_args "11")
117         elseif(MSVC10)
118                 set(_vsversion_args "10")
119         else()
120                 message(FATAL_ERROR "Unsupported compiler ${CMAKE_C_COMPILER}")
121         endif()
122
123         # Is it possible to have a one-time, non-cached option in CMake? If
124         # so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
125         # win-setup.ps1.
126         execute_process(
127                 COMMAND ${POWERSHELL_COMMAND} "${_win_setup}" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM} -VSVersion ${_vsversion_args}
128                 RESULT_VARIABLE _win_setup_failed
129         )
130         if (${_win_setup_failed})
131                 message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
132         endif()
133
134         # XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
135 endif(WIN32)
136
137 include(UseCustomIncludes)
138 ADD_CUSTOM_CMAKE_INCLUDE()
139
140 # This cannot be implemented via option(...)
141 if( NOT CMAKE_BUILD_TYPE )
142         set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
143                 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
144                 FORCE)
145 endif()
146 message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
147
148 # Override optimization and other flags for make based generators
149 foreach (_BT DEBUG RELEASE RELWITHDEBINFO SIZEREL)
150         set( CMAKE_C_FLAGS_${_BT} "${CMAKE_C_FLAGS_${_BT}} ${CMAKE_C_FLAGS}" )
151         set( CMAKE_CXX_FLAGS_${_BT} "${CMAKE_C_FLAGS_${_BT}} ${CMAKE_C_FLAGS}" )
152 endforeach()
153
154 message(STATUS "${CMAKE_BUILD_TYPE}: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
155
156 # Where to put executables and libraries in the build tree
157 # Note: Executables and libraries might end end up in a configuration
158 # subdirectory, e.g. run/Debug or run/Release. We try to set DATAFILE_DIR
159 # to a corresponding value below.
160 if(NOT ARCHIVE_OUTPUT_PATH)
161         set(ARCHIVE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
162                    "Single output directory for building all archives.")
163 endif()
164 if(NOT EXECUTABLE_OUTPUT_PATH)
165         set(EXECUTABLE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
166                    "Single output directory for building all executables.")
167 endif()
168 if(NOT LIBRARY_OUTPUT_PATH)
169         set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
170                    "Single output directory for building all libraries.")
171 endif()
172
173 # Under linux the release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG
174 #Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
175 include(CMakeInstallDirs)
176
177 # Updated by make-version.pl
178 set(GIT_REVISION 0)
179 set(PROJECT_MAJOR_VERSION 1)
180 set(PROJECT_MINOR_VERSION 99)
181 set(PROJECT_PATCH_VERSION 8)
182 set(PROJECT_BUILD_VERSION ${GIT_REVISION})
183 set(PROJECT_VERSION_EXTENSION "$ENV{WIRESHARK_VERSION_EXTRA}")
184 set(PROJECT_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
185
186 # Banner shown at top right of Qt welcome screen.
187 if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
188         set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
189 else()
190         set(VERSION_FLAVOR "Development Build")
191 endif()
192
193 # These are required in .rc files and manifests
194 set(VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
195 set(VERSION_MINOR ${PROJECT_MINOR_VERSION})
196 set(VERSION_MICRO ${PROJECT_PATCH_VERSION})
197 set(VERSION_BUILD ${PROJECT_BUILD_VERSION})
198 set(RC_VERSION ${PROJECT_MAJOR_VERSION},${PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
199
200 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
201
202 include(UseLemon)
203 include(UseMakeDissectorReg)
204 include(UseMakeTapReg)
205 include(UseAsn2Wrs)
206
207 include_directories(
208         ${CMAKE_BINARY_DIR}
209         ${CMAKE_SOURCE_DIR}
210         ${CMAKE_SOURCE_DIR}/epan
211         ${CMAKE_SOURCE_DIR}/tools/lemon
212         ${CMAKE_SOURCE_DIR}/wiretap
213 )
214
215 include( CMakeOptions.txt )
216 if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
217         set( DUMPCAP_SETUID "SETUID" )
218 else()
219         set( DUMPCAP_SETUID )
220 endif()
221 if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
222         DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
223         message( WARNING "Capabilities are only supported on Linux" )
224         set( DUMPCAP_INSTALL_OPTION )
225 endif()
226
227 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
228         if (MSVC10)
229                 set(MSC_VER_REQUIRED 1600)
230         elseif(MSVC11)
231                 set(MSC_VER_REQUIRED 1700)
232         elseif(MSVC12)
233                 set(MSC_VER_REQUIRED 1800)
234         else()
235                 message(FATAL_ERROR "You are using an unsupported version of MSVC")
236         endif()
237
238         add_definitions(
239                 /DWIN32_LEAN_AND_MEAN
240                 "/DMSC_VER_REQUIRED=${MSC_VER_REQUIRED}"
241                 /D_CRT_SECURE_NO_DEPRECATE
242                 /D_CRT_NONSTDC_NO_DEPRECATE
243                 # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
244                 # This avoids conflicts with the C++ standard library.
245                 /DNOMINMAX
246                 # -DPSAPI_VERSION=1                 Programs that must run on earlier versions of Windows as well as Windows 7 and later
247                 #                                   versions should always call this function as GetProcessMemoryInfo. To ensure correct
248                 #                                   resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program
249                 #                                   with -DPSAPI_VERSION=1.To use run-time dynamic linking, load Psapi.dll.
250                 #                                   http://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx
251                 # -DBUILD_WINDOWS                   Starting from VS2013, GetVersionEx is deprecated and we are recommended to use
252                 #                                   VerifyVersionInfo instead
253                 #                                   http://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx
254                 #                                   http://msdn.microsoft.com/en-us/library/windows/desktop/ms725491(v=vs.85).aspx
255                 #                                   To continue to use GetVersionEx, we can define BUILD_WINDOWS
256                 # -D_ALLOW_KEYWORD_MACROS           For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
257                 #                                   (see http://msdn.microsoft.com/en-us/library/bb531344(v=vs.110).aspx)
258                 #                                   This definition prevents the complaint about the redefinition of inline by WinPCap
259                 #                                   in pcap-stdinc.h when compiling CPP files, e.g. the Qt UI
260                 /DPSAPI_VERSION=1
261                 /DBUILD_WINDOWS
262                 /D_ALLOW_KEYWORD_MACROS
263         )
264
265         if(NOT "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64")
266                 add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
267         endif()
268
269         # FIXME: WINPCAP_VERSION cannot be determined from source or executable.
270         set(WINPCAP_VERSION "unknown")
271         add_definitions("/DWINPCAP_VERSION=${WINPCAP_VERSION}")
272
273         set(LOCAL_CFLAGS
274                 /MP
275         )
276
277         if(MSVC12)
278                 # /Zo                               Enhanced debugging of optimised code for VS2013 Update 3 and beyond,
279                 #                                   Assume all VS2013 builds are at least Update 3.
280                 #                                   See http://msdn.microsoft.com/en-us/library/dn785163.aspx
281                 set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/Zo")
282         endif()
283
284         if(ENABLE_CODE_ANALYSIS)
285                 set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/analyze:WX-")
286         endif()
287
288         # Additional compiler warnings to be treated as "Level 3"
289         #  when compiling Wireshark sources. (Selected from "level 4" warnings).
290         ## 4295: array is too small to include a terminating null character
291         ## 4189: local variable is initialized but not referenced
292         set(WARNINGS_CFLAGS "/w34295 /w34189")
293
294         set(WIRESHARK_COMMON_FLAGS
295                 ${LOCAL_CFLAGS}
296                 ${WARNINGS_CFLAGS}
297         )
298
299         # Set in Makefile.nmake
300         set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
301
302 else()
303         if(CMAKE_OSX_DEPLOYMENT_TARGET)
304                 if(APPLE)
305                         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.0")
306                                 message(FATAL_ERROR "We don't support building for OS X 10.0")
307                         elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.1")
308                                 message(FATAL_ERROR "We don't support building for OS X 10.1")
309                         elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.2")
310                                 message(FATAL_ERROR "We don't support building for OS X 10.2")
311                         elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.4" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
312                                 #
313                                 # Only 32-bit builds are supported.  10.5
314                                 # (and 10.4?) had a bug that causes some BPF
315                                 # functions not to work with 64-bit userland
316                                 # code, so capturing won't work.
317                                 #
318                                 set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
319                                 set(CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
320                                 set(WS_LINK_FLAGS "-m32 ${WS_LINK_FLAGS}")
321                         endif()
322                         message(STATUS "Building for OS X ${CMAKE_OSX_DEPLOYMENT_TARGET}")
323                 else()
324                         message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET only applies when building for OS X")
325                 endif()
326         endif()
327
328         set(WIRESHARK_COMMON_FLAGS
329                 # The following are for C and C++
330                 # -O<X> and -g get set by the CMAKE_BUILD_TYPE
331                 -Wall
332                 -W
333                 -Wextra
334                 -Wendif-labels
335                 -Wpointer-arith
336                 -Warray-bounds
337                 -Wformat-security
338                 -fwrapv
339                 -fno-strict-overflow
340                 -fno-delete-null-pointer-checks
341                 -fsanitize=undefined # compile and runtime checks
342                 # -fsanitize=float-divide-by-zero
343                 # -fsanitize=float-cast-overflow
344                 # -fsanitize=address
345                 # -fno-sanitize-recover # Abort during runtime
346                 -Wvla
347                 -Waddress
348                 -Wattributes
349                 -Wdiv-by-zero
350                 -Wignored-qualifiers
351                 -Wpragmas
352                 -Wno-overlength-strings
353                 -Wwrite-strings
354                 -Wno-long-long
355                 -Wheader-guard
356                 -Wunused-const-variable
357         )
358
359         set(WIRESHARK_C_ONLY_FLAGS
360                 # The following are C only, not C++
361                 -Wc++-compat
362                 -Wdeclaration-after-statement
363                 -Wshadow
364                 -Wno-pointer-sign
365                 -Wold-style-definition
366                 -Wstrict-prototypes
367                 -Wlogical-op
368                 -Wjump-misses-init
369                 # The Qt headers generate a ton of shortening errors on 64-bit systems
370                 # so only enable this for C for now.
371                 -Wshorten-64-to-32
372         )
373
374         set(WIRESHARK_CPP_ONLY_FLAGS
375         )
376
377         set(WIRESHARK_EXTRA_COMPILER_COMMON_FLAGS
378                 # The following are for C and C++
379                 -Wpedantic
380                 #
381                 # Various code blocks this one.
382                 #
383                 -Woverflow
384                 -fstrict-overflow -Wstrict-overflow=4
385                 #
386                 # Due to various places where APIs we don't control
387                 # require us to cast away constness, we can probably
388                 # never enable this one with -Werror.
389                 #
390                 -Wcast-qual
391                 #
392                 # Some generated ASN.1 dissectors block this one;
393                 # multiple function declarations for the same
394                 # function are being generated.
395                 #
396                 -Wredundant-decls
397                 #
398                 # Some loops are safe, but it's hard to convince the
399                 # compiler of that.
400                 #
401                 -Wunsafe-loop-optimizations
402                 #
403                 # All the registration functions block these for now.
404                 #
405                 -Wmissing-prototypes
406                 -Wmissing-declarations
407                 #
408                 # A bunch of "that might not work on SPARC" code blocks
409                 # this one for now.
410                 #
411                 -Wcast-align
412                 #
413                 # Works only with Clang
414                 #
415                 -Wunreachable-code
416                 #
417                 # Works only with Clang but generates a lot of warnings
418                 # (about glib library not using Doxygen)
419                 #
420                 -Wdocumentation
421         )
422
423         set(WIRESHARK_EXTRA_COMPILER_C_ONLY_FLAGS
424                 # The following are C only, not C++
425                 #
426                 # Due to various places where APIs we don't control
427                 # require us to cast away constness, we can probably
428                 # never enable this one with -Werror.
429                 #
430                 -Wbad-function-cast
431         )
432
433         set(WIRESHARK_EXTRA_COMPILER_CPP_ONLY_FLAGS
434         )
435
436         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
437                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
438                         #-fcolor-diagnostics
439                 )
440
441                 # ccache + clang++ can result in "argument unused during
442                 # compilation" warnings.
443                 set(WIRESHARK_CPP_ONLY_FLAGS ${WIRESHARK_CPP_ONLY_FLAGS}
444                         -Qunused-arguments
445                 )
446         else()
447                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
448                         -fexcess-precision=fast
449                 )
450
451                 set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS}
452                 )
453         endif()
454
455         set(WIRESHARK_ASAN_FLAGS
456                 # With Clang >= 3.5 Leak detection is enable by default
457                 # and no yet all leak is fixed...
458                 # use ASAN_OPTIONS=detect_leaks=0 to disable detect_leaks
459                 -fsanitize=address
460         )
461
462         if(ENABLE_ASAN)
463                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_ASAN_FLAGS})
464         endif()
465
466         if(ENABLE_EXTRA_COMPILER_WARNINGS)   # This overrides -Werror
467                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_EXTRA_COMPILER_COMMON_FLAGS})
468                 set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS} ${WIRESHARK_EXTRA_COMPILER_C_ONLY_FLAGS})
469                 set(WIRESHARK_CPP_ONLY_FLAGS ${WIRESHARK_CPP_ONLY_FLAGS} ${WIRESHARK_EXTRA_COMPILER_CPP_ONLY_FLAGS})
470         endif()
471
472         add_definitions(
473                 -DG_DISABLE_DEPRECATED
474                 -DG_DISABLE_SINGLE_INCLUDES
475         )
476 endif()
477
478 set( C_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS} )
479 set( CPP_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CPP_ONLY_FLAGS} )
480
481 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
482 include(CheckCCompilerFlag)
483 include(CheckCXXCompilerFlag)
484
485 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
486         check_c_compiler_flag(-Werror WERROR)
487 else()
488         set(WERROR FALSE)
489 endif()
490
491 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
492 foreach(THIS_FLAG ${C_FLAG_TESTS})
493         string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
494         set(${F} ${THIS_FLAG})
495         set(V C_${F}_VALID)
496         message(STATUS "Checking for c-compiler flag: ${THIS_FLAG}")
497         check_c_compiler_flag("${ADDED_CMAKE_C_FLAGS} ${${F}}" ${V})
498         if (${${V}})
499                 set(ADDED_CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${${F}}")
500         endif()
501 endforeach()
502 set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
503
504 foreach(THIS_FLAG ${CPP_FLAG_TESTS})
505         string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
506         set(${F} ${THIS_FLAG})
507         set(V CPP_${F}_VALID)
508         message(STATUS "Checking for c++-compiler flag: ${THIS_FLAG}")
509         check_cxx_compiler_flag("${ADDED_CMAKE_CXX_FLAGS} ${${F}}" ${V})
510         if (${${V}})
511                 set(ADDED_CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${${F}}")
512         endif()
513 endforeach()
514 set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
515
516 #
517 # Try to have the compiler default to hiding symbols, so that only
518 # symbols explicitly exported with WS_DLL_PUBLIC will be visible
519 # outside (shared) libraries; that way, more UN*X builds will catch
520 # failures to export symbols, rather than having that fail only on
521 # Windows.
522 #
523 # We don't need that with MSVC, as that's the default.
524 #
525 if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
526         #
527         # Try the GCC-and-copatible -fvisibility-hidden first.
528         #
529         check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
530         if(FVHIDDEN)
531                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
532         else()
533                 #
534                 # OK, try the Sun^WOracle C -xldscope=hidden
535                 #
536                 check_c_compiler_flag(-xldscope=hidden XLDSCOPEHIDDEN)
537                 if(XLDSCOPEHIDDEN)
538                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xldscope=hidden")
539                 else()
540                         #
541                         # Anything else?
542                         # If there is anything else, we might want to
543                         # make a list of options to try, and try them
544                         # in a loop.
545                         #
546                         message(WARNING "Hiding shared library symbols is not supported by the compiler."
547                                 " All shared library symbols will be exported.")
548                 endif()
549         endif()
550 endif()
551
552 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
553         set (C_UNUSED "__attribute__((unused))" )
554 else()
555         set (C_UNUSED "" )
556 endif()
557
558
559 if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
560         set(WIRESHARK_LD_FLAGS
561                 -Wl,--as-needed
562                 # -flto
563                 # -fwhopr
564                 # -fwhole-program
565         )
566 endif()
567
568 include(CheckCLinkerFlag)
569 set(_C 0)
570 # Sigh: Have to use THIS_FLAG instead of ${F} for some reason
571 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
572         set(F WS_LD_FLAG_${_C})
573         set(${F} ${THIS_FLAG})
574         set(V WS_LD_FLAG_VALID${_C})
575         check_c_linker_flag(${${F}} ${V})
576         if (${${V}})
577                 set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${${F}}")
578         endif()
579         math(EXPR _C "${_C} + 1")
580 endforeach()
581
582 if(ENABLE_STATIC)
583         set(BUILD_SHARED_LIBS 0)
584         set(LINK_MODE_LIB STATIC)
585         set(LINK_MODE_MODULE STATIC)
586 else()
587         set(BUILD_SHARED_LIBS 1)
588         set(LINK_MODE_LIB SHARED)
589         set(LINK_MODE_MODULE MODULE)
590 endif()
591
592 if(APPLE AND EXISTS /usr/local/opt/gettext)
593         # GLib on OS X requires libintl. Homebrew installs gettext (and
594         # libintl) in /usr/local/opt/gettext
595         include_directories(/usr/local/opt/gettext/include)
596         link_directories(/usr/local/opt/gettext/lib)
597 endif()
598
599 # The packagelist is doing some magic:  If we add XXX to the packagelist, we
600 # - may optionally set XXX_OPTIONS to pass to the find_package command
601 # - will call FindXXX.cmake
602 # - return found libraries in XXX_LIBRARIES
603 # - return found include in XXX_INCLUDE_DIRS
604 # - set HAVE_XXX
605
606 #The minimum package list
607 set(PACKAGELIST Gettext M GLIB2 GMODULE2 GTHREAD2 LEX YACC Perl SED SH PythonInterp)
608 set(LEX_REQUIRED TRUE)
609 set(GLIB2_REQUIRED TRUE)
610 set(GLIB2_FIND_REQUIRED TRUE)
611 set(GLIB2_MIN_VERSION 2.14.0)
612 set(GTHREAD2_REQUIRED TRUE)
613 set(PythonInterp_FIND_VERSION 2)
614 set(Python_ADDITIONAL_VERSIONS 3)
615 set(YACC_REQUIRED TRUE)
616
617 if (NOT WIN32)
618         set(M_REQUIRED TRUE)
619 endif()
620
621 set(PACKAGELIST ${PACKAGELIST} HtmlViewer)
622
623 if(ENABLE_PCAP)
624         set(PACKAGELIST ${PACKAGELIST} PCAP)
625 endif()
626
627 if(ENABLE_AIRPCAP)
628         set(PACKAGELIST ${PACKAGELIST} AIRPCAP)
629 endif()
630
631 # Build the GTK-GUI?
632 if(BUILD_wireshark_gtk)
633         if(ENABLE_GTK3)
634                 set(PACKAGELIST ${PACKAGELIST} GTK3)
635         else()
636                 set(PACKAGELIST ${PACKAGELIST} GTK2)
637                 set(GTK2_OPTIONS COMPONENTS gtk)
638                 set(GTK2_FIND_VERSION 2.12)
639                 set(GTK2_DEBUG false)
640         endif()
641 endif()
642
643 # Build the Qt GUI?
644 if(BUILD_wireshark)
645         if(ENABLE_QT5)
646                 # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
647                 # somewhere. The if WIN32 in this place is annoying as well.
648                 if( WIN32 )
649                         set( QT5_BASE_PATH "$ENV{QT5_BASE_DIR}" )
650                         set( CMAKE_PREFIX_PATH "${QT5_BASE_PATH}" )
651                 endif()
652                 set(PACKAGELIST ${PACKAGELIST}
653                         Qt5Core
654                         Qt5LinguistTools
655                         Qt5MultimediaWidgets
656                         Qt5PrintSupport
657                         Qt5Widgets
658                 )
659                 if (APPLE)
660                         set(PACKAGELIST ${PACKAGELIST} Qt5MacExtras)
661                 endif()
662                 if( WIN32 )
663                         set(PACKAGELIST ${PACKAGELIST} Qt5WinExtras)
664                 endif()
665                 set(QT_VERSION 5)
666         else()
667                 set(PACKAGELIST ${PACKAGELIST} Qt4)
668                 # set(Qt4_OPTIONS 4.7.1 REQUIRED QtCore QtGui)
669                 set(QT_VERSION 4)
670         endif()
671 endif()
672
673 # SMI SNMP
674 if(ENABLE_SMI)
675         set(PACKAGELIST ${PACKAGELIST} SMI)
676 endif()
677
678 # GNU crypto
679 if(ENABLE_GCRYPT)
680         set(PACKAGELIST ${PACKAGELIST} GCRYPT)
681 endif()
682
683 # GNU SSL/TLS support
684 if(ENABLE_GNUTLS)
685         set(PACKAGELIST ${PACKAGELIST} GNUTLS)
686 endif()
687
688 # Kerberos
689 if(ENABLE_KERBEROS)
690         set(PACKAGELIST ${PACKAGELIST} KERBEROS)
691 endif()
692
693 # Portable audio
694 if(ENABLE_PORTAUDIO AND BUILD_wireshark_gtk)
695         set(PACKAGELIST ${PACKAGELIST} PORTAUDIO)
696 endif()
697
698
699 # Prefer c-ares over adns
700 if(ENABLE_CARES) # C Asynchronouse resolver
701         set(PACKAGELIST ${PACKAGELIST} CARES)
702 elseif(ENABLE_ADNS) # Gnu asynchronous DNS
703         set(PACKAGELIST ${PACKAGELIST} ADNS)
704 endif()
705
706 # Zlib compression
707 if(ENABLE_ZLIB)
708         if (WIN32)
709                 # On Windows we build our own version of zlib, so add the paths
710                 set(ZLIB_SRC_DIR "${_PROJECT_LIB_DIR}/zlib-1.2.8-ws")
711                 add_subdirectory("${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
712                 set(ZLIB_INCLUDE_DIR  "${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
713                 set(ZLIB_LIBRARY zlib)
714                 set(ZLIB_DLL "zlib1.dll")
715                 set_target_properties(zlib PROPERTIES FOLDER "Libs/zlib")
716                 # Annoyingly zlib also builds some other stuff we aren't interested in
717                 set_target_properties(zlibstatic PROPERTIES FOLDER "Libs/zlib")
718         endif()
719         set(PACKAGELIST ${PACKAGELIST} ZLIB)
720 endif()
721
722 # Embedded Lua interpreter
723 if(ENABLE_LUA)
724         set(PACKAGELIST ${PACKAGELIST} LUA)
725 endif()
726
727 # GeoIP address resolving
728 if(ENABLE_GEOIP)
729         set(PACKAGELIST ${PACKAGELIST} GEOIP)
730 endif()
731
732 if(ENABLE_NETLINK)
733         set(PACKAGELIST ${PACKAGELIST} NL)
734 endif()
735
736 if(ENABLE_SBC)
737         set(PACKAGELIST ${PACKAGELIST} SBC)
738 endif()
739
740 # Capabilities
741 if(ENABLE_CAP)
742         set(PACKAGELIST ${PACKAGELIST} CAP SETCAP)
743 endif()
744
745 # Windows version updates
746 if(ENABLE_WINSPARKLE)
747         set(PACKAGELIST ${PACKAGELIST} WINSPARKLE)
748 endif()
749
750 set(PACKAGELIST ${PACKAGELIST} YAPP)
751
752 set(PACKAGELIST ${PACKAGELIST} POD)
753
754 if(ENABLE_HTML_GUIDES)
755         set(PACKAGELIST ${PACKAGELIST} DOXYGEN)
756 endif()
757
758 set(PROGLIST)
759
760 #Sort the package list
761 list(SORT PACKAGELIST)
762 message(STATUS "Packagelist: ${PACKAGELIST}")
763 #Let's loop the package list
764 foreach(PACKAGE ${PACKAGELIST})
765         if(${PACKAGE} STREQUAL "Qt4")
766                 set(PACKAGE_VAR "QT")
767         elseif(${PACKAGE} STREQUAL "PythonInterp")
768                 set(PACKAGE_VAR "PYTHONINTERP")
769         elseif(${PACKAGE} STREQUAL "Gettext")
770                 set(PACKAGE_VAR "GETTEXT")
771         elseif(${PACKAGE} STREQUAL "HtmlViewer")
772                 set(PACKAGE_VAR "HTML_VIEWER")
773         elseif(${PACKAGE} STREQUAL "Perl")
774                 set(PACKAGE_VAR "PERL")
775         else()
776                 set(PACKAGE_VAR ${PACKAGE})
777         endif()
778         if(${PACKAGE}_OPTIONS)
779                 find_package(${PACKAGE} ${${PACKAGE}_OPTIONS})
780         elseif(${PACKAGE}_REQUIRED)
781                 find_package(${PACKAGE} REQUIRED)
782         else()
783                 find_package(${PACKAGE})
784         endif()
785         if (${PACKAGE_VAR}_FOUND)
786                 message(STATUS "${PACKAGE_VAR} FOUND")
787                 set(HAVE_LIB${PACKAGE_VAR} 1)
788                 include_directories(SYSTEM ${${PACKAGE_VAR}_INCLUDE_DIRS})
789                 set(WS_ALL_LIBS ${WS_ALL_LIBS} ${${PACKAGE_VAR}_LIBRARIES})
790                 message(STATUS "${PACKAGE} includes: ${${PACKAGE_VAR}_INCLUDE_DIRS}")
791                 message(STATUS "${PACKAGE} libs: ${${PACKAGE_VAR}_LIBRARIES}")
792                 if (${PACKAGE}_DEFINITIONS)
793                         message(STATUS "${PACKAGE} definitions: ${${PACKAGE_VAR}_DEFINITIONS}")
794                 endif()
795                 if (${PACKAGE_VAR}_EXECUTABLE)
796                         message(STATUS "${PACKAGE} executable: ${${PACKAGE_VAR}_EXECUTABLE}")
797                 endif()
798         else()
799                 #
800                 # Not finding a package is only a fatal error if the
801                 # package is required; if it's required, then its
802                 # XXX_REQUIRED variable is set to TRUE, and the above
803                 # code will pass REQUIRED to find_package, and the
804                 # configure will fail if the package isn't found.
805                 #
806                 # Do *NOT* report this as an error!
807                 #
808                 message(STATUS "${PACKAGE_VAR} NOT FOUND")
809         endif()
810 endforeach()
811
812 # Provide Windows system lib names
813 include( UseWinLibs )
814
815 #packaging
816 include(CPackConfig.txt)
817
818 if(HAVE_LIBAIRPCAP)
819         set(HAVE_AIRPCAP 1)
820 endif()
821 if(HAVE_LIBLUA)
822         set(HAVE_LUA_H 1)
823         set(HAVE_LUA 1)
824 endif()
825 if(HAVE_LIBKERBEROS)
826         set(HAVE_KERBEROS 1)
827         # HAVE_HEIMDAL_KERBEROS
828         set(HAVE_MIT_KERBEROS 1)
829         set(HAVE_KEYTYPE_ARCFOUR_56 1)
830 endif()
831 if(HAVE_LIBGEOIP)
832         set(HAVE_GEOIP 1)
833 endif()
834 if(HAVE_LIBCARES)
835         set(HAVE_C_ARES 1)
836 endif()
837 if(HAVE_LIBADNS)
838         set(HAVE_GNU_ADNS 1)
839 endif()
840 if(HAVE_LIBNL AND HAVE_AIRPCAP)
841         message(ERROR "Airpcap and Libnl support are mutually exclusive")
842 endif()
843 if(HAVE_LIBSBC)
844         set(HAVE_SBC 1)
845 endif()
846 if(EXTCAP_ANDROIDDUMP_LIBPCAP)
847         set(ANDROIDDUMP_USE_LIBPCAP 1)
848 endif()
849
850 if (HAVE_LIBWINSPARKLE)
851         set(HAVE_SOFTWARE_UPDATE 1)
852 endif()
853
854 # No matter which version of GTK is present
855 if(GTK2_FOUND OR GTK3_FOUND)
856         set(GTK_FOUND ON)
857 endif()
858 # That's the name autofoo uses
859 if(HAVE_LIBZLIB)
860         set(HAVE_LIBZ 1)
861         # Always include the "true" zlib includes first. This works around a
862         # bug in the Windows setup of GTK[23] which has a faulty zconf.h.
863         include_directories(BEFORE ${ZLIB_INCLUDE_DIRS})
864 endif()
865 if (Qt5Widgets_FOUND)
866         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
867         if (Qt5_POSITION_INDEPENDENT_CODE)
868                 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
869         endif()
870         set (QT_FOUND ON)
871         set (QT_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES})
872         if(Qt5MultimediaWidgets_FOUND)
873                 set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MultimediaWidgets_LIBRARIES})
874                 # That's the name autofoo uses
875                 set(QT_MULTIMEDIAWIDGETS_LIB 1)
876         endif()
877         if(Qt5MacExtras_FOUND)
878                 set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MacExtras_LIBRARIES})
879                 # That's the name autofoo uses
880                 set(QT_MACEXTRAS_LIB 1)
881         endif()
882         if(Qt5WinExtras_FOUND)
883                 set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5WinExtras_LIBRARIES})
884                 # set(QT_WINEXTRAS_LIB 1) # Not needed?
885         endif()
886 # If Qt4: QT_LIBRARIES and QT_INCLUDES are not set above. They require extra magic
887 elseif(QT_FOUND)
888         include(${QT_USE_FILE})
889         include_directories(${QT_INCLUDE_DIR})
890         message(STATUS "Qt includes: ${QT_INCLUDE_DIR}")
891         message(STATUS "Qt libs: ${QT_LIBRARIES}")
892 endif()
893
894 message(STATUS "C-Flags: ${CMAKE_C_FLAGS}")
895 message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS}")
896
897 if(APPLE)
898         #
899         # We assume that APPLE means OS X so that we have the OS X
900         # frameworks.
901         #
902         set(HAVE_OS_X_FRAMEWORKS 1)
903         FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
904         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
905         FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
906 endif()
907
908 include(ConfigureChecks.cmake)
909
910 #Big or little endian ?
911 include(TestBigEndian)
912 test_big_endian(WORDS_BIGENDIAN)
913
914 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
915
916 add_custom_command(
917         OUTPUT  ${CMAKE_BINARY_DIR}/version.h
918         COMMAND ${PERL_EXECUTABLE}
919                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
920                 ${CMAKE_CURRENT_SOURCE_DIR}
921         DEPENDS
922                 ${CMAKE_CURRENT_SOURCE_DIR}/make-version.pl
923 )
924
925 add_custom_target(
926         gitversion ALL
927         DEPENDS ${CMAKE_BINARY_DIR}/version.h
928 )
929 set_target_properties(gitversion PROPERTIES FOLDER "Auxiliary")
930
931 add_subdirectory( asn1 EXCLUDE_FROM_ALL )
932 add_subdirectory( capchild )
933 add_subdirectory( caputils )
934 add_subdirectory( codecs )
935 add_subdirectory( docbook )
936 add_subdirectory( epan )
937 add_subdirectory( tools/lemon )
938 add_subdirectory( ui )
939 add_subdirectory( wiretap )
940 add_subdirectory( wsutil )
941
942 add_dependencies(wsutil gitversion)
943
944 if(NOT WIN32)
945         add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil color.h)
946 endif()
947
948 if(ENABLE_ECHLD)
949         add_subdirectory( echld )
950 endif()
951
952 if(BUILD_wireshark_gtk AND GTK_FOUND)
953         add_subdirectory( ui/gtk )
954 endif()
955
956 if(BUILD_wireshark AND QT_FOUND)
957         add_subdirectory( ui/qt )
958 endif()
959
960 # Location of our data files. This should be set to a value that allows
961 # running from the build directory on Windows, on OS X when building an
962 # application bundle, and on UNIX if WIRESHARK_RUN_FROM_BUILD_DIRECTORY
963 # is set.
964 if(ENABLE_APPLICATION_BUNDLE)
965         set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
966 else()
967         get_target_property(_libwireshark_location epan LOCATION)
968         get_filename_component(_datafile_dir "${_libwireshark_location}" PATH)
969 endif()
970 set (DATAFILE_DIR ${_datafile_dir} CACHE INTERNAL "Build time data file location.")
971
972 if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR})
973   set(ABSOLUTE_CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
974 else()
975   set(ABSOLUTE_CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
976 endif()
977
978 if(ENABLE_EXTCAP)
979         set(HAVE_EXTCAP 1)
980         set(EXTCAP_DIR "${ABSOLUTE_CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/extcap/")
981 endif()
982
983 # Location of our plugins. PLUGIN_DIRECTORY should allow running
984 # from the build directory similar to DATAFILE_DIR above.
985 if(ENABLE_PLUGINS)
986         set(HAVE_PLUGINS 1)
987         add_custom_target(plugins)
988         set_target_properties(plugins PROPERTIES FOLDER "Plugins")
989         set(PLUGIN_INSTALL_DIR "${ABSOLUTE_CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/plugins/${CPACK_PACKAGE_VERSION}")
990         set(PLUGIN_SRC_DIRS
991                 plugins/docsis
992                 plugins/ethercat
993                 plugins/gryphon
994                 plugins/irda
995                 plugins/m2m
996                 plugins/mate
997                 plugins/opcua
998                 plugins/profinet
999                 plugins/stats_tree
1000                 plugins/unistim
1001                 plugins/wimax
1002                 plugins/wimaxasncp
1003                 plugins/wimaxmacphy
1004                 ${CUSTOM_PLUGIN_SRC_DIR}
1005         )
1006 # It seems this stuff doesn't build with autofoo either...
1007 #       if(YAPP_FOUND)
1008 #               set(PLUGIN_SRC_DIRS
1009 #                       ${PLUGIN_SRC_DIRS}
1010 #                       plugins/tpg
1011 #               )
1012 #       endif()
1013 else()
1014         set(PLUGIN_SRC_DIRS )
1015 endif()
1016
1017 if(ENABLE_APPLICATION_BUNDLE)
1018         set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark")
1019 else()
1020         get_target_property(_libwireshark_location epan LOCATION)
1021         get_filename_component(_plugin_dir "${_libwireshark_location}" PATH)
1022         set(_plugin_dir "${_plugin_dir}/plugins")
1023 endif()
1024 # XXX The NMake environment appends the version. Should we do so here?
1025 set (PLUGIN_DIR ${_plugin_dir} CACHE INTERNAL "Build time plugin location.")
1026
1027 foreach(_plugin_src_dir ${PLUGIN_SRC_DIRS})
1028         add_subdirectory( ${_plugin_src_dir} )
1029 endforeach()
1030
1031
1032 # Basedir where to install guides
1033 set(DOC_DIR "$ENV{docdir}" CACHE FILEPATH "Installation directory for ug and dg pdfs.")
1034 message(STATUS "docdir: ${DOC_DIR}")
1035
1036 if(ENABLE_PCAP_NG_DEFAULT)
1037         set(PCAP_NG_DEFAULT 1)
1038 endif()
1039
1040 # Large file support (e.g. make off_t 64 bit if supported)
1041 include(gmxTestLargeFiles)
1042 gmx_test_large_files(GMX_LARGEFILES)
1043
1044 add_definitions( -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\" )
1045
1046 if(WIN32)
1047         set(WS_MSVC_NORETURN "__declspec(noreturn)")
1048
1049         # Disable deprecation
1050         if(MSVC80 OR MSVC90)
1051                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1052         endif()
1053 else()
1054         set(WS_MSVC_NORETURN " ")
1055 endif()
1056
1057 set( VERSION ${PROJECT_VERSION} )
1058 set( configure_input "Built with CMake ${CMAKE_VERSION}" )
1059 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
1060 set(ICON_PATH "${CMAKE_SOURCE_DIR}/image/")
1061 set( IN_FILES
1062         adns_dll.rc
1063         capchild/doxygen.cfg.in
1064         caputils/doxygen.cfg.in
1065         doxygen.cfg.in
1066         doxygen_global.cfg
1067         epan/doxygen.cfg.in
1068         image/libwireshark.rc.in
1069         image/text2pcap.rc.in
1070         image/capinfos.rc.in
1071         image/wireshark.rc.in
1072         image/mergecap.rc.in
1073         image/tshark.rc.in
1074         image/dumpcap.rc.in
1075         image/reordercap.rc.in
1076         image/rawshark.rc.in
1077         image/file_dlg_win32.rc
1078         image/tfshark.rc.in
1079         image/editcap.rc.in
1080         image/captype.rc.in
1081         image/libwsutil.rc.in
1082         image/wiretap.rc.in
1083         image/wireshark.exe.manifest.in
1084         packaging/macosx/Info.plist.in
1085         ${CUSTOM_PLUGIN_IN_FILES}
1086         ui/doxygen.cfg.in
1087         ui/gtk/doxygen.cfg.in
1088         ui/qt/doxygen.cfg.in
1089         wireshark.pc.in
1090 )
1091 foreach( _in_file ${IN_FILES} )
1092         get_filename_component( _path ${_in_file} PATH )
1093         string( REGEX REPLACE "(.*)\\.in" "\\1" _outfile ${_in_file}  )
1094         configure_file( ${CMAKE_SOURCE_DIR}/${_in_file} ${CMAKE_BINARY_DIR}/${_outfile} @ONLY )
1095 endforeach()
1096
1097 include(FeatureSummary)
1098 #SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ])
1099 SET_FEATURE_INFO(SBC "SBC Codec for Bluetooth A2DP stream playing" "www: http://git.kernel.org/cgit/bluetooth/sbc.git" )
1100
1101 FEATURE_SUMMARY(WHAT ALL)
1102
1103 link_directories(
1104         ${CMAKE_BINARY_DIR}/ui
1105         ${CMAKE_BINARY_DIR}/ui/gtk
1106         ${CMAKE_BINARY_DIR}/ui/qt
1107         ${CMAKE_BINARY_DIR}/capchild
1108         ${CMAKE_BINARY_DIR}/caputils
1109         ${CMAKE_BINARY_DIR}/codecs
1110         ${CMAKE_BINARY_DIR}/epan
1111         ${CMAKE_BINARY_DIR}/wiretap
1112         ${CMAKE_BINARY_DIR}/wsutil
1113 )
1114
1115 if(WIN32)
1116         set(PLATFORM_UI_SRC
1117                 ui/win32/console_win32.c
1118                 ui/win32/file_dlg_win32.c
1119                 ui/win32/print_win32.c
1120         )
1121         set(PLATFORM_UI_RC_FILES
1122                 image/file_dlg_win32.rc
1123         )
1124 endif()
1125
1126 # sources common for wireshark, tshark, and rawshark
1127 set(SHARK_COMMON_SRC
1128         cfile.c
1129         frame_tvbuff.c
1130         sync_pipe_write.c
1131 )
1132
1133 # sources for external capture interfaces
1134 if(ENABLE_EXTCAP)
1135         set(SHARK_COMMON_SRC
1136                 ${SHARK_COMMON_SRC}
1137                 extcap.c
1138                 extcap_parser.c
1139         )
1140 endif()
1141
1142 set(TSHARK_TAP_SRC
1143         ui/cli/tap-camelcounter.c
1144         ui/cli/tap-camelsrt.c
1145         ui/cli/tap-comparestat.c
1146         ui/cli/tap-diameter-avp.c
1147         ui/cli/tap-expert.c
1148         ui/cli/tap-endpoints.c
1149         ui/cli/tap-follow.c
1150         ui/cli/tap-funnel.c
1151         ui/cli/tap-gsm_astat.c
1152         ui/cli/tap-h225counter.c
1153         ui/cli/tap-hosts.c
1154         ui/cli/tap-httpstat.c
1155         ui/cli/tap-icmpstat.c
1156         ui/cli/tap-icmpv6stat.c
1157         ui/cli/tap-iostat.c
1158         ui/cli/tap-iousers.c
1159         ui/cli/tap-macltestat.c
1160         ui/cli/tap-protocolinfo.c
1161         ui/cli/tap-protohierstat.c
1162         ui/cli/tap-rlcltestat.c
1163         ui/cli/tap-rpcprogs.c
1164         ui/cli/tap-rtd.c
1165         ui/cli/tap-rtp.c
1166         ui/cli/tap-rtspstat.c
1167         ui/cli/tap-sctpchunkstat.c
1168         ui/cli/tap-simple_stattable.c
1169         ui/cli/tap-sipstat.c
1170         ui/cli/tap-smbsids.c
1171         ui/cli/tap-srt.c
1172         ui/cli/tap-stats_tree.c
1173         ui/cli/tap-sv.c
1174         ui/cli/tap-wspstat.c
1175 )
1176
1177 set(INSTALL_DIRS
1178         diameter
1179         dtds
1180         help
1181         radius
1182         tpncp
1183         wimaxasncp
1184 )
1185
1186 set(INSTALL_FILES
1187         ${CMAKE_BINARY_DIR}/androiddump.html
1188         ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
1189         ${CMAKE_BINARY_DIR}/capinfos.html
1190         ${CMAKE_BINARY_DIR}/captype.html
1191         cfilters
1192         colorfilters
1193         dfilters
1194         ${CMAKE_BINARY_DIR}/dftest.html
1195         ${CMAKE_BINARY_DIR}/dumpcap.html
1196         ${CMAKE_BINARY_DIR}/editcap.html
1197         ${CMAKE_BINARY_DIR}/extcap.html
1198         ${CMAKE_BINARY_DIR}/asn2deb.html
1199         ${CMAKE_BINARY_DIR}/idl2deb.html
1200         ${CMAKE_BINARY_DIR}/idl2wrs.html
1201         ipmap.html
1202         manuf
1203         ${CMAKE_BINARY_DIR}/mergecap.html
1204         pdml2html.xsl
1205         ${CMAKE_BINARY_DIR}/randpkt.html
1206         ${CMAKE_BINARY_DIR}/rawshark.html
1207         ${CMAKE_BINARY_DIR}/reordercap.html
1208         services
1209         smi_modules
1210         ${CMAKE_BINARY_DIR}/text2pcap.html
1211         ${CMAKE_BINARY_DIR}/tshark.html
1212         ${CMAKE_BINARY_DIR}/wireshark-filter.html
1213         ${CMAKE_BINARY_DIR}/wireshark.html
1214         docbook/ws.css
1215 )
1216
1217 if(WIN32)
1218         set(TEXTIFY_FILES COPYING NEWS README README.windows)
1219         foreach(_text_file ${TEXTIFY_FILES})
1220                 set(INSTALL_FILES ${CMAKE_BINARY_DIR}/${_text_file}.txt ${INSTALL_FILES})
1221         endforeach()
1222 else()
1223         set(INSTALL_FILES COPYING ${INSTALL_FILES})
1224 endif()
1225
1226 set(MAN1_FILES
1227         ${CMAKE_BINARY_DIR}/androiddump.1
1228         ${CMAKE_BINARY_DIR}/capinfos.1
1229         ${CMAKE_BINARY_DIR}/captype.1
1230         ${CMAKE_BINARY_DIR}/dftest.1
1231         ${CMAKE_BINARY_DIR}/dumpcap.1
1232         ${CMAKE_BINARY_DIR}/editcap.1
1233         ${CMAKE_BINARY_DIR}/extcap.4
1234         ${CMAKE_BINARY_DIR}/idl2wrs.1
1235         ${CMAKE_BINARY_DIR}/mergecap.1
1236         ${CMAKE_BINARY_DIR}/randpkt.1
1237         ${CMAKE_BINARY_DIR}/rawshark.1
1238         ${CMAKE_BINARY_DIR}/reordercap.1
1239         ${CMAKE_BINARY_DIR}/text2pcap.1
1240         ${CMAKE_BINARY_DIR}/tshark.1
1241         ${CMAKE_BINARY_DIR}/wireshark.1
1242 )
1243
1244 set(MAN4_FILES
1245         ${CMAKE_BINARY_DIR}/wireshark-filter.4
1246 )
1247
1248 set(LIBEPAN_LIBS
1249 #               @NSL_LIBS@      # -lnsl
1250 #               @SOCKET_LIBS@   # -lsocket
1251 #               @SSL_LIBS@      # -lcrypto
1252                 epan
1253 #               $(plugin_ldadd) # in case of static
1254                 ${AIRPCAP_LIBRARIES}
1255                 ${PCAP_LIBRARIES}
1256                 ${CARES_LIBRARIES}
1257                 ${ADNS_LIBRARIES}
1258                 ${KERBEROS_LIBRARIES}
1259                 ${LUA_LIBRARIES}
1260                 ${PYTHON_LIBRARIES}
1261                 ${GEOIP_LIBRARIES}
1262                 ${GCRYPT_LIBRARIES}
1263                 ${GNUTLS_LIBRARIES}
1264                 ${SMI_LIBRARIES}
1265                 ${ZLIB_LIBRARIES}
1266                 ${M_LIBRARIES}
1267                 ${SBC_LIBRARIES}
1268                 ${WINSPARKLE_LIBRARIES}
1269 )
1270
1271 if(WIN32)
1272         # According to http://stackoverflow.com/questions/14474659/cmake-how-to-have-a-target-for-copying-files
1273         # we can't just use "set(_dll_output_dir "$<TARGET_FILE_DIR:epan>")"
1274         # DATAFILE_DIR is set using the same property. We could probably
1275         # get away with using it here.
1276         get_target_property(_libwireshark_location epan LOCATION)
1277         get_filename_component(_dll_output_dir "${_libwireshark_location}" PATH)
1278         add_custom_target(copy_cli_dlls)
1279         set_target_properties(copy_cli_dlls PROPERTIES FOLDER "Copy Tasks")
1280         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1281                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
1282         )
1283
1284         # XXX Can (and should) we iterate over these similar to the way
1285         # the top-level CMakeLists.txt iterates over the package list?
1286
1287         # Required DLLs.
1288         # The cairo, freetype, gio, gnutls, png, and other OBS-generated DLLs
1289         # depend on zlib1.dll. We compile zlib locally but the Debug
1290         # configuration (the default) creates zlibd1.dll.
1291         file (TO_NATIVE_PATH "${_dll_output_dir}" _dll_output_dir_win )
1292         foreach( _dll ${GLIB2_DLLS} $<$<CONFIG:Debug>:zlib1.dll> )
1293                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1294                         # It would be really handy if copy, xcopy, or "cmake
1295                         # -E copy_if_different" supported multiple files
1296                         # separated by whitespace, or if robocpy had a sane
1297                         # notion of exit codes.
1298                         COMMAND if exist \"${_dll}\" xcopy ${_dll} "${_dll_output_dir_win}" /D /Y
1299                         WORKING_DIRECTORY "${GLIB2_DLL_DIR}"
1300                 )
1301         endforeach(_dll)
1302
1303
1304         # Don't overwrite an exe if it's already there. We don't want to
1305         # clobber any previous code signing.
1306         file(GLOB _gspawn_helpers
1307                 RELATIVE "${GLIB2_DLL_DIR}"
1308                 "${GLIB2_DLL_DIR}/gspawn*.exe"
1309         )
1310         foreach(_gspawn_helper ${_gspawn_helpers})
1311                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1312                         COMMAND if not exist \"${_dll_output_dir_win}\\${_gspawn_helper}\" xcopy ${_gspawn_helper} "${_dll_output_dir_win}" /D /Y
1313                         WORKING_DIRECTORY "${GLIB2_DLL_DIR}"
1314                 )
1315         endforeach()
1316
1317         # Optional
1318         if (AIRPCAP_FOUND)
1319                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1320                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1321                                 "${AIRPCAP_DLL_DIR}/${AIRPCAP_DLL}"
1322                                 "${_dll_output_dir}"
1323                 )
1324         endif(AIRPCAP_FOUND)
1325         if (CARES_FOUND)
1326                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1327                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1328                                 "${CARES_DLL_DIR}/${CARES_DLL}"
1329                                 "${_dll_output_dir}"
1330                 )
1331         endif(CARES_FOUND)
1332         if (GEOIP_FOUND)
1333                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1334                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1335                                 "${GEOIP_DLL_DIR}/${GEOIP_DLL}"
1336                                 "${_dll_output_dir}"
1337                 )
1338         endif(GEOIP_FOUND)
1339         if(GCRYPT_FOUND)
1340                 foreach( _dll ${GCRYPT_DLLS} )
1341                         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1342                                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1343                                         "${GCRYPT_DLL_DIR}/${_dll}"
1344                                         "${_dll_output_dir}"
1345                         )
1346                 endforeach(_dll)
1347         endif(GCRYPT_FOUND)
1348         if(GNUTLS_FOUND)
1349                 foreach( _dll ${GNUTLS_DLLS} )
1350                         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1351                                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1352                                         "${GNUTLS_DLL_DIR}/${_dll}"
1353                                         "${_dll_output_dir}"
1354                         )
1355                 endforeach(_dll)
1356         endif(GNUTLS_FOUND)
1357         if(KERBEROS_FOUND)
1358                 foreach( _dll ${KERBEROS_DLLS} )
1359                         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1360                                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1361                                         "${KERBEROS_DLL_DIR}/${_dll}"
1362                                         "${_dll_output_dir}"
1363                         )
1364                 endforeach(_dll)
1365         endif(KERBEROS_FOUND)
1366         if (LUA_FOUND)
1367                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1368                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1369                                 "${LUA_DLL_DIR}/${LUA_DLL}"
1370                                 "${_dll_output_dir}"
1371                 )
1372         endif(LUA_FOUND)
1373         if (SMI_FOUND)
1374                 # Wireshark.nsi wants SMI_DIR which is the base SMI directory
1375                 get_filename_component(SMI_DIR ${SMI_DLL_DIR} DIRECTORY)
1376                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1377                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1378                                 "${SMI_DLL_DIR}/${SMI_DLL}"
1379                                 "${_dll_output_dir}"
1380                         COMMAND ${CMAKE_COMMAND} -E make_directory
1381                                 "${_dll_output_dir}/snmp"
1382                         COMMAND ${CMAKE_COMMAND} -E make_directory
1383                                 "${_dll_output_dir}/snmp/mibs"
1384                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1385                                 "${SMI_SHARE_DIR}/${SMI_DLL}/mibs/iana"
1386                                 "${_dll_output_dir}/snmp/mibs"
1387                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1388                                 "${SMI_SHARE_DIR}/${SMI_DLL}/mibs/ietf"
1389                                 "${_dll_output_dir}/snmp/mibs"
1390                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1391                                 "${SMI_SHARE_DIR}/${SMI_DLL}/mibs/irtf"
1392                                 "${_dll_output_dir}/snmp/mibs"
1393                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1394                                 "${SMI_SHARE_DIR}/${SMI_DLL}/mibs/site"
1395                                 "${_dll_output_dir}/snmp/mibs"
1396                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1397                                 "${SMI_SHARE_DIR}/${SMI_DLL}/mibs/tubs"
1398                                 "${_dll_output_dir}/snmp/mibs"
1399                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1400                                 "${SMI_SHARE_DIR}/${SMI_DLL}/pibs"
1401                                 "${_dll_output_dir}/snmp/mibs"
1402                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1403                                 "${SMI_SHARE_DIR}/${SMI_DLL}/yang"
1404                                 "${_dll_output_dir}/snmp/mibs"
1405                 )
1406         endif(SMI_FOUND)
1407         if (WINSPARKLE_FOUND)
1408                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1409                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1410                                 "${WINSPARKLE_DLL_DIR}/${WINSPARKLE_DLL}"
1411                                 "${_dll_output_dir}"
1412                 )
1413         endif(WINSPARKLE_FOUND)
1414
1415         add_dependencies(epan copy_cli_dlls)
1416
1417         # We have a lot of choices for creating zip archives:
1418         # - 7z, WinZip, etc., which require a separate download+install.
1419         # - Cygwin's zip, which requires Cygwin.
1420         # - "CMake -E tar cz", which creates a tar file.
1421         # - CPack, which requires a CPack configuration.
1422         # - PowerShell via PSCX or System.IO.Compression.FileSystem.
1423         # - Python via zipfile.
1424         # For now, just look for 7z. It's installed on the Windows builders,
1425         # which might be the only systems that use this target.
1426         find_program(ZIP_EXECUTABLE 7z
1427                 PATH "$ENV{PROGRAMFILES}/7-Zip" "$ENV{PROGRAMW6432}/7-Zip"
1428                 DOC "Path to the 7z utility."
1429         )
1430         # XXX "if(ZIP_EXECUTABLE)" doesn't work here. It looks like the
1431         # absence of "-NOTFOUND" doesn't equal "true".
1432         if (NOT "${ZIP_EXECUTABLE}" STREQUAL "ZIP_EXECUTABLE-NOTFOUND")
1433                 add_custom_target(pdb_zip_package)
1434                 set_target_properties(pdb_zip_package PROPERTIES FOLDER "Packaging")
1435                 set(_pdb_zip "${CMAKE_BINARY_DIR}/Wireshark-pdb-${WIRESHARK_TARGET_PLATFORM}-${VERSION}.zip")
1436                 file(TO_NATIVE_PATH "${_pdb_zip}" _pdb_zip_win)
1437                 add_custom_command(TARGET pdb_zip_package POST_BUILD
1438                         COMMAND ${CMAKE_COMMAND} -E remove -f "${_pdb_zip}"
1439                         COMMAND ${ZIP_EXECUTABLE} a -tzip -mmt=on "${_pdb_zip_win}" *.pdb *.lib
1440                         WORKING_DIRECTORY "${_dll_output_dir}"
1441                 )
1442                 add_dependencies(pdb_zip_package epan)
1443         endif()
1444 endif(WIN32)
1445
1446 # Copy ${INSTALL_FILES} and ${INSTALL_DIRS} to ${DATAFILE_DIR}
1447 add_custom_target(copy_data_files ALL DEPENDS ${INSTALL_FILES})
1448 set_target_properties(copy_data_files PROPERTIES FOLDER "Copy Tasks")
1449 add_dependencies(copy_data_files html_docs)
1450 if(ENABLE_APPLICATION_BUNDLE)
1451         add_custom_command(TARGET copy_data_files PRE_BUILD
1452                 COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}"
1453         )
1454 endif()
1455
1456 if(WIN32)
1457         foreach(_text_file ${TEXTIFY_FILES})
1458                 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_text_file}.txt
1459                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1460                                 -Destination ${CMAKE_BINARY_DIR}
1461                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1462                         DEPENDS
1463                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1464                 )
1465         endforeach()
1466 endif()
1467
1468 foreach(_install_file ${INSTALL_FILES})
1469         get_filename_component(_install_basename "${_install_file}" NAME)
1470         add_custom_command(TARGET copy_data_files POST_BUILD
1471                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1472                         "${_install_file}"
1473                         "${DATAFILE_DIR}/${_install_basename}"
1474                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1475         )
1476 endforeach()
1477
1478 if(ENABLE_EXTCAP)
1479         add_custom_command(TARGET copy_data_files PRE_BUILD
1480                 COMMAND ${CMAKE_COMMAND} -E make_directory
1481                         "${DATAFILE_DIR}/extcap"
1482         )
1483 endif()
1484 add_custom_command(TARGET copy_data_files PRE_BUILD
1485         COMMAND ${CMAKE_COMMAND} -E make_directory
1486                 "${DATAFILE_DIR}/help"
1487 )
1488 add_custom_command(TARGET copy_data_files PRE_BUILD
1489         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1490                 "${CMAKE_SOURCE_DIR}/help/toc"
1491                 "${DATAFILE_DIR}/help/toc"
1492 )
1493 if(WIN32)
1494         file(TO_NATIVE_PATH ${DATAFILE_DIR}/help _help_dest_dir)
1495         add_custom_command(TARGET copy_data_files PRE_BUILD
1496                 COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1497                         -Destination ${_help_dest_dir}
1498                         ${CMAKE_SOURCE_DIR}/help/*.txt
1499         )
1500 else()
1501         file(GLOB _help_files
1502                 "${CMAKE_SOURCE_DIR}/help/*.txt"
1503         )
1504         foreach(_help_file ${_help_files})
1505                 add_custom_command(TARGET copy_data_files PRE_BUILD
1506                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1507                                 "${_help_file}"
1508                                 "${DATAFILE_DIR}/help/"
1509                 )
1510         endforeach()
1511 endif(WIN32)
1512 add_custom_command(TARGET copy_data_files PRE_BUILD
1513         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/help/faq.py -b > faq.tmp.html
1514         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
1515                 faq.tmp.html > "${DATAFILE_DIR}/help/faq.txt"
1516         COMMAND ${CMAKE_COMMAND} -E remove faq.tmp.html
1517 )
1518
1519 if(LUA_FOUND)
1520         add_custom_command(TARGET copy_data_files PRE_BUILD
1521                 COMMAND ${CMAKE_COMMAND} -E make_directory
1522                         "${DATAFILE_DIR}/lua"
1523         )
1524         add_custom_command(TARGET copy_data_files PRE_BUILD
1525                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1526                         "${CMAKE_BINARY_DIR}/epan/wslua/init.lua"
1527                         "${DATAFILE_DIR}"
1528         )
1529         add_custom_command(TARGET copy_data_files PRE_BUILD
1530                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1531                         "${CMAKE_SOURCE_DIR}/epan/wslua/console.lua"
1532                         "${DATAFILE_DIR}"
1533         )
1534         add_custom_command(TARGET copy_data_files PRE_BUILD
1535                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1536                         "${CMAKE_SOURCE_DIR}/epan/wslua/dtd_gen.lua"
1537                         "${DATAFILE_DIR}"
1538         )
1539         add_dependencies(copy_data_files wsluaauxiliary)
1540 endif(LUA_FOUND)
1541 # doc/*.html handled elsewhere.
1542 add_custom_command(TARGET copy_data_files PRE_BUILD
1543         COMMAND ${CMAKE_COMMAND} -E copy_directory
1544                 "${CMAKE_SOURCE_DIR}/dtds"
1545                 "${DATAFILE_DIR}/dtds"
1546 )
1547 # Skipping asn1 default.tt
1548 add_custom_command(TARGET copy_data_files PRE_BUILD
1549         COMMAND ${CMAKE_COMMAND} -E copy_directory
1550                 "${CMAKE_SOURCE_DIR}/radius"
1551                 "${DATAFILE_DIR}/radius"
1552 )
1553 add_custom_command(TARGET copy_data_files PRE_BUILD
1554         COMMAND ${CMAKE_COMMAND} -E make_directory
1555                 "${DATAFILE_DIR}/diameter"
1556 )
1557 file(GLOB _diameter_files
1558         "${CMAKE_SOURCE_DIR}/diameter/*.dtd"
1559         "${CMAKE_SOURCE_DIR}/diameter/*.xml"
1560 )
1561 foreach(_diameter_file ${_diameter_files})
1562         add_custom_command(TARGET copy_data_files PRE_BUILD
1563                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1564                         "${_diameter_file}"
1565                         "${DATAFILE_DIR}/diameter/"
1566         )
1567 endforeach()
1568 add_custom_command(TARGET copy_data_files PRE_BUILD
1569         COMMAND ${CMAKE_COMMAND} -E copy_directory
1570                 "${CMAKE_SOURCE_DIR}/profiles"
1571                 "${DATAFILE_DIR}/profiles"
1572 )
1573 add_custom_command(TARGET copy_data_files PRE_BUILD
1574         COMMAND ${CMAKE_COMMAND} -E make_directory
1575                 "${DATAFILE_DIR}/tpncp"
1576 )
1577 add_custom_command(TARGET copy_data_files PRE_BUILD
1578         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1579                 "${CMAKE_SOURCE_DIR}/tpncp/tpncp.dat"
1580                 "${DATAFILE_DIR}/tpncp/tpncp.dat"
1581 )
1582 add_custom_command(TARGET copy_data_files PRE_BUILD
1583         COMMAND ${CMAKE_COMMAND} -E copy_directory
1584                 "${CMAKE_SOURCE_DIR}/wimaxasncp"
1585                 "${DATAFILE_DIR}/wimaxasncp"
1586 )
1587
1588 if( (BUILD_wireshark AND QT_FOUND) OR (BUILD_wireshark_gtk AND GTK_FOUND) )
1589         set(WIRESHARK_SRC
1590                 capture_info.c
1591                 capture_opts.c
1592                 color_filters.c
1593                 file.c
1594                 fileset.c
1595                 summary.c
1596                 ${SHARK_COMMON_SRC}
1597                 ${PLATFORM_UI_SRC}
1598         )
1599         set(wireshark_FILES
1600                 ${WIRESHARK_SRC}
1601                 ${CMAKE_BINARY_DIR}/image/wireshark.rc
1602                 ${PLATFORM_UI_RC_FILES}
1603         )
1604 endif()
1605
1606 if(ENABLE_APPLICATION_BUNDLE)
1607         #
1608         # Add -Wl,-single_module to the LDFLAGS used with shared
1609         # libraries, to fix some error that show up in some cases;
1610         # some Apple documentation recommends it for most shared
1611         # libraries.
1612         #
1613         set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-single_module ${CMAKE_SHARED_LINKER_FLAGS}" )
1614         #
1615         # Add -Wl,-headerpad_max_install_names to the LDFLAGS, as
1616         # code-signing issues is running out of padding space.
1617         #
1618         # Add -Wl,-search_paths_first to make sure that if we search
1619         # directories A and B, in that order, for a given library, a
1620         # non-shared version in directory A, rather than a shared
1621         # version in directory B, is chosen (so we can use
1622         # --with-pcap=/usr/local to force all programs to be linked
1623         # with a static version installed in /usr/local/lib rather than
1624         # the system version in /usr/lib).
1625         #
1626
1627         set(CMAKE_EXE_LINKER_FLAGS
1628         "-Wl,-headerpad_max_install_names -Wl,-search_paths_first ${CMAKE_EXE_LINKER_FLAGS}"
1629         )
1630
1631         # Add files to the app bundle
1632         # Wireshark.app/Contents
1633         file(WRITE ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo "APPLWshk\n")
1634         set(BUNDLE_CONTENTS_FILES
1635                 ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo
1636         )
1637         set_source_files_properties(${BUNDLE_CONTENTS_FILES} PROPERTIES
1638                 MACOSX_PACKAGE_LOCATION .
1639         )
1640
1641         # Wireshark.app/Contents/Resources
1642         set(BUNDLE_RESOURCE_FILES
1643                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Resources/Wireshark.icns
1644                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Resources/Wiresharkdoc.icns
1645         )
1646         set_source_files_properties(${BUNDLE_RESOURCE_FILES} PROPERTIES
1647                 MACOSX_PACKAGE_LOCATION Resources
1648         )
1649
1650         # Wireshark.app/Contents/Resources/share/man/man1
1651         set(BUNDLE_RESOURCE_SHARE_MAN1_FILES ${MAN1_FILES})
1652         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN1_FILES} PROPERTIES
1653                 MACOSX_PACKAGE_LOCATION Resources/share/man/man1
1654         )
1655
1656         # Wireshark.app/Contents/Resources/share/man/man1
1657         set(BUNDLE_RESOURCE_SHARE_MAN4_FILES ${MAN4_FILES})
1658         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN4_FILES} PROPERTIES
1659                 MACOSX_PACKAGE_LOCATION Resources/share/man/man4
1660         )
1661
1662         # INSTALL_FILES and INSTALL_DIRS are handled by copy_data_files
1663
1664         set(EXTRA_BUNDLE_FILES
1665                 ${BUNDLE_CONTENTS_FILES}
1666                 ${BUNDLE_RESOURCE_FILES}
1667                 ${BUNDLE_RESOURCE_SHARE_MAN1_FILES}
1668                 ${BUNDLE_RESOURCE_SHARE_MAN4_FILES}
1669         )
1670 else()
1671         set(EXTRA_BUNDLE_FILES)
1672 endif()
1673
1674 if(BUILD_wireshark AND QT_FOUND)
1675         set(wireshark_LIBS
1676                 qtui
1677                 ui
1678                 capchild
1679                 caputils
1680                 ${QT_LIBRARIES}
1681                 ${GTHREAD2_LIBRARIES}
1682                 codecs
1683                 ${LIBEPAN_LIBS}
1684                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
1685                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1686                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1687                 ${NL_LIBRARIES}
1688         )
1689         # wireshark and wireshark-gtk share wireshark_FILES
1690         add_dependencies(qtui gitversion)
1691
1692         # Policy since 2.8.11
1693         if (POLICY CMP0020)
1694                 cmake_policy(SET CMP0020 NEW)
1695         endif()
1696
1697         add_executable(wireshark WIN32 MACOSX_BUNDLE wireshark-qt.cpp ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
1698         set(PROGLIST ${PROGLIST} wireshark)
1699         set_target_properties(wireshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1700         set_target_properties(wireshark PROPERTIES FOLDER "Executables")
1701         if(ENABLE_APPLICATION_BUNDLE OR WIN32)
1702                 set_target_properties(wireshark PROPERTIES OUTPUT_NAME Wireshark)
1703         endif()
1704
1705         if(ENABLE_APPLICATION_BUNDLE)
1706                 set_target_properties(
1707                         wireshark PROPERTIES
1708                                 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/Info.plist
1709                 )
1710                 # Add a wrapper script which opens the bundle. This adds
1711                 # convenience but makes debugging more difficult.
1712                 file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
1713                 file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
1714                 file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "open ${CMAKE_BINARY_DIR}/run/Wireshark.app --args \"\$\@\"\n")
1715                 execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
1716         endif()
1717
1718         target_link_libraries(wireshark ${wireshark_LIBS})
1719         install(
1720                 TARGETS wireshark
1721                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1722                 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1723         )
1724
1725         if(NOT ENABLE_APPLICATION_BUNDLE)
1726                 # Map for endpoints dialog
1727                 ADD_CUSTOM_COMMAND(
1728                         TARGET wireshark
1729                         POST_BUILD
1730                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1731                                 "${PROJECT_SOURCE_DIR}/ipmap.html"
1732                                 $<TARGET_FILE_DIR:wireshark>
1733                 )
1734         endif()
1735
1736         if(WIN32 AND Qt5Core_FOUND)
1737                 # Use windeployqt to copy our required DLLs to the run path.
1738                 # Ideally one of the modules in ${QTDIR}/lib/cmake would expose
1739                 # the path to windeployqt. For that matter having a reliable
1740                 # path to qmake would be *amazingly convenient*. We don't have
1741                 # either of those so we try to discover the path via Qt5Core.
1742                 # http://stackoverflow.com/questions/24650936/qt5-with-cmake-how-to-find-qt-translations-dir
1743
1744                 get_target_property(_qmake_location Qt5::qmake IMPORTED_LOCATION)
1745                 get_filename_component(_qt_bin_path "${_qmake_location}" DIRECTORY)
1746                 find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt
1747                         HINTS "${_qmake_location}"
1748                         DOC "Path to the windeployqt utility."
1749                 )
1750                 if (NOT "${QT_WINDEPLOYQT_EXECUTABLE}" STREQUAL "QT_WINDEPLOYQT_EXECUTABLE-NOTFOUND")
1751                         set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL
1752                                 "Path to qmake, windeployqt, and other Qt utilities."
1753                         )
1754                         add_custom_target(copy_qt_dlls ALL)
1755                         set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks")
1756                         # Will we ever need to use --debug? Windeployqt seems to
1757                         # be smart enough to copy debug DLLs when needed.
1758                         add_custom_command(TARGET copy_qt_dlls
1759                                 POST_BUILD
1760                                 COMMAND set "PATH=%PATH%;${QT_BIN_PATH}"
1761                                 COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}"
1762                                         $<$<CONFIG:Debug>:--debug>
1763                                         $<$<NOT:$<CONFIG:Debug>>:--release>
1764                                         --no-compiler-runtime
1765                                         "$<TARGET_FILE:wireshark>"
1766                         )
1767                         add_dependencies(copy_qt_dlls wireshark)
1768                 endif()
1769         endif(WIN32 AND Qt5Core_FOUND)
1770 endif()
1771
1772 # Common properties for CLI executables
1773 macro(set_extra_executable_properties _executable _folder)
1774         set_target_properties(${_executable} PROPERTIES
1775                 LINK_FLAGS "${WS_LINK_FLAGS}"
1776                 FOLDER ${_folder}
1777         )
1778
1779         set(PROGLIST ${PROGLIST} ${_executable})
1780
1781         if(ENABLE_APPLICATION_BUNDLE)
1782                 set_target_properties(${_executable} PROPERTIES
1783                         RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
1784                 )
1785                 # Add a wrapper script which runs each executable from the
1786                 # correct location. This adds convenience but makes debugging
1787                 # more difficult.
1788                 file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
1789                 file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
1790                 file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/${_executable} \"\$\@\"\n")
1791                 execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
1792         endif()
1793 endmacro()
1794
1795 macro(set_extcap_executable_properties _executable)
1796         set_target_properties(androiddump PROPERTIES FOLDER "Executables/Extcaps")
1797
1798         set(PROGLIST ${PROGLIST} ${_executable})
1799
1800         if(WIN32)
1801                 set_target_properties(${_executable} PROPERTIES
1802                         LINK_FLAGS "${WS_LINK_FLAGS}"
1803                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
1804                         RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/run/Debug/extcap
1805                         RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/run/Release/extcap
1806                         RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/run/MinSizeRel/extcap
1807                         RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/run/RelWithDebInfo/extcap
1808                 )
1809         else()
1810                 set_target_properties(${_executable} PROPERTIES
1811                         LINK_FLAGS "${WS_LINK_FLAGS}"
1812                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
1813                 )
1814                 if(ENABLE_APPLICATION_BUNDLE)
1815                         set_target_properties(${_executable} PROPERTIES
1816                                 RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS/extcap
1817                         )
1818                         # Add a wrapper script which runs each executable from the
1819                         # correct location. This adds convenience but makes debugging
1820                         # more difficult.
1821                         file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
1822                         file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
1823                         file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/extcap/${_executable} \"\$\@\"\n")
1824                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
1825                 endif()
1826         endif()
1827 endmacro()
1828
1829 if(BUILD_wireshark_gtk AND GTK_FOUND)
1830         set(wireshark_gtk_LIBS
1831                 gtkui
1832                 ui
1833                 capchild
1834                 caputils
1835                 ${GTK2_LIBRARIES}
1836                 ${GTK3_LIBRARIES}
1837                 ${GTHREAD2_LIBRARIES}
1838                 codecs
1839                 ${PORTAUDIO_LIBRARIES}
1840                 ${LIBEPAN_LIBS}
1841                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
1842                 ${APPLE_CORE_SERVICES_LIBRARY}
1843                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1844                 ${NL_LIBRARIES}
1845                 ${WIN_COMCTL32_LIBRARY}
1846         )
1847         # wireshark and wireshark-gtk share wireshark_FILES
1848
1849         add_executable(wireshark-gtk WIN32 ${wireshark_FILES})
1850         set(PROGLIST ${PROGLIST} wireshark-gtk)
1851         set_target_properties(wireshark-gtk PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
1852         set_target_properties(wireshark-gtk PROPERTIES FOLDER "Executables")
1853         target_link_libraries(wireshark-gtk ${wireshark_gtk_LIBS})
1854         install(TARGETS wireshark-gtk RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1855
1856         # Map for endpoints dialog
1857         ADD_CUSTOM_COMMAND(
1858                 TARGET wireshark-gtk
1859                 POST_BUILD
1860                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1861                         "${PROJECT_SOURCE_DIR}/ipmap.html"
1862                         $<TARGET_FILE_DIR:wireshark-gtk>
1863         )
1864
1865         if(WIN32)
1866                 get_target_property(_wsgtk_location wireshark-gtk LOCATION)
1867                 get_filename_component(_dll_output_dir "${_wsgtk_location}" PATH)
1868                 add_custom_target(copy_gtk_dlls)
1869                 set_target_properties(copy_gtk_dlls PROPERTIES FOLDER "Copy Tasks")
1870                 add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1871                         COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
1872                 )
1873
1874                 if(GTK2_FOUND)
1875                         set(_gtk_dll_dir "${GTK2_DLL_DIR}")
1876                         set(_gtk_etc_dir "${GTK2_ETC_DIR}")
1877                         set(_gtk_dlls "${GTK2_DLLS}")
1878                         set(_gtk_etc_dir "${GTK2_ETC_DIR}")
1879                 else()
1880                         set(_gtk_dll_dir "${GTK3_DLL_DIR}")
1881                         set(_gtk_dlls "${GTK3_DLLS}")
1882                         set(_gtk_etc_dir "${GTK3_ETC_DIR}")
1883                 endif()
1884
1885                 foreach(_dll ${_gtk_dlls})
1886                         add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1887                                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1888                                         "${_gtk_dll_dir}/${_dll}" "${_dll_output_dir}"
1889                         )
1890                 endforeach(_dll)
1891
1892                 # /etc
1893                 add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1894                         COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}/etc"
1895                 )
1896                 add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1897                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1898                                 "${_gtk_etc_dir}" "${_dll_output_dir}/etc"
1899                 )
1900
1901                 # XXX - Omitting ${GTK2_LIB_DIR}\loaders copying from Makefile.nmake
1902                 if(GTK2_FOUND)
1903                         # Engines
1904                         set (_engines_output_dir "${_dll_output_dir}/lib/gtk-2.0/2.10.0/engines")
1905                         add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1906                                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_engines_output_dir}"
1907                         )
1908                         foreach(_dll ${GTK2_ENGINES_DLLS})
1909                                 add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1910                                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1911                                                 "${GTK2_ENGINES_DLL_DIR}/${_dll}" "${_engines_output_dir}"
1912                                 )
1913                         endforeach(_dll)
1914
1915                         # Themes
1916                         add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1917                                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1918                                         "${GTK2_THEMES_DIR}/gtkrc" "${_dll_output_dir}/etc/gtk-2.0"
1919                         )
1920
1921                         # Modules
1922                         add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1923                                 COMMAND ${CMAKE_COMMAND} -E copy_directory
1924                                         "${GTK2_LIB_DIR}" "${_dll_output_dir}/lib/gtk-2.0"
1925                         )
1926                 else()
1927                         add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
1928                                 COMMAND ${CMAKE_COMMAND} -E copy_directory
1929                                         "${CMAKE_SOURCE_DIR}/ui/win32/settings.ini" "${_dll_output_dir}/etc"
1930                         )
1931                 endif()
1932
1933                 add_dependencies(wireshark-gtk copy_gtk_dlls copy_cli_dlls)
1934         endif(WIN32)
1935 endif()
1936
1937 register_tap_files(tshark-tap-register.c
1938         tshark-taps
1939         ${TSHARK_TAP_SRC}
1940 )
1941
1942 if(BUILD_tshark)
1943         set(tshark_LIBS
1944                 ui
1945                 capchild
1946                 caputils
1947                 ${LIBEPAN_LIBS}
1948                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1949                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1950         )
1951         set(tshark_FILES
1952                 capture_opts.c
1953                 tshark-tap-register.c
1954                 tshark.c
1955                 ${TSHARK_TAP_SRC}
1956                 ${SHARK_COMMON_SRC}
1957                 ${CMAKE_BINARY_DIR}/image/tshark.rc
1958         )
1959         add_executable(tshark ${tshark_FILES})
1960         set_extra_executable_properties(tshark "Executables")
1961         target_link_libraries(tshark ${tshark_LIBS})
1962         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1963 endif()
1964
1965 if(BUILD_tfshark)
1966         set(tfshark_LIBS
1967                 ui
1968                 ${LIBEPAN_LIBS}
1969                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1970                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1971         )
1972         set(tfshark_FILES
1973                 tfshark.c
1974                 ${TSHARK_TAP_SRC}
1975                 ${SHARK_COMMON_SRC}
1976                 ${CMAKE_BINARY_DIR}/image/tfshark.rc
1977         )
1978         add_executable(tfshark ${tfshark_FILES})
1979         set_extra_executable_properties(tfshark "Executables")
1980         target_link_libraries(tfshark ${tfshark_LIBS})
1981         install(TARGETS tfshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1982 endif()
1983
1984 if(BUILD_rawshark AND PCAP_FOUND)
1985         set(rawshark_LIBS
1986                 caputils
1987                 ${LIBEPAN_LIBS}
1988                 ${APPLE_CORE_FOUNDATION_LIBRARY}
1989                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
1990         )
1991         set(rawshark_FILES
1992                 ${SHARK_COMMON_SRC}
1993                 rawshark.c
1994                 ui/util.c
1995                 ${CMAKE_BINARY_DIR}/image/rawshark.rc
1996         )
1997         add_executable(rawshark ${rawshark_FILES})
1998         set_extra_executable_properties(rawshark "Executables")
1999         target_link_libraries(rawshark ${rawshark_LIBS})
2000         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2001 endif()
2002
2003 if(BUILD_dftest)
2004         set(dftest_LIBS
2005                 ${LIBEPAN_LIBS}
2006         )
2007         set(dftest_FILES
2008                 dftest.c
2009                 ui/util.c
2010         )
2011         add_executable(dftest ${dftest_FILES})
2012         set_extra_executable_properties(dftest "Tests")
2013         target_link_libraries(dftest ${dftest_LIBS})
2014         install(TARGETS dftest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2015 endif()
2016
2017 if(BUILD_randpkt)
2018         set(randpkt_LIBS
2019                 wiretap
2020                 wsutil
2021                 ${M_LIBRARIES}
2022                 ${PCAP_LIBRARIES}
2023 #               @SOCKET_LIBS@
2024 #               @NSL_LIBS@
2025                 ${CARES_LIBRARIES}
2026                 ${ADNS_LIBRARIES}
2027                 ${ZLIB_LIBRARIES}
2028         )
2029         set(randpkt_FILES
2030                 randpkt.c
2031         )
2032         add_executable(randpkt ${randpkt_FILES})
2033         set_extra_executable_properties(randpkt "Executables")
2034         target_link_libraries(randpkt ${randpkt_LIBS})
2035         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2036 endif()
2037
2038 if(BUILD_text2pcap)
2039         set(text2pcap_LIBS
2040                 wsutil
2041                 ${M_LIBRARIES}
2042                 ${ZLIB_LIBRARIES}
2043         )
2044         set(text2pcap_CLEAN_FILES
2045                 text2pcap.c
2046                 pcapio.c
2047         )
2048         set(text2pcap_FILES
2049                 ${text2pcap_CLEAN_FILES}
2050                 ${CMAKE_BINARY_DIR}/image/text2pcap.rc
2051         )
2052         add_lex_files(text2pcap_FILES
2053                 text2pcap-scanner.l
2054         )
2055         add_executable(text2pcap ${text2pcap_FILES})
2056         set_extra_executable_properties(text2pcap "Executables")
2057         target_link_libraries(text2pcap ${text2pcap_LIBS})
2058         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2059 endif()
2060
2061 if(BUILD_mergecap)
2062         set(mergecap_LIBS
2063                 wiretap
2064                 ${ZLIB_LIBRARIES}
2065                 ${CMAKE_DL_LIBS}
2066         )
2067         set(mergecap_FILES
2068                 mergecap.c
2069                 ${CMAKE_BINARY_DIR}/image/mergecap.rc
2070         )
2071         add_executable(mergecap ${mergecap_FILES})
2072         set_extra_executable_properties(mergecap "Executables")
2073         target_link_libraries(mergecap ${mergecap_LIBS})
2074         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2075 endif()
2076
2077 if(BUILD_reordercap)
2078         set(reordercap_LIBS
2079                 wiretap
2080                 ${ZLIB_LIBRARIES}
2081                 ${CMAKE_DL_LIBS}
2082         )
2083         set(reordercap_FILES
2084                 reordercap.c
2085                 ${CMAKE_BINARY_DIR}/image/reordercap.rc
2086         )
2087         add_executable(reordercap ${reordercap_FILES})
2088         set_extra_executable_properties(reordercap "Executables")
2089         target_link_libraries(reordercap ${reordercap_LIBS})
2090         install(TARGETS reordercap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2091 endif()
2092
2093 if(BUILD_capinfos)
2094         set(capinfos_LIBS
2095                 wiretap
2096                 wsutil
2097                 ${ZLIB_LIBRARIES}
2098                 ${GCRYPT_LIBRARIES}
2099                 ${CMAKE_DL_LIBS}
2100         )
2101         set(capinfos_FILES
2102                 capinfos.c
2103                 ${CMAKE_BINARY_DIR}/image/capinfos.rc
2104         )
2105         add_executable(capinfos ${capinfos_FILES})
2106         set_extra_executable_properties(capinfos "Executables")
2107         target_link_libraries(capinfos ${capinfos_LIBS})
2108         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2109 endif()
2110
2111 if(BUILD_captype)
2112         set(captype_LIBS
2113                 wiretap
2114                 wsutil
2115                 ${ZLIB_LIBRARIES}
2116                 ${CMAKE_DL_LIBS}
2117         )
2118         set(captype_FILES
2119                 captype.c
2120                 ${CMAKE_BINARY_DIR}/image/captype.rc
2121         )
2122         add_executable(captype ${captype_FILES})
2123         set_extra_executable_properties(captype "Executables")
2124         target_link_libraries(captype ${captype_LIBS})
2125         install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2126 endif()
2127
2128 if(BUILD_editcap)
2129         set(editcap_LIBS
2130                 wiretap
2131                 ${ZLIB_LIBRARIES}
2132                 ${CMAKE_DL_LIBS}
2133         )
2134         set(editcap_FILES
2135                 editcap.c
2136                 ${CMAKE_BINARY_DIR}/image/editcap.rc
2137         )
2138         add_executable(editcap ${editcap_FILES})
2139         set_extra_executable_properties(editcap "Executables")
2140         target_link_libraries(editcap ${editcap_LIBS})
2141         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2142 endif()
2143
2144 if(BUILD_dumpcap AND PCAP_FOUND)
2145         set(dumpcap_LIBS
2146                 wsutil
2147                 caputils
2148                 ${PCAP_LIBRARIES}
2149                 ${CAP_LIBRARIES}
2150 #               @SOCKET_LIBS@
2151 #               @NSL_LIBS@
2152                 ${GLIB2_LIBRARIES}
2153                 ${GTHREAD2_LIBRARIES}
2154                 ${ZLIB_LIBRARIES}
2155                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2156                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2157                 ${NL_LIBRARIES}
2158         )
2159         set(dumpcap_FILES
2160                 capture_opts.c
2161                 capture_stop_conditions.c
2162                 conditions.c
2163                 dumpcap.c
2164                 pcapio.c
2165                 ringbuffer.c
2166                 sync_pipe_write.c
2167                 ${CMAKE_BINARY_DIR}/image/dumpcap.rc
2168         )
2169         add_executable(dumpcap ${dumpcap_FILES})
2170         set_extra_executable_properties(dumpcap "Executables")
2171         target_link_libraries(dumpcap ${dumpcap_LIBS})
2172         install(TARGETS dumpcap
2173                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2174                         PERMISSIONS ${DUMPCAP_SETUID}
2175                                 OWNER_READ OWNER_WRITE OWNER_EXECUTE
2176                                 GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
2177         )
2178         if(DUMPCAP_INSTALL_OPTION STREQUAL "capabilities")
2179                 install( CODE "execute_process(
2180                         COMMAND
2181                                 ${SETCAP_EXECUTABLE}
2182                                 cap_net_raw,cap_net_admin+ep
2183                                 ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/dumpcap${CMAKE_EXECUTABLE_SUFFIX}
2184                         RESULT_VARIABLE
2185                                 _SETCAP_RESULT
2186                         )
2187                         if( _SETCAP_RESULT )
2188                                 message( WARNING \"setcap failed (${_SETCAP_RESULT}).\")
2189                         endif()"
2190                 )
2191         endif()
2192 endif()
2193
2194 if (WIN32)
2195         # Must come after executable targets are defined.
2196         find_package( NSIS )
2197
2198         if (NOT "${MAKENSIS_EXECUTABLE}" STREQUAL "MAKENSIS_EXECUTABLE-NOTFOUND")
2199                 add_subdirectory( packaging/nsis EXCLUDE_FROM_ALL )
2200                 ADD_NSIS_UNINSTALLER_TARGET()
2201                 ADD_NSIS_PACKAGE_TARGET()
2202         endif()
2203
2204         find_package( PortableApps )
2205         if (
2206                 NOT "${PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE}" STREQUAL "PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE-NOTFOUND"
2207                 AND
2208                 NOT "${PORTABLEAPPS_INSTALLER_EXECUTABLE}" STREQUAL "PORTABLEAPPS_INSTALLER_EXECUTABLE-NOTFOUND"
2209         )
2210                 add_subdirectory( packaging/portableapps EXCLUDE_FROM_ALL )
2211                 ADD_PORTABLEAPPS_PACKAGE_TARGET()
2212         endif()
2213 endif()
2214
2215 if(BUILD_androiddump)
2216         if(EXTCAP_ANDROIDDUMP_LIBPCAP)
2217                 if(HAVE_LIBPCAP)
2218                         set(androiddump_LIBS
2219                                 ${GLIB2_LIBRARIES}
2220                                 ${PCAP_LIBRARIES}
2221                         )
2222                 else()
2223                         message(FATAL_ERROR "You try to build androiddump with libpcap but do not have it")
2224                 endif()
2225         else()
2226                 set(androiddump_LIBS
2227                         wiretap
2228                         ${GLIB2_LIBRARIES}
2229                         ${CMAKE_DL_LIBS}
2230                 )
2231         endif()
2232         set(androiddump_FILES
2233                 extcap/androiddump.c
2234         )
2235
2236         add_executable(androiddump WIN32 ${androiddump_FILES})
2237         # XXX Shouldn't we add wsutil to androiddump_LIBS instead?
2238         add_dependencies(androiddump gitversion)
2239         set_extcap_executable_properties(androiddump)
2240         target_link_libraries(androiddump ${androiddump_LIBS})
2241         install(TARGETS androiddump RUNTIME DESTINATION ${EXTCAP_DIR})
2242 endif()
2243
2244 ADD_CUSTOM_COMMAND(
2245         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
2246         COMMAND ${PERL_EXECUTABLE}
2247                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
2248                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
2249                 < ${CMAKE_SOURCE_DIR}/AUTHORS
2250                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
2251         DEPENDS
2252                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
2253                 ${CMAKE_SOURCE_DIR}/doc/make-authors-short.pl
2254                 ${CMAKE_SOURCE_DIR}/AUTHORS
2255 )
2256
2257 ADD_CUSTOM_COMMAND(
2258         OUTPUT  ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
2259         COMMAND ${PERL_EXECUTABLE}
2260                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
2261                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
2262                 < ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
2263                 > ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
2264         DEPENDS
2265                 ${CMAKE_SOURCE_DIR}/doc/perlnoutf.pl
2266                 ${CMAKE_SOURCE_DIR}/doc/make-authors-format.pl
2267                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
2268 )
2269
2270 if(WIN32)
2271 FILE(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template WPT_WIN_PATH)
2272 FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT ASF_WIN_PATH)
2273 FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/wireshark.pod WP_WIN_PATH)
2274 ADD_CUSTOM_COMMAND(
2275         OUTPUT  ${CMAKE_BINARY_DIR}/wireshark.pod
2276         COMMAND copy /B ${WPT_WIN_PATH} + ${ASF_WIN_PATH} ${WP_WIN_PATH}
2277         DEPENDS
2278                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
2279                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
2280 )
2281 else()
2282
2283 ADD_CUSTOM_COMMAND(
2284         OUTPUT  ${CMAKE_BINARY_DIR}/wireshark.pod
2285         COMMAND cat
2286                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
2287                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
2288                 > ${CMAKE_BINARY_DIR}/wireshark.pod
2289         DEPENDS
2290                 ${CMAKE_SOURCE_DIR}/doc/wireshark.pod.template
2291                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT-FORMAT
2292 )
2293 endif()
2294
2295 if(ENABLE_APPLICATION_BUNDLE)
2296         add_custom_target(app_bundle)
2297         set_target_properties(app_bundle PROPERTIES FOLDER "Copy Tasks")
2298         add_custom_command(TARGET app_bundle
2299                 POST_BUILD
2300                 COMMAND "${CMAKE_SOURCE_DIR}/packaging/macosx/osx-app.sh"
2301                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/run"
2302         )
2303         add_dependencies(app_bundle ${PROGLIST})
2304 endif()
2305
2306 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/androiddump 1 )
2307 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/capinfos 1 )
2308 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/captype 1 )
2309 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dftest 1 )
2310 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/dumpcap 1 )
2311 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/editcap 1 )
2312 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/extcap 4 )
2313 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/asn2deb 1 )
2314 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2deb 1 )
2315 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/idl2wrs 1 )
2316 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/mergecap 1 )
2317 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/randpkt 1 )
2318 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/rawshark 1 )
2319 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/reordercap 1 )
2320 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/text2pcap 1 )
2321 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/tshark 1 )
2322 pod2manhtml( ${CMAKE_BINARY_DIR}/wireshark 1 )
2323 pod2manhtml( ${CMAKE_SOURCE_DIR}/doc/wireshark-filter 4 )
2324
2325 add_custom_target(
2326         html_docs ALL
2327         DEPENDS
2328                 ${CMAKE_BINARY_DIR}/AUTHORS-SHORT
2329                 androiddump.html
2330                 capinfos.html
2331                 captype.html
2332                 dftest.html
2333                 dumpcap.html
2334                 editcap.html
2335                 asn2deb.html
2336                 idl2deb.html
2337                 idl2wrs.html
2338                 mergecap.html
2339                 randpkt.html
2340                 rawshark.html
2341                 reordercap.html
2342                 text2pcap.html
2343                 tshark.html
2344                 wireshark.html
2345                 wireshark-filter.html
2346 )
2347 set_target_properties(html_docs PROPERTIES FOLDER "Docs")
2348
2349 set(CLEAN_FILES
2350         ${wireshark_FILES}
2351         ${tshark_FILES}
2352         ${rawshark_FILES}
2353         ${dftest_FILES}
2354         ${randpkt_FILES}
2355         ${text2pcap_CLEAN_FILES}
2356         ${mergecap_FILES}
2357         ${capinfos_FILES}
2358         ${captype_FILES}
2359         ${editcap_FILES}
2360         ${dumpcap_FILES}
2361         ${androiddump_FILES}
2362 )
2363
2364 if (WERROR)
2365         set_source_files_properties(
2366                 ${CLEAN_FILES}
2367                 PROPERTIES
2368                 COMPILE_FLAGS -Werror
2369         )
2370 endif()
2371
2372 install(
2373         FILES
2374                 ${INSTALL_FILES}
2375         DESTINATION
2376                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
2377 )
2378
2379 install(
2380         FILES
2381                 ${MAN1_FILES}
2382         DESTINATION
2383                 ${CMAKE_INSTALL_MANDIR}/man1
2384 )
2385
2386 install(
2387         FILES
2388                 ${MAN4_FILES}
2389         DESTINATION
2390                 ${CMAKE_INSTALL_MANDIR}/man4
2391 )
2392
2393 install(
2394         FILES
2395                 "${CMAKE_BINARY_DIR}/wireshark.pc"
2396         DESTINATION
2397                 ${CMAKE_INSTALL_LIBDIR}/pkgconfig
2398 )
2399
2400 install(
2401         DIRECTORY
2402                 ${INSTALL_DIRS}
2403         DIRECTORY_PERMISSIONS
2404                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
2405                 GROUP_EXECUTE GROUP_READ
2406                 WORLD_EXECUTE WORLD_READ
2407         DESTINATION
2408                 ${CMAKE_INSTALL_DATADIR}/${CPACK_PACKAGE_NAME}
2409         PATTERN ".git" EXCLUDE
2410         PATTERN ".svn" EXCLUDE
2411         PATTERN "Makefile.*" EXCLUDE
2412         PATTERN "faq.py" EXCLUDE
2413 )
2414
2415 include( UseCheckAPI )
2416 CHECKAPI(
2417         ${TSHARK_TAP_SRC}
2418         ${WIRESHARK_SRC}
2419 )
2420
2421 set(CMAKE_INSTALL_MODULES_DIR ${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME})
2422 configure_file("${CMAKE_MODULE_PATH}/WiresharkConfig.cmake.in" "${CMAKE_BINARY_DIR}/WiresharkConfig.cmake" @ONLY)
2423 configure_file("${CMAKE_MODULE_PATH}/WiresharkConfigVersion.cmake.in" "${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake" @ONLY)
2424 install(
2425         FILES
2426                 ${CMAKE_MODULE_PATH}/FindGLIB2.cmake
2427                 ${CMAKE_MODULE_PATH}/FindWireshark.cmake
2428                 ${CMAKE_MODULE_PATH}/FindWSWinLibs.cmake
2429                 ${CMAKE_MODULE_PATH}/UseAsn2Wrs.cmake
2430                 ${CMAKE_MODULE_PATH}/LocatePythonModule.cmake
2431                 ${CMAKE_MODULE_PATH}/UseMakeDissectorReg.cmake
2432                 ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
2433                 ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
2434         DESTINATION
2435                 ${CMAKE_INSTALL_MODULES_DIR}
2436 )
2437
2438 if(DOC_DIR)
2439         message(STATUS "Docdir install: ${DOC_DIR}")
2440         INSTALL(
2441                 DIRECTORY
2442                         ${CMAKE_BINARY_DIR}/docbook/
2443                 DIRECTORY_PERMISSIONS
2444                         OWNER_EXECUTE OWNER_WRITE OWNER_READ
2445                         GROUP_EXECUTE GROUP_READ
2446                         WORLD_EXECUTE WORLD_READ
2447                 DESTINATION
2448                         ${DOC_DIR}/guides
2449                 FILES_MATCHING
2450                 PATTERN "*.pdf"
2451         )
2452 endif()
2453
2454 # Test suite wrapper
2455 if(ENABLE_APPLICATION_BUNDLE)
2456         set(TEST_SH_BIN_DIR ${CMAKE_BINARY_DIR}/run)
2457 else()
2458         set(TEST_SH_BIN_DIR $<TARGET_FILE_DIR:epan>)
2459 endif()
2460
2461 add_custom_target(test-sh
2462         COMMAND ${CMAKE_COMMAND}
2463                 -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
2464                 -DTEST_SH_BIN_DIR=${TEST_SH_BIN_DIR}
2465                 -DTEST_SH_SRC_DIR=${CMAKE_SOURCE_DIR}/test
2466                 -P ${CMAKE_SOURCE_DIR}/cmake/modules/GenerateTestSh.cmake
2467         DEPENDS ${CMAKE_SOURCE_DIR}/cmake/modules/GenerateTestSh.cmake
2468 )
2469 set_target_properties(test-sh PROPERTIES FOLDER "Tests")
2470
2471 add_custom_target(test-programs
2472         DEPENDS test-sh
2473                 exntest
2474                 oids_test
2475                 reassemble_test
2476                 tvbtest
2477                 wmem_test
2478         COMMENT "Building unit test programs and wrapper"
2479 )
2480 set_target_properties(test-programs PROPERTIES FOLDER "Tests")
2481
2482
2483 #
2484 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
2485 #
2486 # Local variables:
2487 # c-basic-offset: 8
2488 # tab-width: 8
2489 # indent-tabs-mode: t
2490 # End:
2491 #
2492 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
2493 # :indentSize=8:tabSize=8:noTabs=false:
2494 #