From c50325b8e55e55306fbf8bca38128303b82a51a9 Mon Sep 17 00:00:00 2001 From: Nikolay Orliuk Date: Wed, 26 Feb 2014 14:47:38 +0200 Subject: [PATCH 1/2] FindGTest: Optionally detect sources automatically (#14775) Teach GTEST_ADD_TESTS an "AUTO" option to read the source files from the SOURCES target property of an executable. --- Modules/FindGTest.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake index c00a750f1..aa3c235d1 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}) From ac42bca8330e0501d2fbf80dbe6d4d93234ba0c0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 Feb 2014 08:54:13 -0500 Subject: [PATCH 2/2] Help: Add FindGTest-AUTO-SOURCES topic release notes --- Help/release/dev/FindGTest-AUTO-SOURCES.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Help/release/dev/FindGTest-AUTO-SOURCES.rst diff --git a/Help/release/dev/FindGTest-AUTO-SOURCES.rst b/Help/release/dev/FindGTest-AUTO-SOURCES.rst new file mode 100644 index 000000000..17b2a1b17 --- /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.