@@ -2,18 +2,33 @@ find_package(benchmark REQUIRED)
22find_package (example-robot-data 4.0.9 REQUIRED)
33
44# Add a benchmark.
5- function (create_bench exfile )
6- get_filename_component (exname ${exfile } NAME_WE )
7- set (exname "bench-${exname } " )
8- add_executable (${exname } ${exfile } )
9- message (STATUS "Adding cpp example ${exname } " )
10- set_target_properties (${exname } PROPERTIES LINKER_LANGUAGE CXX)
11- target_include_directories (${exname } PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
5+ function (create_bench benchfile )
6+ get_filename_component (benchname ${benchfile } NAME_WE )
7+ set (benchname "bench-${benchname } " )
8+ add_executable (${benchname } ${benchfile } )
9+ message (STATUS "Adding cpp example ${benchname } " )
10+ set_target_properties (${benchname } PROPERTIES LINKER_LANGUAGE CXX)
11+ target_include_directories (${benchname } PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
1212
13- target_link_libraries (${exname} PUBLIC ${PROJECT_NAME} )
14- target_link_libraries (${exname} PUBLIC example-robot-data::example-robot-data)
15- target_link_libraries (${exname} PUBLIC benchmark::benchmark)
13+ target_link_libraries (${benchname} PUBLIC ${PROJECT_NAME} )
14+ target_link_libraries (${benchname} PUBLIC example-robot-data::example-robot-data)
15+ target_link_libraries (${benchname} PUBLIC benchmark::benchmark)
16+
17+ # Add custom command to run this particular benchmark
18+ add_custom_target (run-${benchname}
19+ COMMAND ${benchname}
20+ DEPENDS ${benchname}
21+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
22+ )
23+ # Add this benchmark in the dependencies to run all benchmarks
24+ add_dependencies (run-benchmarks run-${benchname} )
1625endfunction ()
1726
27+ # Create a custom target to run all benchmarks
28+ add_custom_target (run-benchmarks
29+ COMMAND ${CMAKE_COMMAND} -E echo "All benchmarks run."
30+ )
31+
32+ # Add benchmarks
1833create_bench("talos.cpp" )
1934create_bench("go2.cpp" )
0 commit comments