summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Help/release/dev/FindGTest-AUTO-SOURCES.rst7
-rw-r--r--Modules/FindGTest.cmake8
2 files changed, 13 insertions, 2 deletions
diff --git a/Help/release/dev/FindGTest-AUTO-SOURCES.rst b/Help/release/dev/FindGTest-AUTO-SOURCES.rst
new file mode 100644
index 0000000000..17b2a1b17b
--- /dev/null
+++ b/Help/release/dev/FindGTest-AUTO-SOURCES.rst
@@ -0,0 +1,7 @@
+FindGTest-AUTO-SOURCES
+----------------------
+
+* The :module:`FindGTest` module ``gtest_add_tests`` macro learned
+ a new ``AUTO`` option to automatically read the :prop_tgt:`SOURCES`
+ target property of the test executable and scan the source files
+ for tests to be added.
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index c00a750f12..aa3c235d10 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -79,7 +79,7 @@
# extra_args = Pass a list of extra arguments to be passed to
# executable enclosed in quotes (or "" for none)
# ARGN = A list of source files to search for tests & test
-# fixtures.
+# fixtures. Or AUTO to find them from executable target.
#
#
#
@@ -88,7 +88,7 @@
# Example:
# set(FooTestArgs --foo 1 --bar 2)
# add_executable(FooTest FooUnitTest.cc)
-# GTEST_ADD_TESTS(FooTest "${FooTestArgs}" FooUnitTest.cc)
+# GTEST_ADD_TESTS(FooTest "${FooTestArgs}" AUTO)
#=============================================================================
# Copyright 2009 Kitware, Inc.
@@ -111,6 +111,10 @@ function(GTEST_ADD_TESTS executable extra_args)
if(NOT ARGN)
message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
endif()
+ if(ARGN STREQUAL "AUTO")
+ # obtain sources used for building that executable
+ get_property(ARGN TARGET ${executable} PROPERTY SOURCES)
+ endif()
foreach(source ${ARGN})
file(READ "${source}" contents)
string(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})