GoogleTest: Avoid cluttering custom working directory during discovery

Since commit 1cdceae8e3 (GoogleTest: Parse discovered test list from
JSON output if supported, 2025-05-02, v4.2.0-rc1~533^2~2) we've placed
the discovery JSON files in the working directory provided by the user.
Place them in the current build tree folder instead.

Fixes: #27840
This commit is contained in:
Ottmar Zittlau
2026-06-07 11:18:47 +02:00
committed by Brad King
parent cdd5dbbba5
commit b5f555f687
2 changed files with 3 additions and 1 deletions

View File

@@ -700,6 +700,7 @@ function(gtest_discover_tests target)
" TEST_DISCOVERY_TIMEOUT" " [==[${arg_DISCOVERY_TIMEOUT}]==]" "\n"
" TEST_DISCOVERY_EXTRA_ARGS [==[${arg_DISCOVERY_EXTRA_ARGS}]==]" "\n"
" TEST_XML_OUTPUT_DIR" " [==[${arg_XML_OUTPUT_DIR}]==]" "\n"
" TEST_JSON_OUTPUT_DIR" " [==[${CMAKE_CURRENT_BINARY_DIR}]==]" "\n"
")" "\n"
)
file(GENERATE OUTPUT "${discovery_file}" CONTENT "${discovery_content}")

View File

@@ -143,6 +143,7 @@ function(gtest_discover_tests_impl)
CTEST_FILE
TEST_DISCOVERY_TIMEOUT
TEST_XML_OUTPUT_DIR
TEST_JSON_OUTPUT_DIR
TEST_FILTER
)
set(multiValueArgs
@@ -202,7 +203,7 @@ function(gtest_discover_tests_impl)
string(SHA256 target_hash "${arg_TEST_TARGET}")
string(SUBSTRING "${target_hash}" 0 10 target_hash)
set(json_file
"${arg_TEST_WORKING_DIR}/cmake_test_discovery_${target_hash}.json"
"${arg_TEST_JSON_OUTPUT_DIR}/cmake_test_discovery_${target_hash}.json"
)
# Remove json file to make sure we don't pick up an outdated one