Skip to content

Commit 9156d98

Browse files
committed
Make cmake target to run all benchmarks and call it from pixi
1 parent 24d299a commit 9156d98

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

benchmark/CMakeLists.txt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,33 @@ find_package(benchmark REQUIRED)
22
find_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})
1625
endfunction()
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
1833
create_bench("talos.cpp")
1934
create_bench("go2.cpp")

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cmd = "ctest --test-dir build --output-on-failure"
4646
depends-on = [{"task" = "build", "args" = [{ "buildtype" = "Debug" }, {"buildtests" = "ON"}] }]
4747

4848
[tasks.benchmark]
49-
cmd = "ctest --test-dir build --output-on-failure"
49+
cmd = "cmake --build build --target run-benchmarks"
5050
depends-on = [{"task" = "build", "args" = [{ "buildtype" = "Release" }, {"buildbenchmarks" = "ON"}] }]
5151

5252
[feature.lint]

0 commit comments

Comments
 (0)