summaryrefslogtreecommitdiffstats
path: root/Modules/GoogleTest.cmake
diff options
context:
space:
mode:
authorMatthew Woehlke <matthew.woehlke@kitware.com>2017-11-20 17:53:25 (GMT)
committerBrad King <brad.king@kitware.com>2017-11-21 17:05:34 (GMT)
commit70f9f62da86d43c61435ea2d58782ba470d8d282 (patch)
tree8aa40945947795235871ebaa527ac1accc06ec1b /Modules/GoogleTest.cmake
parent7746fdb2fe0177341aadeafec2ae73aa08ddfaf6 (diff)
downloadCMake-70f9f62da86d43c61435ea2d58782ba470d8d282.zip
CMake-70f9f62da86d43c61435ea2d58782ba470d8d282.tar.gz
CMake-70f9f62da86d43c61435ea2d58782ba470d8d282.tar.bz2
GoogleTest: Fix multiple discovery on same target
According to the documentation, tests can be discovered for a target multiple times by using a different prefix and/or suffix to ensure name uniqueness. However, while this worked for gtest_add_tests, it did not work with gtest_discover_tests because the generated file that sets up the tests was named based only on the target name, and so subsequent discovery from the same target would clobber earlier discovery. Fix this by introducing a counter that records how many times discovery has been used on a target, and use this to generate unique names of the generated test list files.
Diffstat (limited to 'Modules/GoogleTest.cmake')
-rw-r--r--Modules/GoogleTest.cmake27
1 files changed, 25 insertions, 2 deletions
diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake
index 41bd1dc..3d47367 100644
--- a/Modules/GoogleTest.cmake
+++ b/Modules/GoogleTest.cmake
@@ -361,9 +361,32 @@ function(gtest_discover_tests TARGET)
set(_TEST_LIST ${TARGET}_TESTS)
endif()
+ get_property(
+ has_counter
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ SET
+ )
+ if(has_counter)
+ get_property(
+ counter
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ )
+ math(EXPR counter "${counter} + 1")
+ else()
+ set(counter 1)
+ endif()
+ set_property(
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ ${counter}
+ )
+
# Define rule to generate test list for aforementioned test executable
- set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include.cmake")
- set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake")
+ set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}[${counter}]")
+ set(ctest_include_file "${ctest_file_base}_include.cmake")
+ set(ctest_tests_file "${ctest_file_base}_tests.cmake")
get_property(crosscompiling_emulator
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR