You can use CTest (it's usually installed along with CMake) to achieve this.
First, you need to include
the CTest module in your CMakeLists.txt, then you just need to use the add_test
command for each of your test executables:
include(CTest)
add_subdirectory(/usr/src/gtest gtest)
include_directories(${GTEST_INCLUDE_DIR})
add_executable(TestA TestA.cpp)
target_link_libraries(TestA gtest)
add_test(NAME AllTestsInA COMMAND TestA)
add_executable(TestB TestB.cpp)
target_link_libraries(TestB gtest)
add_test(NAME AllTestsInB COMMAND TestB)
add_executable(TestC TestC.cpp)
target_link_libraries(TestC gtest)
add_test(NAME AllTestsInC COMMAND TestC)
Now, once your test exes are built, from your build folder you can execute CTest to run all the tests. E.g. to run the Debug tests:
ctest -C Debug
or to get more verbose output:
ctest -C Debug -V