Get the CMake installer from https://cmake.org/download/ and install CMake into the default location. Ensure the directory containing cmake.exe is added to your path.
Alternatively you can install CMake using Chocolatey:
PS$>choco install cmake.portable
Chocolatey ensures cmake.exe is on your path.
Make sure everything works | |
---|---|
It’s a good idea to make sure Wireshark compiles and runs at least once before you start hacking the Wireshark sources for your own project. This example uses Git Extensions but any other Git client should work as well. |
Download sources Download Wireshark sources into C:\Development\wireshark using either the command line or Git Extensions:
Using the command line:
>cd C:\Development >git clone https://code.wireshark.org/review/wireshark
Using Git extensions:
In the main screen select Clone repository. Fill in the following:
Repository to clone: https://code.wireshark.org/review/wireshark
Destination: Your top-level development directory, e.g. C:\Development
.
Subdirectory to create: Anything you’d like. Usually wireshark
.
Check your paths | |
---|---|
Make sure your repository path doesn’t contain spaces. |
From the Start Menu (or Start Screen), navigate to the Visual Studio 2013 → Visual Studio Tools directory and choose the Command Prompt appropriate for the build you wish to make, e.g. VS2013 x86 Native Tools Command Prompt for a 32-bit version, VS2013 x64 Native Tools Command Prompt for a 64-bit version.
Pin the items to the Task Bar | |
---|---|
Pin the Command Prompt you use to the Task Bar for easy access. |
All subsequent operations take place in this Command Prompt window.
Set environment variables to control the build.
Set the following environment variables, using paths and values suitable for your installation:
> set CYGWIN=nodosfilewarning > set WIRESHARK_BASE_DIR=C:\Development or set WIRESHARK_LIB_DIR to the appropriate library directory for your build. > set WIRESHARK_TARGET_PLATFORM=win32 or win64 as required > set QT5_BASE_DIR=C:\Qt\Qt5.5.0\5.5\msvc2013 > set WIRESHARK_VERSION_EXTRA=-YourExtraVersionInfo
If your Cygwin installation path is not automatically detected by CMake, you can explicitly specify it with the following environment variable:
> set WIRESHARK_CYGWIN_INSTALL_PATH=c:\cygwin or whatever other path that is applicable to your setup
If you are using a version of Visual Studio earlier than VS2012 then you must set an additional env var, e.g. for VS2010 set the following:
> set VisualStudioVersion=10.0
Setting these variables could be added to a batch file to be run after you open the Visual Studio Tools Command Prompt.
Create and change to the correct build directory. CMake is best used in an out-of-tree build configuration where the build is done in a separate directory to the source tree, leaving the source tree in a pristine state. 32 and 64 bit builds require a separate build directory. Create (if required) and change to the appropriate build directory.
> mkdir C:\Development\wsbuild32 > cd C:\Development\wsbuild32
to create and jump into the build directory.
The build directory can be deleted at any time and the build files regenerated as detailed in Section 2.3.3, “Generate the build files”.
CMake is used to process the CMakeLists.txt files in the source tree and produce build files appropriate for your system.
You can generate Visual Studio solution files to build either from within Visual Studio, or from the command line with MSBuild. CMake can also generate other build types but they aren’t supported.
The initial generation step is only required the first time a build directory is created. Subsequent builds will regenerate the build files as required.
If you’ve closed the Visual Studio Command Prompt prepare it again.
To generate the build files enter the following at the Visual Studio command prompt:
> cmake -DPYTHON_EXECUTABLE=c:/Python27/python -DENABLE_CHM_GUIDES=on -G "Visual Studio 12" ..\wireshark
Adjusting the paths as required to Python and the wireshark source tree. To use a different generator modify the -G parameter, cmake -G lists all the CMake supported generators, but only Visual Studio is supported for Wireshark builds.
The CMake generation process will download the required 3rd party libraries (apart from Qt) as required, then test each library for usability before generating the build files.
At the end of the CMake generation process the following should be displayed:
-- Configuring done -- Generating done -- Build files have been written to: C:/Development/wsbuild32
If you get any other output, there is an issue in your envirnment that must be rectified before building. Check the parameters passed to CMake, especially the -G option and the path to the Wireshark sources and the environment variables WIRESHARK_BASE_DIR, WIRESHARK_TARGET_PLATFORM and QT5_BASE_DIR.
Now it’s time to build Wireshark!
Run
> msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln
to build Wireshark.
C:\Development\wsbuild32\run\RelWithDebInfo\Wireshark.exe
and make sure it starts.
C:\Development\wsbuild32\run\RelWithDebInfo\wireshark-gtk.exe
.
You may also open the Wireshark solution file (Wireshark.sln) in the Visual Studio IDE and build there.
Tip | |
---|---|
If compilation fails for suspicious reasons after you changed some source files try to clean the build files by running msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln /t:Clean and then building the solution again. |
The build files produced by CMake will regenerate themselves if required by changes in the source tree.
You can debug using the Visual Studio Debugger or WinDbg. See the section on using the Debugger Tools.
Detailed information to build these guides can be found in the file docbook\README.txt in the Wireshark sources.
Note: You should have successfully built Wireshark before doing the following.
If you want to build your own wireshark-win32-2.0.x-myprotocol123.exe, you’ll need NSIS.
NSIS: Download and install NSIS
Note that the 32-bit version of NSIS will work for both 32-bit and 64-bit versions of Wireshark.
Note: If you do not yet have a copy of vcredist_x86.exe or vcredist_x64.exe in ./wireshark-winXX-libs (where XX is 32 or 64) you will need to download the appropriate file and place it in ./wireshark-winXX-libs before starting this step.
If building an x86 version using a Visual Studio "Express" edition or an x64 version with any edition, then you must have the appropriate vcredist file for your compiler in the support libraries directory (vcredist_x86.exe in wireshark-32-libs or vcredist_x64.exe in wireshark-win64-libs).
The files can be located in the Visual Studio install directory for non-Express edition builds, or downloaded from Microsoft for Expresss edition builds.
Note you must use the correct version of vcredist for your compiler, unfortunately they all have the same name (vcredist_x86.exe or vcredist_x64.exe). You can use Windows Explorer and examine the Properties >> Details tab for a vcredist file to determine which compiler version the file is for use with.
Run
> msbuild /m /p:Configuration=RelWithDebInfo nsis_package_prep.vcxproj > msbuild /m /p:Configuration=RelWithDebInfo nsis_package.vcxproj
to build a Wireshark installer.
Run
> C:\Development\wireshark\packaging\nsis\wireshark-win32-wireshark-major-minor-version:[].x-myprotocol123.exe
to test your new installer. It’s a good idea to test on a different machine than the developer machine. Note that if you’ve built an x64 version, the installer will be named accordingly.