macro(add_slicot_test name src)
    get_filename_component(baseNAME ${src} NAME_WE)
    string(SUBSTRING ${baseNAME} 1 -1 baseNAME)
    set(TEST_INPUT  "${CMAKE_CURRENT_SOURCE_DIR}/data/${baseNAME}.dat")
    set(TEST_RESULT "${CMAKE_CURRENT_SOURCE_DIR}/results/${baseNAME}.res")
    set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${baseNAME}.exa")


    # if(EXISTS "${TEST_INPUT}")
    #     MESSAGE(STATUS "Test Input ${TEST_INPUT} exists")
    # else()
    #     MESSAGE(STATUS "Test Input ${TEST_INPUT} does not exist")
    # endif()
    add_executable(${name} ${src})
    target_link_libraries(${name} SLICOT::slicot)
    if(EXISTS "${TEST_INPUT}")
       if (EXISTS "${TEST_RESULT}")
            add_test(NAME test-${baseNAME} COMMAND "${CMAKE_COMMAND}"
                -DTEST=$<TARGET_FILE:${name}>
                -DINPUT=${TEST_INPUT}
                -DOUTPUT=${TEST_OUTPUT}
                -DRESULT=${TEST_RESULT}
                -DINTDIR=${CMAKE_CFG_INTDIR}
                -P "${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake")

            set_property(TEST test-${baseNAME} PROPERTY
                ATTACHED_FILES "${TEST_INPUT};${TEST_RESULT};${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake")
        else()
            add_test(NAME test-${baseNAME} COMMAND "${CMAKE_COMMAND}"
                -DTEST=$<TARGET_FILE:${name}>
                -DINPUT=${TEST_INPUT}
                -DOUTPUT=${TEST_OUTPUT}
                -DINTDIR=${CMAKE_CFG_INTDIR}
                -P "${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake")
            set_property(TEST test-${baseNAME} PROPERTY
                ATTACHED_FILES "${TEST_INPUT};${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake")

        endif()
    else()
        add_test(NAME test-${name} COMMAND "${CMAKE_COMMAND}"
            -DTEST=$<TARGET_FILE:${name}>
            -DOUTPUT=${TEST_OUTPUT}
            -DINTDIR=${CMAKE_CFG_INTDIR}
            -P "${LAPACK_SOURCE_DIR}/TESTING/runtest.cmake")
        set_property(TEST test-${baseNAME} PROPERTY
            ATTACHED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake")


    endif()
endmacro()


add_slicot_test(TAB01MD TAB01MD.f)
add_slicot_test(TAB01ND TAB01ND.f)
add_slicot_test(TAB01OD TAB01OD.f)
add_slicot_test(TAB04MD TAB04MD.f)
add_slicot_test(TAB05MD TAB05MD.f)
add_slicot_test(TAB05ND TAB05ND.f)
add_slicot_test(TAB05OD TAB05OD.f)
add_slicot_test(TAB05PD TAB05PD.f)
add_slicot_test(TAB05QD TAB05QD.f)
add_slicot_test(TAB05RD TAB05RD.f)
add_slicot_test(TAB07MD TAB07MD.f)
add_slicot_test(TAB07ND TAB07ND.f)
add_slicot_test(TAB08ND TAB08ND.f)
add_slicot_test(TAB08NW TAB08NW.f)
add_slicot_test(TAB08NZ TAB08NZ.f)
add_slicot_test(TAB09AD TAB09AD.f)
add_slicot_test(TAB09BD TAB09BD.f)
add_slicot_test(TAB09CD TAB09CD.f)
add_slicot_test(TAB09DD TAB09DD.f)
add_slicot_test(TAB09ED TAB09ED.f)
add_slicot_test(TAB09FD TAB09FD.f)
add_slicot_test(TAB09GD TAB09GD.f)
add_slicot_test(TAB09HD TAB09HD.f)
add_slicot_test(TAB09ID TAB09ID.f)
add_slicot_test(TAB09JD TAB09JD.f)
add_slicot_test(TAB09KD TAB09KD.f)
add_slicot_test(TAB09MD TAB09MD.f)
add_slicot_test(TAB09ND TAB09ND.f)
add_slicot_test(TAB13AD TAB13AD.f)
add_slicot_test(TAB13BD TAB13BD.f)
add_slicot_test(TAB13CD TAB13CD.f)
add_slicot_test(TAB13DD TAB13DD.f)
add_slicot_test(TAB13ED TAB13ED.f)
add_slicot_test(TAB13FD TAB13FD.f)
add_slicot_test(TAB13ID TAB13ID.f)
add_slicot_test(TAB13MD TAB13MD.f)
add_slicot_test(TAG08BD TAG08BD.f)
add_slicot_test(TAG08BZ TAG08BZ.f)
add_slicot_test(TBB01AD TBB01AD.f)
add_slicot_test(TBB02AD TBB02AD.f)
add_slicot_test(TBB03AD TBB03AD.f)
add_slicot_test(TBB04AD TBB04AD.f)
add_slicot_test(TBD01AD TBD01AD.f)
add_slicot_test(TBD02AD TBD02AD.f)
add_slicot_test(TDE01OD TDE01OD.f)
add_slicot_test(TDE01PD TDE01PD.f)
add_slicot_test(TDF01MD TDF01MD.f)
add_slicot_test(TDG01MD TDG01MD.f)
add_slicot_test(TDG01ND TDG01ND.f)
add_slicot_test(TDG01OD TDG01OD.f)
add_slicot_test(TDK01MD TDK01MD.f)
add_slicot_test(TFB01QD TFB01QD.f)
add_slicot_test(TFB01RD TFB01RD.f)
add_slicot_test(TFB01SD TFB01SD.f)
add_slicot_test(TFB01TD TFB01TD.f)
add_slicot_test(TFB01VD TFB01VD.f)
add_slicot_test(TFD01AD TFD01AD.f)
add_slicot_test(TIB01AD TIB01AD.f)
add_slicot_test(TIB01BD TIB01BD.f)
add_slicot_test(TIB01CD TIB01CD.f)
add_slicot_test(TIB03AD TIB03AD.f)
add_slicot_test(TIB03BD TIB03BD.f)
add_slicot_test(TMB01TD TMB01TD.f)
add_slicot_test(TMB02CD TMB02CD.f)
add_slicot_test(TMB02DD TMB02DD.f)
add_slicot_test(TMB02ED TMB02ED.f)
add_slicot_test(TMB02FD TMB02FD.f)
add_slicot_test(TMB02GD TMB02GD.f)
add_slicot_test(TMB02HD TMB02HD.f)
add_slicot_test(TMB02ID TMB02ID.f)
add_slicot_test(TMB02JD TMB02JD.f)
add_slicot_test(TMB02JX TMB02JX.f)
add_slicot_test(TMB02KD TMB02KD.f)
add_slicot_test(TMB02MD TMB02MD.f)
add_slicot_test(TMB02ND TMB02ND.f)
add_slicot_test(TMB02QD TMB02QD.f)
add_slicot_test(TMB02SD TMB02SD.f)
add_slicot_test(TMB02VD TMB02VD.f)
add_slicot_test(TMB03BD TMB03BD.f)
add_slicot_test(TMB03BZ TMB03BZ.f)
add_slicot_test(TMB03FZ TMB03FZ.f)
add_slicot_test(TMB03KD TMB03KD.f)
add_slicot_test(TMB03LD TMB03LD.f)
add_slicot_test(TMB03LF TMB03LF.f)
add_slicot_test(TMB03LZ TMB03LZ.f)
add_slicot_test(TMB03MD TMB03MD.f)
add_slicot_test(TMB03ND TMB03ND.f)
add_slicot_test(TMB03OD TMB03OD.f)
add_slicot_test(TMB03PD TMB03PD.f)
add_slicot_test(TMB03QD TMB03QD.f)
add_slicot_test(TMB03QG TMB03QG.f)
add_slicot_test(TMB03RD TMB03RD.f)
add_slicot_test(TMB03SD TMB03SD.f)
add_slicot_test(TMB03TD TMB03TD.f)
add_slicot_test(TMB03UD TMB03UD.f)
add_slicot_test(TMB03VD TMB03VD.f)
add_slicot_test(TMB03WD TMB03WD.f)
add_slicot_test(TMB03XD TMB03XD.f)
add_slicot_test(TMB03XP TMB03XP.f)
add_slicot_test(TMB03XZ TMB03XZ.f)
add_slicot_test(TMB03ZD TMB03ZD.f)
add_slicot_test(TMB04AD TMB04AD.f)
add_slicot_test(TMB04AZ TMB04AZ.f)
add_slicot_test(TMB04BD TMB04BD.f)
add_slicot_test(TMB04BZ TMB04BZ.f)
add_slicot_test(TMB04DD TMB04DD.f)
add_slicot_test(TMB04DL TMB04DL.f)
add_slicot_test(TMB04DP TMB04DP.f)
add_slicot_test(TMB04DS TMB04DS.f)
add_slicot_test(TMB04DY TMB04DY.f)
add_slicot_test(TMB04DZ TMB04DZ.f)
add_slicot_test(TMB04ED TMB04ED.f)
add_slicot_test(TMB04FD TMB04FD.f)
add_slicot_test(TMB04GD TMB04GD.f)
add_slicot_test(TMB04MD TMB04MD.f)
add_slicot_test(TMB04OD TMB04OD.f)
add_slicot_test(TMB04PB TMB04PB.f)
add_slicot_test(TMB04PU TMB04PU.f)
add_slicot_test(TMB04TB TMB04TB.f)
add_slicot_test(TMB04TS TMB04TS.f)
add_slicot_test(TMB04UD TMB04UD.f)
add_slicot_test(TMB04VD TMB04VD.f)
add_slicot_test(TMB04XD TMB04XD.f)
add_slicot_test(TMB04YD TMB04YD.f)
add_slicot_test(TMB04ZD TMB04ZD.f)
add_slicot_test(TMB05MD TMB05MD.f)
add_slicot_test(TMB05ND TMB05ND.f)
add_slicot_test(TMB05OD TMB05OD.f)
add_slicot_test(TMB4DLZ TMB4DLZ.f)
add_slicot_test(TMB4DPZ TMB4DPZ.f)
add_slicot_test(TMC01MD TMC01MD.f)
add_slicot_test(TMC01ND TMC01ND.f)
add_slicot_test(TMC01OD TMC01OD.f)
add_slicot_test(TMC01PD TMC01PD.f)
add_slicot_test(TMC01QD TMC01QD.f)
add_slicot_test(TMC01RD TMC01RD.f)
add_slicot_test(TMC01SD TMC01SD.f)
add_slicot_test(TMC01TD TMC01TD.f)
add_slicot_test(TMC01VD TMC01VD.f)
add_slicot_test(TMC01WD TMC01WD.f)
add_slicot_test(TMC01XD TMC01XD.f)
add_slicot_test(TMC03MD TMC03MD.f)
add_slicot_test(TMC03ND TMC03ND.f)
add_slicot_test(TMD03AD TMD03AD.f)
add_slicot_test(TMD03BD TMD03BD.f)
add_slicot_test(TSB01BD TSB01BD.f)
add_slicot_test(TSB01DD TSB01DD.f)
add_slicot_test(TSB01MD TSB01MD.f)
add_slicot_test(TSB02MD TSB02MD.f)
add_slicot_test(TSB02ND TSB02ND.f)
add_slicot_test(TSB02OD TSB02OD.f)
add_slicot_test(TSB02PD TSB02PD.f)
add_slicot_test(TSB02QD TSB02QD.f)
add_slicot_test(TSB02RD TSB02RD.f)
add_slicot_test(TSB02SD TSB02SD.f)
add_slicot_test(TSB03MD TSB03MD.f)
add_slicot_test(TSB03OD TSB03OD.f)
add_slicot_test(TSB03QD TSB03QD.f)
add_slicot_test(TSB03SD TSB03SD.f)
add_slicot_test(TSB03TD TSB03TD.f)
add_slicot_test(TSB03UD TSB03UD.f)
add_slicot_test(TSB04MD TSB04MD.f)
add_slicot_test(TSB04ND TSB04ND.f)
add_slicot_test(TSB04OD TSB04OD.f)
add_slicot_test(TSB04PD TSB04PD.f)
add_slicot_test(TSB04QD TSB04QD.f)
add_slicot_test(TSB04RD TSB04RD.f)
add_slicot_test(TSB06ND TSB06ND.f)
add_slicot_test(TSB08CD TSB08CD.f)
add_slicot_test(TSB08DD TSB08DD.f)
add_slicot_test(TSB08ED TSB08ED.f)
add_slicot_test(TSB08FD TSB08FD.f)
add_slicot_test(TSB08MD TSB08MD.f)
add_slicot_test(TSB08ND TSB08ND.f)
add_slicot_test(TSB09MD TSB09MD.f)
add_slicot_test(TSB10DD TSB10DD.f)
add_slicot_test(TSB10ED TSB10ED.f)
add_slicot_test(TSB10FD TSB10FD.f)
add_slicot_test(TSB10HD TSB10HD.f)
add_slicot_test(TSB10ID TSB10ID.f)
add_slicot_test(TSB10KD TSB10KD.f)
add_slicot_test(TSB10ZD TSB10ZD.f)
add_slicot_test(TSB16AD TSB16AD.f)
add_slicot_test(TSB16BD TSB16BD.f)
add_slicot_test(TSB16CD TSB16CD.f)
add_slicot_test(TSG02AD TSG02AD.f)
add_slicot_test(TSG02ND TSG02ND.f)
add_slicot_test(TSG03AD TSG03AD.f)
add_slicot_test(TSG03BD TSG03BD.f)
add_slicot_test(TTB01ID TTB01ID.f)
add_slicot_test(TTB01IZ TTB01IZ.f)
add_slicot_test(TTB01KD TTB01KD.f)
add_slicot_test(TTB01LD TTB01LD.f)
add_slicot_test(TTB01MD TTB01MD.f)
add_slicot_test(TTB01ND TTB01ND.f)
add_slicot_test(TTB01PD TTB01PD.f)
add_slicot_test(TTB01PX TTB01PX.f)
add_slicot_test(TTB01TD TTB01TD.f)
add_slicot_test(TTB01UD TTB01UD.f)
add_slicot_test(TTB01UY TTB01UY.f)
add_slicot_test(TTB01WD TTB01WD.f)
add_slicot_test(TTB01WX TTB01WX.f)
add_slicot_test(TTB01ZD TTB01ZD.f)
add_slicot_test(TTB03AD TTB03AD.f)
add_slicot_test(TTB04AD TTB04AD.f)
add_slicot_test(TTB04BD TTB04BD.f)
add_slicot_test(TTB04CD TTB04CD.f)
add_slicot_test(TTB05AD TTB05AD.f)
add_slicot_test(TTC01OD TTC01OD.f)
add_slicot_test(TTC04AD TTC04AD.f)
add_slicot_test(TTC05AD TTC05AD.f)
add_slicot_test(TTD03AD TTD03AD.f)
add_slicot_test(TTD04AD TTD04AD.f)
add_slicot_test(TTD05AD TTD05AD.f)
add_slicot_test(TTF01MD TTF01MD.f)
add_slicot_test(TTF01ND TTF01ND.f)
add_slicot_test(TTF01OD TTF01OD.f)
add_slicot_test(TTF01PD TTF01PD.f)
add_slicot_test(TTF01QD TTF01QD.f)
add_slicot_test(TTF01RD TTF01RD.f)
add_slicot_test(TTG01AD TTG01AD.f)
add_slicot_test(TTG01AZ TTG01AZ.f)
add_slicot_test(TTG01CD TTG01CD.f)
add_slicot_test(TTG01DD TTG01DD.f)
add_slicot_test(TTG01ED TTG01ED.f)
add_slicot_test(TTG01FD TTG01FD.f)
add_slicot_test(TTG01FZ TTG01FZ.f)
add_slicot_test(TTG01GD TTG01GD.f)
add_slicot_test(TTG01HD TTG01HD.f)
add_slicot_test(TTG01ID TTG01ID.f)
add_slicot_test(TTG01JD TTG01JD.f)
add_slicot_test(TTG01JY TTG01JY.f)
add_slicot_test(TTG01LD TTG01LD.f)
add_slicot_test(TTG01MD TTG01MD.f)
add_slicot_test(TTG01ND TTG01ND.f)
add_slicot_test(TTG01PD TTG01PD.f)
add_slicot_test(TTG01QD TTG01QD.f)
add_slicot_test(TUD01BD TUD01BD.f)
add_slicot_test(TUD01CD TUD01CD.f)
add_slicot_test(TUD01DD TUD01DD.f)
add_slicot_test(TUD01MD TUD01MD.f)
add_slicot_test(TUD01ND TUD01ND.f)
