Skip to content

Commit 7c82d91

Browse files
committed
Fixed CMakeLists Tracy dependancy
for Test and Benchmarks, Tracy can be enabled/disabled automatically
1 parent a5f0005 commit 7c82d91

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

tests/CMakeLists.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ FetchContent_Declare(
55
GIT_TAG v2.13.10
66
)
77
FetchContent_MakeAvailable(catch)
8+
89
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/tests/CMake/Modules/)
910
include(ParseAndAddCatchTests)
1011

11-
# Define a function to automate adding benchamrks
12-
function(automate_add_benchmarks target_name source_file)
12+
# Usage: add_blast_target(target_name source_file [TEST | BENCH])
13+
function(add_blast_target target_name source_file type)
1314
add_executable(${target_name} ${source_file})
1415
target_compile_features(${target_name} PUBLIC cxx_std_17)
15-
target_link_libraries(${target_name} PUBLIC Catch2::Catch2 blast TracyClient)
16-
target_compile_definitions(${target_name} PUBLIC TRACY_ENABLE TRACY_NO_EXIT)
17-
endfunction()
1816

19-
# Define a function to automate adding tests
20-
function(automate_add_tests target_name source_file)
21-
add_executable(${target_name} ${source_file})
22-
target_compile_features(${target_name} PUBLIC cxx_std_17)
23-
target_link_libraries(${target_name} PRIVATE Catch2::Catch2 blast TracyClient)
24-
add_test(NAME ${target_name}_test COMMAND ${target_name})
17+
# Base dependencies
18+
target_link_libraries(${target_name} PRIVATE Catch2::Catch2 blast)
19+
20+
# Conditional Tracy logic
21+
if (ENABLE_TRACY)
22+
target_link_libraries(${target_name} PRIVATE TracyClient)
23+
target_compile_definitions(${target_name} PRIVATE TRACY_ENABLE TRACY_NO_EXIT)
24+
endif ()
25+
26+
# If marked as a TEST, register it with CTest
27+
if ("${type}" STREQUAL "TEST")
28+
add_test(NAME ${target_name}_test COMMAND ${target_name})
29+
endif ()
2530
endfunction()
2631

2732
# note: Add new benchmark files as follows :
@@ -38,6 +43,8 @@ set(BENCHMARKS
3843
# bench_paper_gradients benchmarks/bench_paper_gradients.cpp
3944
# bench_constraints benchmarks/bench_constraints.cpp
4045
# bench_functions benchmarks/bench_functions.cpp
46+
47+
bench_optimization_methods benchmarks/bench_optimization_methods.cpp
4148
)
4249

4350
# note: Add new tests files as follows :
@@ -75,20 +82,16 @@ set(TESTS
7582
test_bspline trajectory/test_bsplines.cpp
7683
)
7784

78-
add_executable(bench_optimization_methods benchmarks/bench_optimization_methods.cpp)
79-
target_compile_features(bench_optimization_methods PUBLIC cxx_std_17)
80-
target_link_libraries(bench_optimization_methods PUBLIC blast)
81-
8285
# Loop through and add benchmarks
8386
while (BENCHMARKS)
8487
list(POP_FRONT BENCHMARKS target_name)
8588
list(POP_FRONT BENCHMARKS source_file)
86-
automate_add_benchmarks(${target_name} ${source_file})
89+
add_blast_target(${target_name} ${source_file} "BENCH")
8790
endwhile ()
8891

8992
# Loop through and add tests
9093
while (TESTS)
9194
list(POP_FRONT TESTS target_name)
9295
list(POP_FRONT TESTS source_file)
93-
automate_add_tests(${target_name} ${source_file})
96+
add_blast_target(${target_name} ${source_file} "TEST")
9497
endwhile ()

0 commit comments

Comments
 (0)