<target>_TESTS not available after gtest_discover_tests()
gtest_discover_tests() documentation says:
If more fine-grained test control is needed, custom content may be provided through an external CTest script using the TEST_INCLUDE_FILES directory property. The set of discovered tests is made accessible to such a script via the <target>_TESTS
variable.
This is not true. I have no way to access the <target>_TESTS
variable. Consider the following:
set_directory_properties(PROPERTIES TEST_INCLUDE_FILES ${PROJECT_BINARY_DIR}/ctest_custom.cmake)
gtest_discover_tests(MyTest)
The problem comes from the generated CTestTestfile.cmake:
include("ctest_custom.cmake")
include("MyTest[1]_include.cmake")
'MyTest[1]_include.cmake' includes 'MyTest[1]_tests.cmake' in which is defined the <target>_TESTS
variable.
So the issue here is that my custom script 'ctest_custom.cmake' is included before anything else in the CTestTestfile.cmake. But I would need it to be included last. If I do this change manually, then everything works and I can run my tests correctly.