[hit] Add support for specifying dependencies in HIT syntax (#1323)
This commit is contained in:
+36
-4
@@ -3,7 +3,7 @@ find_package(HIP REQUIRED)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Helper macro to parse BUILD instructions
|
||||
macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _dir)
|
||||
macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _depends _dir)
|
||||
set(${_target})
|
||||
set(${_sources})
|
||||
set(${_hipcc_options})
|
||||
@@ -11,12 +11,14 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt
|
||||
set(${_nvcc_options})
|
||||
set(${_link_options})
|
||||
set(${_exclude_platforms})
|
||||
set(${_depends})
|
||||
set(_target_found FALSE)
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found FALSE)
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
@@ -27,30 +29,42 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xHCC_OPTIONS")
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found TRUE)
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xNVCC_OPTIONS")
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found FALSE)
|
||||
set(_nvcc_options_found TRUE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xLINK_OPTIONS")
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found FALSE)
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found TRUE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found FALSE)
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found TRUE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xDEPENDS")
|
||||
set(_hipcc_options_found FALSE)
|
||||
set(_hcc_options_found FALSE)
|
||||
set(_nvcc_options_found FALSE)
|
||||
set(_link_options_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found TRUE)
|
||||
else()
|
||||
if(_hipcc_options_found)
|
||||
list(APPEND ${_hipcc_options} ${arg})
|
||||
@@ -62,6 +76,8 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt
|
||||
list(APPEND ${_link_options} ${arg})
|
||||
elseif(_exclude_platforms_found)
|
||||
set(${_exclude_platforms} ${arg})
|
||||
elseif(_depends_found)
|
||||
list(APPEND ${_depends} ${arg})
|
||||
else()
|
||||
list(APPEND ${_sources} "${_dir}/${arg}")
|
||||
endif()
|
||||
@@ -70,21 +86,29 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt
|
||||
endmacro()
|
||||
|
||||
# Helper macro to parse CUSTOM BUILD instructions
|
||||
macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms)
|
||||
macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms _depends)
|
||||
set(${_target})
|
||||
set(${_buildcmd} " ")
|
||||
set(${_exclude_platforms})
|
||||
set(${_depends})
|
||||
set(_target_found FALSE)
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found FALSE)
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
set(${_target} ${arg})
|
||||
elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
set(_exclude_platforms_found TRUE)
|
||||
set(_depends_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "xDEPENDS")
|
||||
set(_exclude_platforms_found FALSE)
|
||||
set(_depends_found TRUE)
|
||||
else()
|
||||
if(_exclude_platforms_found)
|
||||
set(${_exclude_platforms} ${arg})
|
||||
elseif(_depends_found)
|
||||
list(APPEND ${_depends} ${arg})
|
||||
else()
|
||||
list(APPEND ${_buildcmd} ${arg})
|
||||
endif()
|
||||
@@ -179,7 +203,7 @@ macro(HIT_ADD_FILES _dir _label _parent)
|
||||
string(REGEX REPLACE "\n" ";" _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_build_command(_target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms ${_dir} ${_cmd})
|
||||
parse_build_command(_target _sources _hipcc_options _hcc_options _nvcc_options _link_options _exclude_platforms _depends ${_dir} ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
insert_into_map("_exclude" "${target}" "${_exclude_platforms}")
|
||||
if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM})
|
||||
@@ -190,6 +214,10 @@ macro(HIT_ADD_FILES _dir _label _parent)
|
||||
target_link_libraries(${target} PRIVATE ${_link_options})
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${_target} RUNTIME_OUTPUT_DIRECTORY ${_label} LINK_DEPENDS "${HIP_LIB_FILES}")
|
||||
add_dependencies(${_parent} ${target})
|
||||
foreach(_dependency ${_depends})
|
||||
string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency})
|
||||
add_dependencies(${target} ${_dependency})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -208,7 +236,7 @@ macro(HIT_ADD_FILES _dir _label _parent)
|
||||
string(REGEX REPLACE "%T" ${_label} _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_custombuild_command(_target _buildcmd _exclude_platforms ${_cmd})
|
||||
parse_custombuild_command(_target _buildcmd _exclude_platforms _depends ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
insert_into_map("_exclude" "${target}" "${_exclude_platforms}")
|
||||
if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM})
|
||||
@@ -219,6 +247,10 @@ macro(HIT_ADD_FILES _dir _label _parent)
|
||||
#add_custom_target(${target} COMMAND ${buildscript})
|
||||
add_custom_target(${target} COMMAND sh -c "${_buildcmd}")
|
||||
add_dependencies(${_parent} ${target})
|
||||
foreach(_dependency ${_depends})
|
||||
string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency})
|
||||
add_dependencies(${target} ${_dependency})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user