如何统计编译时长?

内容目录

在项目顶层 CMakelists.txt 添加

set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")

效果如下:

-- Build files have been written to: /Users/mac/Development/tiny-ros-dds/build/CMake
[  1%] Building CXX object core/CMakeFiles/tinyroscore.dir/src/serialization.cpp.o
Elapsed time (seconds): 0.714919
[  2%] Building CXX object core/CMakeFiles/tinyroscore.dir/src/socket_node.cpp.o
Elapsed time (seconds): 6.90129
[  4%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/async.cpp.o
Elapsed time (seconds): 1.47324
[  5%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/bundled_fmtlib_format.cpp.o
Elapsed time (seconds): 2.61582
[  7%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/cfg.cpp.o
Elapsed time (seconds): 0.969724
[  8%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/color_sinks.cpp.o
Elapsed time (seconds): 1.20908
[ 10%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/file_sinks.cpp.o
Elapsed time (seconds): 0.924956
[ 11%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/spdlog.cpp.o
Elapsed time (seconds): 5.54922
[ 13%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/spdlog/src/stdout_sinks.cpp.o
Elapsed time (seconds): 1.13608
[ 14%] Building CXX object core/CMakeFiles/tinyroscore.dir/__/build/output/roslib/gcc/tiny_ros/time.cpp.o
Elapsed time (seconds): 0.145248
[ 16%] Linking CXX executable /Users/mac/Development/tiny-ros-dds/build/output/bin/tinyroscore
打赏作者