Draft: CMake buildsystem
I'm not sure on the demand for this, but using CMake enables basically all IDEs through Xcode/Visual Studio/Makefiles/Ninja projects (CLion, Code::Blocks, Visual Studio, Xcode, Eclipse, etc). Those are great for developing, but especially for profiling and debugging. It has been working for the last few years, but it was not in a presentable state.
Tried to make it as a drop-in replacement for waf, with very few changes to upstream code. The changes to upstream code are mostly in test.py to accept executables without ns3ver- and -buildProfileSuffix (which I could reproduce, but choose not to do so for now), a missing header in dhcp-example.cc, a gitignore file and the CI file.
The current version should be able to build most of the ns-3 project without issues and run ./test.py with --nowaf flag.
It should also work fine for MinGW/Msys2 with the patches from !437 (closed).
What is missing?
Doxygen A code coverage option
Python bindings(it is kind of working, but failing for a fd-net-device) Sphinx docs
Contribution scripts(still not exactly the same, but closer to the waf version)
- All-in-one/Bake integration
Newer fd-net-devices added in 3.32 Linking to boost libraries Examples-as-tests-suites are broken due to waf dependency
- NSC examples
- Planetlab dependencies
What is working but currently not included?
Static builds Vcpkg library/dependencies installation
Libtorch support(nobody asked for these two, so I'm not including them) Netanim Openflow Brite
How to use?
From the command line
- Create a cmake cache folder (e.g.
mkdir cmake_cache && cd cmake_cache)
- Call cmake to generate the build system files and copy headers to ns-3-dev/build/ns3
cmake -DCMAKE_BUILD_TYPE=debug -G"Ninja" -DNS3_TESTS=ON -DNS3_EXAMPLES=ON ..)
- All flag options like NS3_TESTS|NS3_EXAMPLES are located in the CMakeLists.txt file in ns-3-dev.
- Call the build system (e.g.
- Not that different from waf
, except for the fact the header copy isn't triggered every time you try to rebuild things.
From IDEs that do not support CMake projects (e.g. Code::Blocks)
Same instructions for command line, but choosing "Unix Makefiles" or "MinGW Makefiles" as the CMake generator (-G). Then open the IDE and load the Makefile in the cmake cache folder. Targets to build/run/debug should be available for libraries/tests/examples/docs if enabled.
From IDEs that support CMake projects (e.g. CLion and Visual Studio)
Just open the ns-3-dev folder, right click the CMakeLists file and click to load the CMake project. It will automatically generate the cache and load the targets to build/run/debug.
I've more details at https://gabrielcarvfer.github.io/NS3/installation. I can rewrite the docs properly depending on the demand/feedback.
EDIT: Adding a list of supported switches and their mapping to CMake.
Main wscript option switches
--enable-gcov and --lcov-report : NS3_COVERAGE=ON|OFF --lcov-zerocounters: NS3_COVERAGE_ZERO_COUNTERS=ON|OFF --no-task-lines: depend on the buildsystem, not sure CMake can silence this. Supported in fakewaf.py --no-task-lines. --run, --run-no-build, --visualize, --gdb, --valgrind: fakewaf.py --run|--run-no-build|--visualize|--gdb|--valgrind --command-template, --pyrun and --pyrun-no-build: in the works for fakewaf. --doxygen-no-build, --docset: probably require two targets per command, one depending on the libraries/executables and other not depending on them --enable-sudo: not implemented. Assuming running `sudo ninja|make|etc` would do the trick --enable-tests/--disable-tests: NS3_TESTS=ON|OFF --enable-examples/--disable-examples: NS3_EXAMPLES=ON|OFF --enable-static: NS3_STATIC=ON|OFF --enable-mpi: NS3_MPI=ON|OFF --enable-des-metrics: NS3_DES_METRICS=ON|OFF --enable-cxx-standard: CMAKE_CXX_STANDARD=11|14|... --enable-asserts: NS3_ASSERT=ON|OFF --enable-logs: NS3_LOG=ON|OFF
src/wscript option switches
--enable-rpath: enabled by default --enable-modules: currently not implemented. Assumed it was not needed since only the necessary libraries are built for a selected target. Brite, click, mpi, openflow, visualizer and tap-bridge are only built if NS3_BRITE, NS3_CLICK, NS3_MPI, NS3_OPENFLOW, NS3_PYTHON_BINDINGS and NS3_TAP are enabled.