From 4d4d814d1959ac8f7b5ea575e599da6c97aa5a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Wed, 1 Apr 2026 10:05:12 +0300 Subject: [PATCH] fix(cmake): add proper gtest filtering (#26861) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmake/px4_add_gtest.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmake/px4_add_gtest.cmake b/cmake/px4_add_gtest.cmake index 7b4d1bc4c9..2cb605e061 100644 --- a/cmake/px4_add_gtest.cmake +++ b/cmake/px4_add_gtest.cmake @@ -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 @@ -74,7 +83,7 @@ function(px4_add_unit_gtest) WORKING_DIRECTORY ${PX4_BINARY_DIR}) # attach it to the unit test target - add_dependencies(test_results ${TESTNAME}) + add_filtered_test_dependencies(${TESTNAME}) endif() endfunction() @@ -133,6 +142,6 @@ function(px4_add_functional_gtest) COMMAND ${PX4_BINARY_DIR}/${TESTNAME}) # attach it to the unit test target - add_dependencies(test_results ${TESTNAME}) + add_filtered_test_dependencies(${TESTNAME}) endif() endfunction()