I need to figure out which translation units need to be restructured to improve compile times, How do I get hold of the compilation time, using cmake, for my translation units ?
To expand on the previous answer, here's a concrete solution that I just wrote up — which is to say, it definitely works in practice, not just in theory, but it has been used by only one person for approximately three minutes, so it probably has some infelicities.
#!/bin/bash
{ time clang "$@"; } 2> >(cat <(echo "clang $@") - >> /tmp/results.txt)
I put the above two lines in /tmp/time-clang
and then ran
chmod +x /tmp/time-clang
cmake .. -DCMAKE_C_COMPILER=/tmp/time-clang
make
You can use -DCMAKE_CXX_COMPILER=
to hook the C++ compiler in exactly the same way.
I didn't use make -j8
because I didn't want the results to get interleaved in weird ways.
I had to put an explicit hashbang #!/bin/bash
on my script because the default shell (dash
, I think?) on Ubuntu 12.04 wasn't happy with those redirection operators.