# Build options for use by CMake

include(CMakeDependentOption)

option(BUILD_wireshark     "Build Wireshark" ON)
option(BUILD_stratoshark   "Build Stratoshark" OFF)
option(BUILD_tshark        "Build tshark" ON)
option(BUILD_strato        "Build strato" ${BUILD_stratoshark})
option(BUILD_tfshark       "Build tfshark" OFF)
option(BUILD_rawshark      "Build rawshark" ON)
option(BUILD_dumpcap       "Build dumpcap" ON)
option(BUILD_text2pcap     "Build text2pcap" ON)
option(BUILD_mergecap      "Build mergecap" ON)
option(BUILD_reordercap    "Build reordercap" ON)
option(BUILD_editcap       "Build editcap" ON)
option(BUILD_capinfos      "Build capinfos" ON)
option(BUILD_captype       "Build captype" ON)
option(BUILD_randpkt       "Build randpkt" ON)
option(BUILD_dftest        "Build dftest" ON)
option(BUILD_corbaidl2wrs  "Build corbaidl2wrs" OFF)
option(BUILD_dcerpcidl2wrs "Build dcerpcidl2wrs" ON)
option(BUILD_xxx2deb       "Build xxx2deb" OFF)

option(BUILD_androiddump   "Build androiddump" ON)
cmake_dependent_option(EXTCAP_ANDROIDDUMP_LIBPCAP   "Build androiddump using libpcap" OFF BUILD_androiddump OFF)

option(BUILD_sshdump       "Build sshdump" ON)
option(BUILD_ciscodump     "Build ciscodump" ON)
option(BUILD_dpauxmon      "Build dpauxmon" ON)
option(BUILD_randpktdump   "Build randpktdump" ON)
option(BUILD_wifidump      "Build wifidump" ON)
if(WIN32 AND NOT MINGW)
	option(BUILD_etwdump	   "Build etwdump" ON)
else()
	option(BUILD_etwdump	   "Build etwdump" OFF)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	option(BUILD_sdjournal   "Build sdjournal" ON)
else()
	option(BUILD_sdjournal   "Build sdjournal" OFF)
endif()
option(BUILD_udpdump       "Build udpdump" ON)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	cmake_dependent_option(BUILD_dumpcalls	"Build dumpcalls" ON "BUILD_stratoshark OR BUILD_strato" OFF)
else()
	cmake_dependent_option(BUILD_dumpcalls	"Build dumpcalls" OFF "BUILD_stratoshark OR BUILD_strato" OFF)
endif()
cmake_dependent_option(BUILD_falcodump	"Build falcodump" ON "BUILD_stratoshark OR BUILD_strato" OFF)
cmake_dependent_option(BUILD_sshdig	"Build sshdig" ON "BUILD_stratoshark OR BUILD_strato" OFF)

option(BUILD_sharkd        "Build sharkd" ON)
option(BUILD_mmdbresolve   "Build MaxMind DB resolver" ON)
option(BUILD_fuzzshark     "Build fuzzshark" OFF)

option(ENABLE_WERROR     "Treat warnings as errors" ON)
# Debugging is enabled for "Debug" build type.
option(ENABLE_DEBUG      "Enable debugging for all build configurations" OFF)
option(ENABLE_DEBUG_UTF_8  "Enable UTF-8 sanity checks (requires ENABLE_DEBUG)" ON)
option(ENABLE_DEBUG_A2W  "Enable line directive from .cnf file" OFF)
# Assertions are enabled for "Debug" and "RelWithDebInfo" build types.
option(ENABLE_ASSERT     "Enable assertions for all build configurations" OFF)

