cmake: compilation statistics

前端 未结 3 1354
自闭症患者
自闭症患者 2021-02-02 11:19

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 ?

3条回答
  •  清歌不尽
    2021-02-02 12:05

    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.

提交回复
热议问题