function(rox_add_tests FILE_EXT LIBS)
    set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${ARGN})
    file(GLOB children RELATIVE ${TEST_DIR} ${TEST_DIR}/*)
    message("Adding tests from ${TEST_DIR}")
    if (ARGN)
        set(TEST_PATH ${ARGN}/)
    else ()
        set(TEST_PATH "")
    endif ()
    foreach (child ${children})
        if (IS_DIRECTORY ${TEST_DIR}/${child})
            rox_add_tests("${FILE_EXT}" "${LIBS}" "${TEST_PATH}${child}")
        else ()
            get_filename_component(TEST_FILE_EXT ${child} EXT)
            if ("${TEST_FILE_EXT}" STREQUAL ${FILE_EXT} AND ${child} MATCHES "^test_")
                get_filename_component(TEST_NAME ${child} NAME_WE)
                string(REPLACE "/" "_" TEST_PREFIX "${TEST_PATH}")
                set(TEST_TARGET "${TEST_PREFIX}${TEST_NAME}")
                if (NOT (ROX_SKIP_TESTS AND "${TEST_TARGET}" IN_LIST ROX_SKIP_TESTS))
                    add_executable("${TEST_TARGET}" ${TEST_PATH}${child})
                    add_test(${TEST_TARGET} ${TEST_TARGET})
                    target_link_libraries(${TEST_TARGET} ${LIBS})
                    if (ROX_CLIENT)
                        set_target_properties(${TEST_TARGET} PROPERTIES COMPILE_DEFINITIONS "ROX_CLIENT")
                    endif ()
                else ()
                    message("Skipping test ${TEST_TARGET}")
                endif ()
            endif ()
        endif ()
    endforeach ()
endfunction()