Merged
refactor: ENABLE_BUILD_DEVICE相关逻辑合并 #2078
refactor: ENABLE_BUILD_DEVICE相关逻辑合并 #2078
Merged
zhengfeitengAdd on May 11
Total: 4 files changed+63-56
@@ -32,6 +32,7 @@ set(ASCENDC_IMPL_DIR ${ASCENDC_DIR}/impl)
32 32 
33if(BUILD_OPEN_PROJECT)33if(BUILD_OPEN_PROJECT)
34 include(cmake/config.cmake)34 include(cmake/config.cmake)
35+ include(cmake/func.cmake)
35 set(INSTALL_LIBRARY_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux)36 set(INSTALL_LIBRARY_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux)
36endif()37endif()
37 38 
@@ -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()
@@ -82,62 +82,6 @@ install(FILES ${CMAKE_BINARY_DIR}/version.asc-devkit.info
82 COMPONENT asc-devkit82 COMPONENT asc-devkit
83)83)
84 84 
85-if(ENABLE_BUILD_DEVICE)
86- set(HCCL_CC_BUILD_DIR ${CMAKE_BINARY_DIR}/impl/adv_api/detail/hccl/cc)
87- install(FILES "${HCCL_CC_BUILD_DIR}/src/libmc2_client.so" "${HCCL_CC_BUILD_DIR}/src/common/hcomm_dlsym/libmc2_compat.so"
88- DESTINATION "hccl/lib64" COMPONENT asc-devkit OPTIONAL)
89- install(FILES "${HCCL_CC_BUILD_DIR}/src/libmc2_server.json"
90- DESTINATION "hccl/built-in/data/op/aicpu" COMPONENT asc-devkit OPTIONAL)
91-endif()
92- 
93-function(install_mc2_runtime_staging_link src_rel_path dst_rel_path required)
94- install(CODE "
95-set(_src_rel_path \"${src_rel_path}\")
96-set(_dst_rel_path \"${dst_rel_path}\")
97-set(_required \"${required}\")
98-set(_install_prefix \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}\")
99-file(TO_CMAKE_PATH \"\${_install_prefix}\" _install_prefix)
100-set(_src_path \"\${_install_prefix}/\${_src_rel_path}\")
101-set(_dst_path \"\${_install_prefix}/\${_dst_rel_path}\")
102-if(EXISTS \"\${_dst_path}\" AND IS_DIRECTORY \"\${_dst_path}\" AND NOT IS_SYMLINK \"\${_dst_path}\")
103- message(FATAL_ERROR \"MC2 runtime staging path \${_dst_rel_path} is a directory, cannot create file softlink.\")
104-elseif(EXISTS \"\${_dst_path}\")
105- message(STATUS \"MC2 runtime staging path \${_dst_rel_path} already exists, skip.\")
106-else()
107- if(IS_SYMLINK \"\${_dst_path}\")
108- file(REMOVE \"\${_dst_path}\")
109- endif()
110- if(NOT EXISTS \"\${_src_path}\")
111- if(_required)
112- message(FATAL_ERROR \"MC2 runtime staging source \${_src_rel_path} does not exist.\")
113- else()
114- message(WARNING \"MC2 runtime staging source \${_src_rel_path} does not exist, skip creating \${_dst_rel_path}.\")
115- endif()
116- else()
117- get_filename_component(_dst_dir \"\${_dst_path}\" DIRECTORY)
118- file(MAKE_DIRECTORY \"\${_dst_dir}\")
119- file(RELATIVE_PATH _link_target \"\${_dst_dir}\" \"\${_src_path}\")
120- execute_process(
121- COMMAND \"${CMAKE_COMMAND}\" -E create_symlink \"\${_link_target}\" \"\${_dst_path}\"
122- RESULT_VARIABLE _link_ret
123- )
124- if(NOT _link_ret EQUAL 0)
125- message(FATAL_ERROR \"failed to create MC2 runtime staging link \${_dst_rel_path} -> \${_src_rel_path}.\")
126- endif()
127- message(STATUS \"Created MC2 runtime staging link \${_dst_rel_path} -> \${_src_rel_path}.\")
128- endif()
129-endif()
130-" COMPONENT asc-devkit)
131-endfunction()
132- 
133-if(ENABLE_BUILD_DEVICE)
134- install_mc2_runtime_staging_link("hccl/include/hccl/hccl.h" "${CMAKE_SYSTEM_PROCESSOR}-linux/include/hccl/hccl.h" TRUE)
135- install_mc2_runtime_staging_link("hccl/include/hccl/hccl_mc2.h" "${CMAKE_SYSTEM_PROCESSOR}-linux/include/hccl/hccl_mc2.h" TRUE)
136- install_mc2_runtime_staging_link("hccl/lib64/libmc2_client.so" "${CMAKE_SYSTEM_PROCESSOR}-linux/lib64/libmc2_client.so" TRUE)
137- install_mc2_runtime_staging_link("hccl/lib64/libmc2_compat.so" "${CMAKE_SYSTEM_PROCESSOR}-linux/lib64/libmc2_compat.so" TRUE)
138- install_mc2_runtime_staging_link("hccl/built-in/data/op/aicpu/libmc2_server.json" "opp/built-in/op_impl/aicpu/config/libmc2_server.json" TRUE)
139- install_mc2_runtime_staging_link("hccl/Ascend/aicpu/mc2_server.tar.gz" "opp/built-in/op_impl/aicpu/kernel/mc2_server.tar.gz" FALSE)
140-endif()
141# ============= CPack =============85# ============= CPack =============
142set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")86set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
143set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")87set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
@@ -149,6 +149,19 @@ endif()
149 149 
150if (ENABLE_BUILD_DEVICE)150if (ENABLE_BUILD_DEVICE)
151 add_subdirectory(detail/hccl/cc)151 add_subdirectory(detail/hccl/cc)
152+ 
153+ set(HCCL_CC_BUILD_DIR ${CMAKE_BINARY_DIR}/impl/adv_api/detail/hccl/cc)
154+ install(FILES "${HCCL_CC_BUILD_DIR}/src/libmc2_client.so" "${HCCL_CC_BUILD_DIR}/src/common/hcomm_dlsym/libmc2_compat.so"
155+ DESTINATION "hccl/lib64" COMPONENT asc-devkit OPTIONAL)
156+ install(FILES "${HCCL_CC_BUILD_DIR}/src/libmc2_server.json"
157+ DESTINATION "hccl/built-in/data/op/aicpu" COMPONENT asc-devkit OPTIONAL)
158+ 
159+ install_mc2_runtime_staging_link("hccl/include/hccl/hccl.h" "${CMAKE_SYSTEM_PROCESSOR}-linux/include/hccl/hccl.h" TRUE)
160+ install_mc2_runtime_staging_link("hccl/include/hccl/hccl_mc2.h" "${CMAKE_SYSTEM_PROCESSOR}-linux/include/hccl/hccl_mc2.h" TRUE)
161+ install_mc2_runtime_staging_link("hccl/lib64/libmc2_client.so" "${CMAKE_SYSTEM_PROCESSOR}-linux/lib64/libmc2_client.so" TRUE)
162+ install_mc2_runtime_staging_link("hccl/lib64/libmc2_compat.so" "${CMAKE_SYSTEM_PROCESSOR}-linux/lib64/libmc2_compat.so" TRUE)
163+ install_mc2_runtime_staging_link("hccl/built-in/data/op/aicpu/libmc2_server.json" "opp/built-in/op_impl/aicpu/config/libmc2_server.json" TRUE)
164+ install_mc2_runtime_staging_link("hccl/Ascend/aicpu/mc2_server.tar.gz" "opp/built-in/op_impl/aicpu/kernel/mc2_server.tar.gz" FALSE)
152endif()165endif()
153 166 
154if(NOT BUILD_OPEN_PROJECT)167if(NOT BUILD_OPEN_PROJECT)