# get_all_tests(OUTVAR var [DIRECTORY dir]) # will produce a list (in var) containing all the tests # defined using add_test in the directory hierarchy starting at dir # (if not given dir defaults to $CMAKE_CURRENT_SOURCE_DIR) # function(get_all_tests) cmake_parse_arguments(PARSE_ARGV 0 A "" "OUTVAR;DIRECTORY" "") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() if(NOT A_DIRECTORY) set(A_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endif() set(tests) get_all_tests_recursive(tests ${A_DIRECTORY}) set(${A_OUTVAR} ${tests} PARENT_SCOPE) endfunction() macro(get_all_tests_recursive tests dir) get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) foreach(subdir ${subdirectories}) get_all_tests_recursive(${tests} ${subdir}) endforeach() get_property(current_tests DIRECTORY ${dir} PROPERTY TESTS) list(APPEND ${tests} ${current_tests}) endmacro()