Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the build time of C Project using CMake

I am working in a C-Project and for building the software I am using CMake. Unfortunately the building of the software needs a lot of time. For analysing the build time, I want to:

  • print the translation time for every c file
  • print the time for the whole build

into a text file.

How can I do it using CMake?

like image 738
elguerrero Avatar asked Sep 19 '25 05:09

elguerrero


1 Answers

I am working in a C-Project and for building the software I am using CMake.

Not really; CMake doesn't build anything, it's not a build tool. CMake is used to generate the buildsystem (such as makefiles or Visual Studio solutions) and then the normal build tools are used for building. Even invoking cmake --build is just a wrapper which launches the proper build tool.

This means build timing is outside CMake control. You will have to inspect your build toolchain (gcc, cl, etc.) for its timing features. If these require command-line options for the compiler etc., you can of course then set these up in your CMakeLists using normal CMake mechanisms (target_compile_options() etc.).

As for timing the whole build, you can use CMake's built-in timing feature cmake -E time command args..., but that is again nothing build-specific; it's just a cross-platform way of timing the run of an arbitrary command.

like image 55
Angew is no longer proud of SO Avatar answered Sep 20 '25 22:09

Angew is no longer proud of SO