I have made a small edit to the FindGTest module that eliminates the need
to manually rerun cmake when new tests are added to existing test files
when using the gtest_add_tests function.  There are false positives when
the test files are modified without adding/removing tests.  Additionally it
adds a copy of the test source files in the cmake_current_binary_directory
(since configure_file is used to add the dependency).

Zak
From 34114d973372f3380b6aed29c62a6e47f6642546 Mon Sep 17 00:00:00 2001
From: GodricSeer <[email protected]>
Date: Fri, 11 Mar 2016 11:23:32 -0500
Subject: [PATCH] Eliminated need to rerun cmake when changing tests

By configuring each test source file with COPYONLY this adds a dependency between the make target rebuild_cache and all of the test source files parsed by gtest_add_tests.  Now whenever those files are changed, cmake will automatically rerun to include any new/remove any deleted tests.
---
 Modules/FindGTest.cmake |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index ca49e4a..9f5ddbe 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -82,8 +82,7 @@
 #   ``AUTO`` to find them from executable target
 #
 # However, note that this macro will slow down your tests by running
-# an executable for each test and test fixture.  You will also have to
-# re-run CMake after adding or removing tests or test fixtures.
+# an executable for each test and test fixture.
 #
 # Example usage::
 #
@@ -119,6 +118,7 @@ function(GTEST_ADD_TESTS executable extra_args)
     set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+) *, *([A-Za-z_0-9]+) *\\).*")
     set(gtest_test_type_regex "(TYPED_TEST|TEST_?[FP]?)")
     foreach(source ${ARGN})
+        configure_file(${source} ${source}.out COPYONLY)
         file(READ "${source}" contents)
         string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
         foreach(hit ${found_tests})
-- 
1.7.1

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to