fix(cmake): add proper gtest filtering (#26861)

Before this change, filtered test runs still built every gtest target
because `test_results` depended on all unit and functional gtest targets.

This updates both `px4_add_unit_gtest()` and `px4_add_functional_gtest()`
to use the filtered dependency helper so filtered runs only build the
selected targets.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
This commit is contained in:
Onur Özkan 2026-04-01 10:05:12 +03:00 committed by GitHub
parent 14086c6f2e
commit 4d4d814d19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,15 @@
# #
############################################################################ ############################################################################
# Attach only matching test binaries to `test_results` when TESTFILTER is set.
# `ctest -R` filters execution only; without this helper the build still
# compiles every gtest target before running the filtered subset.
function(add_filtered_test_dependencies TESTNAME)
if(NOT TESTFILTER OR "${TESTNAME}" MATCHES "${TESTFILTER}")
add_dependencies(test_results ${TESTNAME})
endif()
endfunction()
#============================================================================= #=============================================================================
# #
# px4_add_unit_gtest # px4_add_unit_gtest
@ -74,7 +83,7 @@ function(px4_add_unit_gtest)
WORKING_DIRECTORY ${PX4_BINARY_DIR}) WORKING_DIRECTORY ${PX4_BINARY_DIR})
# attach it to the unit test target # attach it to the unit test target
add_dependencies(test_results ${TESTNAME}) add_filtered_test_dependencies(${TESTNAME})
endif() endif()
endfunction() endfunction()
@ -133,6 +142,6 @@ function(px4_add_functional_gtest)
COMMAND ${PX4_BINARY_DIR}/${TESTNAME}) COMMAND ${PX4_BINARY_DIR}/${TESTNAME})
# attach it to the unit test target # attach it to the unit test target
add_dependencies(test_results ${TESTNAME}) add_filtered_test_dependencies(${TESTNAME})
endif() endif()
endfunction() endfunction()