4

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?

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
elguerrero
  • 59
  • 1
  • 1
  • 8
  • Perhaps it might be possible to do something using [CMake server mode](https://cmake.org/cmake/help/latest/manual/cmake-server.7.html)? – Some programmer dude Sep 13 '19 at 08:48
  • 1
    @Someprogrammerdude CMake server mode is deprecated; it has been replaced by the [CMake file API](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html). And neither of these could do much about builds, I think. – Angew is no longer proud of SO Sep 13 '19 at 08:50

1 Answers1

5

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.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
  • 1
    I have used the command `set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")`. Now I am getting the compile time printed out in cmd prompt window. Can I also redirect the printed time to a file? – elguerrero Sep 16 '19 at 09:13