cmake_minimum_required(VERSION 3.16.0)
project(tools_third_party)
set(_ms_root "")
set(_ms_candidates
"${CANN_3RD_LIB_PATH}"
"${CANN_3RD_LIB_PATH}/../mindstudio"
"${CMAKE_CURRENT_LIST_DIR}"
)
foreach(_cand IN LISTS _ms_candidates)
if(EXISTS "${_cand}/msot/cmake/module/msopgen.cmake")
set(_ms_root "${_cand}")
break()
endif()
endforeach()
if(_ms_root)
message(STATUS "Reusing existing msot at: ${_ms_root}")
set(_ms_template_dst "${_ms_root}/msopgen/thirdparty/asc-tools/utils/templates/new_op_project_template")
set(_ms_template_src "${CMAKE_CURRENT_LIST_DIR}/../utils/templates/new_op_project_template")
if(NOT EXISTS "${_ms_template_dst}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_directory ${_ms_template_src} ${_ms_template_dst}
)
endif()
else()
message(STATUS "No reusable msot found, fetching into repo third_party...")
set(_ms_root "${CMAKE_CURRENT_LIST_DIR}")
set(SUB_ZIP_PREFIXES "mskl" "mskpp" "mssanitizer" "msopgen" "msdebug" "msopprof")
set(ZIP_PREFIXES "msot" ${SUB_ZIP_PREFIXES})
set(ALL_ZIP_EXIST TRUE)
foreach(PREFIX ${ZIP_PREFIXES})
set(ZIP_FILE "${CANN_3RD_LIB_PATH}/${PREFIX}-master.zip")
if(NOT EXISTS ${ZIP_FILE})
message(STATUS "${ZIP_FILE} does not exist.")
set(ALL_ZIP_EXIST FALSE)
endif()
endforeach()
if(ALL_ZIP_EXIST)
foreach(PREFIX ${ZIP_PREFIXES})
set(ZIP_FILE "${CANN_3RD_LIB_PATH}/${PREFIX}-master.zip")
execute_process(
COMMAND unzip -q ${ZIP_FILE} -d ${_ms_root}
WORKING_DIRECTORY ${_ms_root}
)
endforeach()
if(EXISTS ${_ms_root}/msot)
file(REMOVE_RECURSE ${_ms_root}/msot)
endif()
execute_process(
COMMAND mv ${_ms_root}/msot-master ${_ms_root}/msot
WORKING_DIRECTORY ${_ms_root}
)
foreach(PREFIX ${SUB_ZIP_PREFIXES})
if(EXISTS ${_ms_root}/msot/${PREFIX})
file(REMOVE_RECURSE ${_ms_root}/msot/${PREFIX})
endif()
execute_process(
COMMAND mv ${_ms_root}/${PREFIX}-master ${_ms_root}/msot/${PREFIX}
WORKING_DIRECTORY ${_ms_root}
)
endforeach()
elseif(NOT EXISTS "${_ms_root}/msot/cmake/module/msopgen.cmake")
include(FetchContent)
FetchContent_Declare(
third_party_msot
GIT_REPOSITORY https://gitcode.com/Ascend/msot.git
GIT_TAG master
GIT_SUBMODULES msopgen
GIT_PROGRESS TRUE
SOURCE_DIR "${_ms_root}/msot"
)
FetchContent_GetProperties(third_party_msot)
if(NOT third_party_msot_POPULATED)
FetchContent_Populate(third_party_msot)
endif()
execute_process(
COMMAND git submodule update --remote msopgen
WORKING_DIRECTORY "${_ms_root}/msot"
)
endif()
endif()
if(EXISTS "${_ms_root}/msopgen" AND NOT EXISTS "${_ms_root}/msot/msopgen")
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory "${_ms_root}/msot"
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${_ms_root}/msopgen"
"${_ms_root}/msot/msopgen"
)
endif()
set(ROOT_DIR "${_ms_root}/msot")
include("${ROOT_DIR}/cmake/module/msopgen.cmake")
set(MSOPGEN_BUILD_DIR "${CMAKE_INSTALL_PREFIX}/msopgen")
install(CODE "
file(GLOB MSOPGEN_WHL \"${MSOPGEN_BUILD_DIR}/mindstudio_opgen-*-py3-none-any.whl\")
file(GLOB MSOPST_WHL \"${MSOPGEN_BUILD_DIR}/mindstudio_opst-*-py3-none-any.whl\")
if(MSOPGEN_WHL)
file(INSTALL \${MSOPGEN_WHL} DESTINATION \"\${CMAKE_INSTALL_PREFIX}/tools/\"
FILE_PERMISSIONS OWNER_READ GROUP_READ)
message(STATUS \"Installed: \${MSOPGEN_WHL}\")
else()
message(WARNING \"msopgen whl not found at ${MSOPGEN_BUILD_DIR}\")
endif()
if(MSOPST_WHL)
file(INSTALL \${MSOPST_WHL} DESTINATION \"\${CMAKE_INSTALL_PREFIX}/tools/\"
FILE_PERMISSIONS OWNER_READ GROUP_READ)
message(STATUS \"Installed: \${MSOPST_WHL}\")
else()
message(WARNING \"msopst whl not found at ${MSOPGEN_BUILD_DIR}\")
endif()
" COMPONENT asc-tools)