option(ENABLE_CCACHE     "Speed up compiling and linking using ccache if possible" OFF)
option(DISABLE_FRAME_LARGER_THAN_WARNING "Disable warning if the size of a function frame is large" OFF)
option(ENABLE_TODO_WARNINGS "Enable compiler warnings that are yet to be fixed" OFF)
option(ENABLE_PEDANTIC_WARNINGS "Enable pedantic or unfixable compiler warnings (noisy)" OFF)
option(ENABLE_CODE_ANALYSIS "Enable the compiler's static analyzer if possible" OFF)
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
option(ENABLE_LSAN "Enable LeakSanitizer (LSAN) for debugging (less overhead than ASAN)" OFF)
option(ENABLE_TSAN "Enable ThreadSanitizer (TSan) for debugging" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
option(ENABLE_FUZZER "Enable libFuzzer instrumentation for use with fuzzshark" OFF)
option(ENABLE_CHECKHF_CONFLICT "Enable hf conflict check for debugging (start-up may be slower)" OFF)

if(CMAKE_GENERATOR STREQUAL "Ninja")
	option(ENABLE_COMPILER_COLOR_DIAGNOSTICS "Always enable the compiler's color diagnostic output" ON)
else()
	option(ENABLE_COMPILER_COLOR_DIAGNOSTICS "Always enable the compiler's color diagnostic output" OFF)
endif()

option(ENABLE_LTO "Use Link Time Optimization (release configuration only)" OFF)
option(ENABLE_Y2038 "Require 64-bit time_t even on 32-bit platforms (experimental)" OFF)

if(WIN32)
	option(ENABLE_VLD "Enable Visual Leak Detect in Debug configuration" OFF)
endif()

option(ENABLE_PCAP       "Enable libpcap support (required for capturing)" ON)
option(BUILD_SHARED_LIBS            "Build Wireshark libraries as shared" ON)
option(USE_STATIC               "Always link statically with external libraries" OFF)
option(ENABLE_PLUGINS           "Build with plugins" ON)
option(ENABLE_PLUGIN_IFDEMO     "Build with plugin interface demo" OFF)

option(ENABLE_ZLIB       "Build with zlib compression support" ON)
option(ENABLE_ZLIBNG     "Build with zlib-ng compression support" ON)
option(ENABLE_XXHASH     "Build with xxhash support" ON)
option(ENABLE_MINIZIP    "Build with zip file compression support" ON)
option(ENABLE_MINIZIPNG  "Build with zip file compression support" ON)
option(ENABLE_LZ4        "Build with LZ4 compression support" ON)
option(ENABLE_BROTLI     "Build with brotli compression support" ON)
option(ENABLE_SNAPPY     "Build with Snappy compression support" ON)
option(ENABLE_ZSTD       "Build with Facebook zstd compression support" ON)
option(ENABLE_NGHTTP2    "Build with HTTP/2 header decompression support" ON)
option(ENABLE_NGHTTP3    "Build with HTTP/3 header decompression support" ON)
option(ENABLE_LUA        "Build with Lua dissector support" ON)
option(ENABLE_SMI        "Build with libsmi snmp support" ON)
option(ENABLE_GNUTLS     "Build with RSA decryption support" ON)
option(ENABLE_PKCS11     "Build with PKCS11 support" ON)
if(WIN32 AND USE_REPOSITORY)
	option(ENABLE_WINSPARKLE "Enable automatic updates using WinSparkle" ON)
endif()
if (NOT WIN32)
	option(ENABLE_CAP        "Build with Posix capabilities support" ON)
endif()
if(UNIX)
	# Libnl is Linux-specific.
	if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
		set(_enable_libnl ON)
	endif()
	option(ENABLE_NETLINK    "Build with libnl support" ${_enable_libnl})
endif()
option(ENABLE_KERBEROS   "Build with Kerberos support" ON)
option(ENABLE_SBC        "Build with SBC Codec support in RTP Player" ON)
option(ENABLE_SPANDSP    "Build with G.722/G.726 codecs support in RTP Player" ON)
option(ENABLE_BCG729     "Build with G.729 codec support in RTP Player" ON)
option(ENABLE_AMRNB      "Build with AMRNB codec support in RTP Player" ON)
option(ENABLE_AMRWB      "Build with AMRWB codec support in RTP Player" ON)
option(ENABLE_ILBC       "Build with iLBC codec support in RTP Player" ON)
option(ENABLE_OPUS       "Build with opus support" ON)
option(ENABLE_SINSP      "Build with libsinsp+libscap support" ON)
option(ENABLE_CPUINFO    "Build with cpuinfo CPU detection support" ON)

option(FETCH_lua         "Download and build Lua" OFF)

# How to install
set(DUMPCAP_INSTALL_OPTION   "normal" CACHE STRING "Permissions to install")
set_property(CACHE DUMPCAP_INSTALL_OPTION PROPERTY STRINGS "normal" "suid" "capabilities")

if(UNIX)
	option(ENABLE_DUMPCAP_GROUP "Install dumpcap with group ownership and permissions (default \"wireshark\")" OFF)
	set(DUMPCAP_INSTALL_GROUP "wireshark" CACHE STRING "Group name for dumpcap (must exist)")
endif()

if(APPLE)
	option(ENABLE_APPLICATION_BUNDLE "Build a macOS application bundle (Wireshark.app)" ON)
	option(ENABLE_SPARKLE "Enable automatic updates using Sparkle" ON)
endif()

set(GLOBAL_PROFILE_DATA_DIR CACHE PATH "Directory that provides Wireshark global profiles for installation")

if(BUILD_stratoshark)
	set(STRATOSHARK_GLOBAL_PROFILE_DATA_DIR CACHE PATH "Directory that provides Stratoshark global profiles for installation")
endif()

if(WIN32)
	# Enable signing of NSIS installer by default only if we have 'sign-wireshark.bat' on the path
	# of the host system.
	set(_enable_signed_nsis False)
	if(CMAKE_HOST_WIN32)
		find_file(SIGN_WIRESHARK_BAT "sign-wireshark.bat")
		if (SIGN_WIRESHARK_BAT)
			set(_enable_signed_nsis True)
		endif()
	endif()
	option(ENABLE_SIGNED_NSIS         "Enable the code signing step of the NSIS installer build" ${_enable_signed_nsis})

	# Advanced options for developers to work-around limitations in the build
	# when cross-compiling to Windows.
	option(SKIP_NSIS_QT_DLLS    "Skip deploying Qt runtime DLLs with installer" OFF)
	mark_as_advanced(SKIP_NSIS_QT_DLLS)
endif()
# macOS and Windows bundle Wireshark and Stratoshark separately, so they don't need
# a "project specific" subdirectory to hold the differences between them.
if ((WIN32 AND NOT DEFINED ENV{MSYSTEM}) OR APPLE)
	option(ENABLE_SEPARATE_PROJECT_NAME         "Use project name as a subdirectory in the installation" OFF)
else()
	option(ENABLE_SEPARATE_PROJECT_NAME         "Use project name as a subdirectory in the installation" ON)
endif()
