4.4. 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. Our Buildbot runs CMake steps on Ubuntu, Win32, Win64, and macOS. In particular, the macOS and Windows packages are built using CMake.

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.11, “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:

-DBUILD_wireshark=OFF
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.
-DENABLE_CAP=OFF
Disable the POSIX capabilities check
-DCMAKE_BUILD_TYPE=Debug
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.
-DPYTHON_EXECUTABLE=c:/Python36/python
Force the Python path. Useful on Windows since Cygwin’s /usr/bin/python is a symlink.
-DENABLE_APPLICATION_BUNDLE=OFF
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.

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: http://lwn.net/Articles/188693/

Introductory tutorial/presentation: http://ait.web.psi.ch/services/linux/hpc/hpc_user_cookbook/tools/cmake/docs/Cmake_VM_2007.pdf

Introductory article in the Linux Journal: http://www.linuxjournal.com/node/6700/print

Useful variables: http://www.cmake.org/Wiki/CMake_Useful_Variables

Frequently Asked Questions: http://www.cmake.org/Wiki/CMake_FAQ