3.1 CMake configuration with ns3waf

Navigate to the cloned NS3 folder and run ns3waf

cd NS3
./ns3waf -d *buildtype* -G *generator*

You can pass arguments to the ns3waf command such as --enable-tests --enable-examples in order to configure it enabling tests and examples.

To set the build type, replace buildtype with either debug, release or optimized.

-G stands for the generator (a.k.a. real build system used by the files generated by CMake). You can find a list of them here buildsystem with the following argument: -G “generator name (with double quotes)”

To simplify things, we are going to automatically select one of the available ones (probably make or ninja).

Most of the arguments match waf, so I won’t list all of them here. Check all the possible arguments in the ns3waf file.

3.2 Building the project with ns3waf

After the configuration, you will have multiple targets (for libraries and executables). The targets are module libraries (e.g. core, internet, network) and executables names (e.g. scratch-simulator).

You can specify which targets you want to build with

./ns3waf --build core internet

This command will refresh the cmake cache (looking for changed settings and new modules), and then build core and internet libraries.

You can also build the entire project with

./ns3waf --build

3.3. Running built executables with ns3waf

After building executables, they will be placed in NS3/build/bin. To run them, you can use the --run argument. For example:

./ns3waf --run scratch-simulator

will refresh the cmake cache, build scratch simulator, then execute it.

If you only want to run the target and not rebuild it (e.g. while debugging), try --run-no-build.

You can also use options like --gdb or --valgrind for debugging/testing and command-template for complicated stuff.