Skip to content

Commit 84ea2e9

Browse files
awoll-bdaiexploy-bot
authored andcommitted
Build test dependencies only if BUILD_TESTING is set (#67)
# Pull Request ### What change is being made Do not build test dependencies if `BUILD_TESTING` is `OFF` ### Why this change is being made More control for consumers of the CMakeLists.txt ### Tested Tested in control, good to go if CI passes. GitOrigin-RevId: b3ac0f38af1cc0cbb30e5b138590be1d827e0c48
1 parent 9138282 commit 84ea2e9

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

control/CMakeLists.txt

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ project(exploy LANGUAGES CXX)
66
set(CMAKE_CXX_STANDARD 20)
77
set(CMAKE_CXX_STANDARD_REQUIRED ON)
88

9-
# Enable testing
10-
enable_testing()
9+
include(CTest)
1110

1211
# Treat warnings as errors
1312
add_compile_options(-Werror -Wpedantic -Wunused-variable -Wunused-parameter -Wreorder)
@@ -17,7 +16,6 @@ find_package(Eigen3 REQUIRED)
1716
find_package(nlohmann_json REQUIRED)
1817
find_package(fmt REQUIRED)
1918
find_package(onnxruntime REQUIRED)
20-
find_package(GTest REQUIRED)
2119

2220
# C++ Shared Library
2321
add_library(exploy SHARED
@@ -38,32 +36,37 @@ target_link_libraries(exploy PUBLIC
3836
)
3937

4038
# Tests
41-
set(GEN_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/test/testdata/test_onnx_generator.py")
42-
set(GEN_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/test/testdata/test.onnx")
39+
if(BUILD_TESTING)
40+
find_package(GTest REQUIRED)
41+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
4342

44-
add_custom_command(
45-
OUTPUT "${GEN_OUTPUT}"
46-
COMMAND ${CMAKE_COMMAND} -E env PYTHONWARNINGS="ignore" python3 "${GEN_SCRIPT}" "${GEN_OUTPUT}"
47-
DEPENDS "${GEN_SCRIPT}"
48-
COMMENT "Generating test ONNX model..."
49-
)
43+
set(GEN_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/test/testdata/test_onnx_generator.py")
44+
set(GEN_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/test/testdata/test.onnx")
5045

51-
add_executable(exploy_test
52-
test/controller_test.cpp
53-
test/components_test.cpp
54-
test/context_test.cpp
55-
test/logging_test.cpp
56-
test/metadata_test.cpp
57-
test/onnx_runtime_test.cpp
58-
"${GEN_OUTPUT}"
59-
)
60-
target_compile_definitions(exploy_test PRIVATE
61-
TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/testdata"
62-
)
63-
target_link_libraries(exploy_test PRIVATE
64-
exploy
65-
GTest::gtest_main
66-
GTest::gmock
67-
fmt::fmt
68-
)
69-
add_test(NAME exploy_test COMMAND exploy_test)
46+
add_custom_command(
47+
OUTPUT "${GEN_OUTPUT}"
48+
COMMAND ${CMAKE_COMMAND} -E env PYTHONWARNINGS="ignore" ${Python3_EXECUTABLE} "${GEN_SCRIPT}" "${GEN_OUTPUT}"
49+
DEPENDS "${GEN_SCRIPT}"
50+
COMMENT "Generating test ONNX model..."
51+
)
52+
53+
add_executable(exploy_test
54+
test/controller_test.cpp
55+
test/components_test.cpp
56+
test/context_test.cpp
57+
test/logging_test.cpp
58+
test/metadata_test.cpp
59+
test/onnx_runtime_test.cpp
60+
"${GEN_OUTPUT}"
61+
)
62+
target_compile_definitions(exploy_test PRIVATE
63+
TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/testdata"
64+
)
65+
target_link_libraries(exploy_test PRIVATE
66+
exploy
67+
GTest::gtest_main
68+
GTest::gmock
69+
fmt::fmt
70+
)
71+
add_test(NAME exploy_test COMMAND exploy_test)
72+
endif()

0 commit comments

Comments
 (0)