Profiling a CMake build
When CMake projects get big, configuring them might take quite a long time, especially if there is external content loaded or if there are lots of checks done for toolchain features. A first step to optimize this is to check what part of the configuration process takes up how much time. Since version 3.18, CMake has included command-line options to produce nice profiling graphs to investigate where time is spent during configuration. By adding the --profiling-output
and --profiling-format
profiling flags, CMake will create profiling output. At the time of writing this book, only the Google trace format for output format is supported. Despite this, the format and the file need to be specified to create profiling information. A call to CMake to create a profiling graph could look like this:
cmake -S <sourceDir> -B <buildDir> --profiling-output ./profiling.json --profiling-format=google-trace
This will write the profiling output to the profiling...