4.3. CMake

Wireshark’s build environment can be configured using CMake on various UNIX-like platforms, including Linux, macOS, and *BSD, and on Windows. CMake is designed to support out-of-tree builds - so much so that in-tree builds do not work properly in all cases. Along with being cross-platform, CMake supports many build tools and environments including traditional make, Ninja, and MSBuild.

Building with CMake typically includes creating a build directory and specifying a generator, aka a build tool. For example, to build Wireshark using Ninja in the directory wireshark-ninja you might run the following commands:

# Starting from your Wireshark source directory, create a build directory
# alongside it.
$ cd ..
$ mkdir wireshark-ninja
$ cd wireshark-ninja
# Assumes your source directory is named "wireshark".
$ cmake -G Ninja ../wireshark
$ ninja (or cmake --build .)

Using CMake on Windows is described further in Section 2.2.12, “Generate the build files”.

Along with specifying a generator with the -G flag you can set variables using the -D flag. Useful variables and generators include the following:

Don’t build the Wireshark GUI application. Each command line utility has its own BUILD_xxx flag as well. For example, you can use -DBUILD_mmdbresolve=OFF to disable mmdbresolve.
Build using the ccache compiler cache.
Disable the POSIX capabilities check
Enable debugging symbols
-DCARES_INCLUDE_DIR=/your/custom/cares/include, -DCARES_LIBRARY=/your/custom/cares/lib/libcares.so
Let you set the path to a locally-compiled version of c-ares. Most optional libraries have xxx_INCLUDE_DIR and xxx_LIB flags that let you control their discovery.
Specify the minimum macOS version for Wireshark and each command line utility. Note that this doesn’t affect the minimum target for third-party libraries. For example, if you’re building for macOS 10.12 you’ll need to install Qt 5.14 or earlier and ensure that other libraries support macOS 10.12, for example by running tools/macos-setup.sh -t 10.12.
Disable building an application bundle (Wireshark.app) on macOS

You can list all build variables (with help) by running cmake -LH [options] ../<Name_of_WS_source_dir>. This lists the cache of build variables after the cmake run. To only view the current cache, add option -N.

Depending on your needs, it might be useful to save your CMake configuration options in a file outside your build directory. CMake supports this via its presets option. For example, adding the following to CMakeUserPresets.json would let you build using Ninja in the build directory, enable ccache, and set a custom Qt directory by running cmake --preset mydev:

  "version": 4,
  "configurePresets": [
      "name": "mydev",
      "displayName": "Local development",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build",
      "cacheVariables": {
        "ENABLE_CCACHE": "ON"
      "environment": {
        "CMAKE_PREFIX_PATH": "/usr/local/Qt6"

After running cmake, you can always run make help to see a list of all possible make targets.

Note that CMake honors user umask for creating directories as of now. You should set the umask explicitly before running the install target.

CMake links:

The home page of the CMake project: https://cmake.org/

Official documentation: https://cmake.org/documentation/

About CMake in general and why KDE4 uses it: https://lwn.net/Articles/188693/

Useful variables: https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Useful-Variables

Frequently Asked Questions: https://gitlab.kitware.com/cmake/community/wikis/FAQ