function(add_fn_testees prefix)
    foreach(backend IN LISTS ARGN)
        set(tgt ${prefix}_${backend})
        add_library(${tgt} INTERFACE)
        target_link_libraries(${tgt} INTERFACE fn_${backend})
        string(TOUPPER ${backend} u_backend)
        target_compile_definitions(${tgt} INTERFACE GT_FN_${u_backend})
        if (backend STREQUAL gpu)
            target_link_libraries(${tgt} INTERFACE storage_gpu)
        elseif (backend STREQUAL naive)
            target_link_libraries(${tgt} INTERFACE storage_cpu_kfirst)
        endif()
    endforeach()
endfunction()
add_fn_testees(fn_testee ${GT_FN_BACKENDS})

function(gridtools_add_fn_regression_test tgt_name)
    gridtools_add_regression_test(${tgt_name} ${ARGN}
        LIB_PREFIX fn_testee
        KEYS ${GT_FN_BACKENDS}
        LABELS fn)
endfunction()

gridtools_add_fn_regression_test(fn_cartesian_horizontal_diffusion SOURCES fn_cartesian_horizontal_diffusion.cpp PERFTEST)
gridtools_add_fn_regression_test(fn_copy SOURCES fn_copy.cpp PERFTEST)
gridtools_add_fn_regression_test(fn_unstructured_nabla SOURCES fn_unstructured_nabla.cpp PERFTEST)
gridtools_add_fn_regression_test(fn_tridiagonal_solve SOURCES fn_tridiagonal_solve.cpp PERFTEST)
gridtools_add_fn_regression_test(fn_cartesian_vertical_advection SOURCES fn_cartesian_vertical_advection.cpp PERFTEST)
gridtools_add_fn_regression_test(fn_domain SOURCES fn_domain.cpp)
gridtools_add_fn_regression_test(fn_vertical_indirection SOURCES fn_vertical_indirection.cpp)
