Merged
refactor: ENABLE_BUILD_DEVICE相关逻辑合并 #2078
zhengfeitengAdd on May 11
refactor: ENABLE_BUILD_DEVICE相关逻辑合并 #2078
Merged
Total: 4 files changed+63-56
| @@ -0,0 +1,49 @@ | |||
| 1 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +function(install_mc2_runtime_staging_link src_rel_path dst_rel_path required) | ||
| 12 | + install(CODE " | ||
| 13 | +set(_src_rel_path \"${src_rel_path}\") | ||
| 14 | +set(_dst_rel_path \"${dst_rel_path}\") | ||
| 15 | +set(_required \"${required}\") | ||
| 16 | +set(_install_prefix \"\${CMAKE_INSTALL_PREFIX}\") | ||
| 17 | +file(TO_CMAKE_PATH \"\${_install_prefix}\" _install_prefix) | ||
| 18 | +set(_src_path \"\${_install_prefix}/\${_src_rel_path}\") | ||
| 19 | +set(_dst_path \"\${_install_prefix}/\${_dst_rel_path}\") | ||
| 20 | +if(EXISTS \"\${_dst_path}\" AND IS_DIRECTORY \"\${_dst_path}\" AND NOT IS_SYMLINK \"\${_dst_path}\") | ||
| 21 | + message(FATAL_ERROR \"MC2 runtime staging path \${_dst_rel_path} is a directory, cannot create file softlink.\") | ||
| 22 | +elseif(EXISTS \"\${_dst_path}\") | ||
| 23 | + message(STATUS \"MC2 runtime staging path \${_dst_rel_path} already exists, skip.\") | ||
| 24 | +else() | ||
| 25 | + if(IS_SYMLINK \"\${_dst_path}\") | ||
| 26 | + file(REMOVE \"\${_dst_path}\") | ||
| 27 | + endif() | ||
| 28 | + if(NOT EXISTS \"\${_src_path}\") | ||
| 29 | + if(_required) | ||
| 30 | + message(FATAL_ERROR \"MC2 runtime staging source \${_src_rel_path} does not exist.\") | ||
| 31 | + else() | ||
| 32 | + message(WARNING \"MC2 runtime staging source \${_src_rel_path} does not exist, skip creating \${_dst_rel_path}.\") | ||
| 33 | + endif() | ||
| 34 | + else() | ||
| 35 | + get_filename_component(_dst_dir \"\${_dst_path}\" DIRECTORY) | ||
| 36 | + file(MAKE_DIRECTORY \"\${_dst_dir}\") | ||
| 37 | + file(RELATIVE_PATH _link_target \"\${_dst_dir}\" \"\${_src_path}\") | ||
| 38 | + execute_process( | ||
| 39 | + COMMAND \"${CMAKE_COMMAND}\" -E create_symlink \"\${_link_target}\" \"\${_dst_path}\" | ||
| 40 | + RESULT_VARIABLE _link_ret | ||
| 41 | + ) | ||
| 42 | + if(NOT _link_ret EQUAL 0) | ||
| 43 | + message(FATAL_ERROR \"failed to create MC2 runtime staging link \${_dst_rel_path} -> \${_src_rel_path}.\") | ||
| 44 | + endif() | ||
| 45 | + message(STATUS \"Created MC2 runtime staging link \${_dst_rel_path} -> \${_src_rel_path}.\") | ||
| 46 | + endif() | ||
| 47 | +endif() | ||
| 48 | +" COMPONENT asc-devkit) | ||
| 49 | +endfunction() | ||