# Generated by the Vitis IDE. Only modify the sections marked as USER SETTINGS.
if( ${VITIS_TARGET} STREQUAL x86sim )
  set (AIE_TARGET x86sim)
elseif(${VITIS_TARGET} STREQUAL hw_emu)
  set (AIE_TARGET hw)
else()
  set (AIE_TARGET ${VITIS_TARGET})
endif()

set(_CONTAINER_NAMES
binary_container_1
)


####    START OF USER SETTINGS    ####
# Below settings can be customized
# Adding any other command line options to be passed to v++ --link
set(USER_CONTAINER_LINKER_OPTIONS
""
)
####    Add any binary container specific linker options.    ####
set(USER_binary_container_1_OPTIONS
""
)
####    END OF USER SETTINGS    ####
####    CAUTION in updating below section    ####


# These setting are required to build the application as per the project
# template used. Update below only to modify the default settings.
# Below linker options are derived from the application template used to create
# this project. Update them to suite your requirement. They will not be modified
# further by the tool. If linker options are needed, they can be added to
# USER_CONTAINER_LINKER_OPTIONS listed above.
set(_CONTAINER_LINKER_OPTIONS
""
)


# Below build data files list is derived from the application template used to
# create this project. This will not be modified further by the tool.
set(_LINK_BUILD_DATAFILES
""
)


# Below linker options are derived from the application template used to create
# this project. Update them to suite your requirement. They will not be modified
# further by the tool. If new container specific linker options are needed, they
# can be added to USER_<binary container name>_OPTIONS listed above.
set(_binary_container_1_OPTIONS
""
)


# Below variables will be auto-updated based on kernels added/removed from the
# binary container.
set(_HW_LINK_PROJ
hw_link
)


# AIE libadf.a library will be added to HW Linker if project has AIE component.
set(_BINEXT
${VIVADO_HW_FLOW_ARCHIVE_EXT}
)
if(${_BINEXT} STREQUAL .vma )
  set (TARGET_OPTION_STRING )
else()
  set (TARGET_OPTION_STRING --target ${VITIS_TARGET})
endif()
set(_binary_container_1_KERNEL_XO_PATHS
mm2s/mm2s/mm2s.xo
s2mm/s2mm/s2mm.xo
)
set(_binary_container_1_USER_KERNEL_PATHS
""
)
set(_binary_container_1_USER_KERNEL_XO_PATHS
""
)
set(_binary_container_1_AIE_LIBADF_PATHS
${WORKSPACE_DIR}/aie_component/build/${AIE_TARGET}/libadf.a
)
set(_binary_container_1_USER_LIBADF_PATHS
""
)
set(_binary_container_1_USER_VSS_PATHS
""
)
set(_binary_container_1_CFG
hw_link/binary_container_1-link.cfg
)

##  End of variables auto-updated by the tool ##

foreach( datafile ${_LINK_BUILD_DATAFILES})
    file(COPY ${datafile} DESTINATION .)
endforeach()

foreach(CONTAINER ${_CONTAINER_NAMES})
	set(_KERNEL_XO ${_${CONTAINER}_KERNEL_XO_PATHS})
	list(TRANSFORM _KERNEL_XO PREPEND "${WORKSPACE_DIR}/")

	set(_USER_KERNEL_XO ${_${CONTAINER}_USER_KERNEL_XO_PATHS})

  set(_AIE_ARCHIVES
    ${_${CONTAINER}_AIE_LIBADF_PATHS}
    ${_${CONTAINER}_USER_LIBADF_PATHS}
  )

  set(_USER_VSS_PATHS
      ${_${CONTAINER}_USER_VSS_PATHS}
  )

	set(_XCLBIN  ${CONTAINER}${_BINEXT})

	#set(_KERNEL_TARGETS ${_${CONTAINER}_KERNEL_PATHS})
	#list(TRANSFORM _KERNEL_TARGETS REPLACE "/" "_")
	#list(TRANSFORM _KERNEL_TARGETS APPEND "_CompileXO")

	set(_CONTAINER_CFG ${_${CONTAINER}_CFG})
	list(TRANSFORM _CONTAINER_CFG PREPEND "${CMAKE_SOURCE_DIR}/")

	set(CONFIG_OPTIONS "")
	foreach( cfg ${_CONTAINER_CFG})
	    list(APPEND CONFIG_OPTIONS "--config")
	    list(APPEND CONFIG_OPTIONS ${cfg})
	endforeach()

	ADD_CUSTOM_COMMAND(OUTPUT ${_XCLBIN}
	    BYPRODUCTS ${CMAKE_BINARY_DIR}/${_HW_LINK_PROJ}/${_XCLBIN}.link_summary
        ${CMAKE_BINARY_DIR}/${_HW_LINK_PROJ}/${_XCLBIN}.info
        ${CMAKE_BINARY_DIR}/${_HW_LINK_PROJ}/${CONTAINER} .Xil xrc.log xcd.log
	  COMMAND ${Vitis_COMPILER}
			--platform ${VITIS_PLATFORM_PATH}
			${TARGET_OPTION_STRING} --link ${_KERNEL_XO} ${_USER_KERNEL_XO}
			${CONFIG_OPTIONS}
			${USER_CONTAINER_LINKER_OPTIONS}
			${_CONTAINER_LINKER_OPTIONS}
			${USER_${CONTAINER}_OPTIONS}  ${_AIE_ARCHIVES} ${_USER_VSS_PATHS}
			-o ${_XCLBIN}
	  DEPENDS ${_CONTAINER_CFG} ${_AIE_ARCHIVES} ${_USER_VSS_PATHS} ${_KERNEL_XO} ${_USER_KERNEL_XO}
	)
	ADD_CUSTOM_TARGET(VppLink_${CONTAINER} ALL
	   DEPENDS ${_XCLBIN} ${_LINK_BUILD_DATAFILES}
	)

	# For adding pre build step.
    # Any script can be used as a pre build step
    # Uncomment below section to use the pre-build step.
    # Example:  To copy a data file into to a pre-defined location.
    #add_custom_command(TARGET VppLink_${CONTAINER} PRE_BUILD
    #COMMAND cp   <source location>  <target location>
    #)

    # For adding post build step.
    # Any script can be used as a post build step, it can take the build output as input.
    # Uncomment below section to use the post build step.
    # Example:  To copy the binary to a pre-defined location.
    #add_custom_command(TARGET VppLink_${CONTAINER} POST_BUILD
    #COMMAND cp <source location> <target location>
    #)
endforeach()
