Using testPresets to filter gtest_discover_tests to ctest on android via adb push and adb shell

I am trying to use presets to solve a particular testing need in a codebase of mine. Specifically, my C++ code relies on lots of macros that are passed from CMake to conditionally compile code. In order to be able to properly test all those different code branches that depend on the macros, I wanted to use CMake presets to define the different configurations, build my test executable (that uses gtest) in all the relevant configurations, and then execute the test executable for each test configuration on an android device by pushing it via adb. I was hoping i could just use gtest_discover_tests and then apply a filter in my testPresets to only execute the relevant test(s) for a specific configuration (eg. only a test that is actually dependent on cmake configuration that changes macros for the tested code); however, I don’t know how I can specify a ctest run to actually push the test executable to the android device and then only run the test(s) that are filtered for by the test preset. Is there a way to do that? If it is not possible, I could isolate the macro-dependent tests in separate executables and just push and execute them via custom targets but i feel like this would undermine the purpose of ctest and the possibilities it offers in conjunction with gtest_discover_tests…

Here is a minimal example based on my description:
Root CMakeLists.txt:

cmake_minimum_required(VERSION 3.22.1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(MyProject)
add_subdirectory(my_library)
if (PROJECT_IS_TOP_LEVEL)
	cmake_minimum_required(VERSION 3.25.0) # support for packagePresets and workflowPresets
	enable_testing()
	add_subdirectory(test)
endif ()

test/CMakeLists.txt

include(FetchContent)
FetchContent_Declare(
    googletest
    URL https://github.com/google/googletest/archive/v1.15.0.zip
)
FetchContent_MakeAvailable(googletest)
add_executable(TestBinary main.cpp)
add_subdirectory(...)
target_link_libraries(TestBinary PRIVATE
    my_library
    gtest
    gtest_main
    ...
)
include(GoogleTest)
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST)
gtest_discover_tests(TestBinary)

An example test in test/main.cpp using gtest, which I want to filter for with a test preset like so “filter”: { “include”: { “name”: “MyTests\.ExampleBranchTest” } } :

#include <gtest/gtest.h>
TEST(MyTests, ExampleBranchTest)
{
	EXPECT_FALSE(some_function_with_macro_branches());
}

where some_function_with_macro_branches could look like:

bool some_function_with_macro_branches()
{
	#if defined(BRANCH_VALUE_MIN) && defined(BRANCH_VALUE_MAX)
	const auto result = MinMaxAlgorithm(BRANCH_VALUE_MIN, BRANCH_VALUE_MAX);
	#elifdef BRANCH_VALUE
	const auto result = BaseAlgorithm(BRANCH_VALUE);
	#else
	const auto result = FallbackAlgorithm();
	#endif
	// Further processing of result
	...
	return xyz;
}


In the end, I want the MyTests.ExampleBranchTest to be executed three times, once for each possible branch, as dictacted by CMake configurations that set the macro values for the branch checks.

To clarify, the most important part of the question is to answer how one can add a test and make sure that my test preset executes this test always with adb push, adb shell chmod +x, and finally adb shell (with a gtest filter somehow)
I verified that it is possible to use a custom build target to do that like so:

# Custom target to push the test binary to the Android device
add_custom_target(PushTestBinaryToAndroid
    COMMAND adb push $<TARGET_FILE:TestBinary> /data/local/tmp/TestBinary
    COMMAND adb shell chmod +x /data/local/tmp/TestBinary
    DEPENDS TestBinary
)
# Custom target to run the test binary on the Android device
add_custom_target(RunTestsOnAndroid
    COMMAND adb shell /data/local/tmp/TestBinary --gtest_filter=*
    DEPENDS PushTestBinaryToAndroid
)
# Ensure ctest depends on pushing and running the tests on the Android device
add_custom_target(ctest_with_adb
    COMMAND ctest --output-on-failure
    DEPENDS RunTestsOnAndroid
)

but that requires me to run it like this

cmake --build --preset test-default-build --target ctest_with_adb

instead of using ctest directly like i want:

ctest --preset test-default-build-test

For future reference, here is how I solved it after lots of attempts with different approaches:
First, i created an executable shell script that handles the steps necessary to execute the test binary on the android device:

#!/bin/bash

# Path to the binary on the host machine
BINARY_PATH=$1
# Use the GTEST_FILTER environment variable if it's set, otherwise use *
GTEST_FILTER=${GTEST_FILTER:-"*"}
# Push the binary to the Android device
adb push "$BINARY_PATH" /data/local/tmp/
# Make the binary executable
adb shell chmod +x /data/local/tmp/$(basename "$BINARY_PATH")
# Execute the tests on the device
adb shell "/data/local/tmp/$(basename "$BINARY_PATH") --gtest_filter=$GTEST_FILTER"
# Capture the exit code from the binary execution
EXIT_CODE=$?
# Return the exit code for ctest to process
exit $EXIT_CODE

Then, I add a test that uses this script in the COMMAND part of add_test

add_test(NAME AndroidTests
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_on_android.sh $<TARGET_FILE:TestBinary>
)

Note, how there is no reference to GoogleTest as well as the call to discover the gtests anymore.
Now, I am able to specify test presets that use the GTEST_FILTER environment variable to filter for certain gtests to execute like so:

"testPresets": [
		{
			"name": "test-default-build-test",
			"description": "Run all tests",
			"configurePreset": "test-default",
			"environment": {
				"GTEST_FILTER": "*"
			},
			"output": {
				"verbosity": "verbose"
			}
		}
	]

All of these things combined satisfy my original requirement of being able to define several configuration presets, each with a build and test preset that automatically executes the tests on an android device, while being able to filter for certain gtest tests in the presets (to be able to test the different code paths, as defined by CMake variables that are used as macros in the C++ code).