function(add_litex_test)
    # ~~~
    # add_litex_test(
    #    litex_board <name of litex board>
    #    generated_sources <sources generated by litex>
    #    flags <list of litex flags>
    #    [loc_idelayctrl]
    # )
    #
    # Generates targets to generate LiteX-based designs

    set(options loc_idelayctrl)
    set(oneValueArgs litex_board)
    set(multiValueArgs generated_sources flags)

    cmake_parse_arguments(
        add_litex_test
        "${options}"
        "${oneValueArgs}"
        "${multiValueArgs}"
        ${ARGN}
    )

    set(litex_board ${add_litex_test_litex_board})
    set(generated_sources ${add_litex_test_generated_sources})
    set(flags ${add_litex_test_flags})
    set(loc_idelayctrl ${add_litex_test_loc_idelayctrl})

    set(gateware_dir ${CMAKE_CURRENT_BINARY_DIR}/${litex_board}/gateware/)

    list(TRANSFORM generated_sources PREPEND ${gateware_dir})

    get_target_property(PYTHON3 programs PYTHON3)
    set(quiet_cmd ${CMAKE_SOURCE_DIR}/utils/quiet_cmd.sh)

    # FIXME: add capability to place IDLEAYCTRL based on controlled IDELAYs location
    if(loc_idelayctrl)
        add_custom_command(
            OUTPUT ${generated_sources}
            COMMAND ${CMAKE_COMMAND} -E env
                ${quiet_cmd}
                ${PYTHON3} -mlitex_boards.targets.${litex_board}
                    --gateware-dir ${gateware_dir}
                    ${flags}
            COMMAND
                echo "" >> ${gateware_dir}${litex_board}.xdc &&
                echo "" >> ${gateware_dir}${litex_board}.xdc &&
                echo "set_property LOC IDELAYCTRL_X1Y0 [get_cells IDELAYCTRL]" >> ${gateware_dir}${litex_board}.xdc &&
                echo "" >> ${gateware_dir}${litex_board}.xdc &&
                echo "set_property BEL IDELAYCTRL [get_cells IDELAYCTRL]" >> ${gateware_dir}${litex_board}.xdc

        )
    else()
        add_custom_command(
            OUTPUT ${generated_sources}
            COMMAND ${CMAKE_COMMAND} -E env
                ${quiet_cmd}
                ${PYTHON3} -mlitex_boards.targets.${litex_board}
                    --gateware-dir ${gateware_dir}
                    ${flags}
        )
    endif()

endfunction()
