Merged
protobuf生成切换工程函数。 #781
protobuf生成切换工程函数。 #781
Merged
zhengfeitengAdd on Aug 25
Total: 12 files changed+12-73
@@ -61,7 +61,6 @@ if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)
61 add_cann_third_party(protobuf)61 add_cann_third_party(protobuf)
62 add_cann_third_party(eigen)62 add_cann_third_party(eigen)
63 add_cann_third_party(json)63 add_cann_third_party(json)
64- include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/func.cmake)
65 64 
66 include(version.cmake)65 include(version.cmake)
67 set(ASCEND_INSTALL_PATH "${ASCEND_HOME_PATH}")66 set(ASCEND_INSTALL_PATH "${ASCEND_HOME_PATH}")
@@ -1,7 +1,7 @@
1cmake_minimum_required(VERSION 3.14.1)1cmake_minimum_required(VERSION 3.14.1)
2project(cpu_kernels_context_device)2project(cpu_kernels_context_device)
3 3 
4-protobuf_generate(aicpu_proto_device PROTO_SRCS PROTO_HDRS ${proto_src_files} TARGET)4+generate_cann_protobuf(aicpu_proto_device PROTO_SRCS PROTO_HDRS ${proto_src_files} TARGET)
5set(aicpu_proto_include "${CMAKE_BINARY_DIR}/proto/aicpu_proto_device")5set(aicpu_proto_include "${CMAKE_BINARY_DIR}/proto/aicpu_proto_device")
6 6 
7add_library(aicpu_context STATIC7add_library(aicpu_context STATIC
@@ -1,7 +1,7 @@
1cmake_minimum_required(VERSION 3.14.1)1cmake_minimum_required(VERSION 3.14.1)
2project(cpu_kernels_context_host)2project(cpu_kernels_context_host)
3 3 
4-protobuf_generate(aicpu_proto_host PROTO_SRCS PROTO_HDRS ${proto_src_files} TARGET)4+generate_cann_protobuf(aicpu_proto_host PROTO_SRCS PROTO_HDRS ${proto_src_files} TARGET)
5set(aicpu_proto_include "${CMAKE_BINARY_DIR}/proto/aicpu_proto_host")5set(aicpu_proto_include "${CMAKE_BINARY_DIR}/proto/aicpu_proto_host")
6 6 
7add_library(aicpu_context_host STATIC7add_library(aicpu_context_host STATIC
@@ -17,7 +17,6 @@ add_cann_target_options()
17get_filename_component(OPS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE)17get_filename_component(OPS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE)
18 18 
19include(${OPS_BASE_DIR}/cmake/config.cmake)19include(${OPS_BASE_DIR}/cmake/config.cmake)
20-include(${OPS_BASE_DIR}/cmake/func.cmake)
21 20 
22add_cann_third_party(protobuf)21add_cann_third_party(protobuf)
23add_cann_third_party(eigen)22add_cann_third_party(eigen)
@@ -14,11 +14,12 @@ if(NOT PROJECT_SOURCE_DIR)
14 else()14 else()
15 include(FetchContent)15 include(FetchContent)
16 16 
17- set(CANN_CMAKE_TAG "master-049")17+ set(CANN_CMAKE_TAG "master-053")
18 if(CANN_3RD_LIB_PATH AND EXISTS "${CANN_3RD_LIB_PATH}/cmake-${CANN_CMAKE_TAG}.tar.gz")18 if(CANN_3RD_LIB_PATH AND EXISTS "${CANN_3RD_LIB_PATH}/cmake-${CANN_CMAKE_TAG}.tar.gz")
19 FetchContent_Declare(19 FetchContent_Declare(
20 cann-cmake20 cann-cmake
21 URL "${CANN_3RD_LIB_PATH}/cmake-${CANN_CMAKE_TAG}.tar.gz"21 URL "${CANN_3RD_LIB_PATH}/cmake-${CANN_CMAKE_TAG}.tar.gz"
22+ URL_HASH SHA256=5ca4948c257f2ba8530d6f506e1fed3bb8d24a3ab347fb226599d37e51edc429
22 )23 )
23 else()24 else()
24 FetchContent_Declare(25 FetchContent_Declare(
@@ -1,59 +0,0 @@
1-function(protobuf_generate comp c_var h_var)
2- if(NOT ARGN)
3- message(SEND_ERROR "Error: protobuf_generate() called without any proto files")
4- return()
5- endif()
6- set(${c_var})
7- set(${h_var})
8- set(_add_target FALSE)
9- 
10- set(extra_option "")
11- foreach(arg ${ARGN})
12- if ("${arg}" MATCHES "--proto_path")
13- set(extra_option ${arg})
14- endif()
15- endforeach()
16- 
17- foreach(file ${ARGN})
18- if("${file}" STREQUAL "TARGET")
19- set(_add_target TRUE)
20- continue()
21- endif()
22- 
23- if ("${file}" MATCHES "--proto_path")
24- continue()
25- endif()
26- 
27- get_filename_component(abs_file ${file} ABSOLUTE)
28- get_filename_component(file_name ${file} NAME_WE)
29- get_filename_component(file_dir ${abs_file} PATH)
30- get_filename_component(parent_subdir ${file_dir} NAME)
31- 
32- if("${parent_subdir}" STREQUAL "proto")
33- set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto)
34- else()
35- set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto/${parent_subdir})
36- endif()
37- list(APPEND ${c_var} "${proto_output_path}/${file_name}.pb.cc")
38- list(APPEND ${h_var} "${proto_output_path}/${file_name}.pb.h")
39- 
40- add_custom_command(
41- OUTPUT "${proto_output_path}/${file_name}.pb.cc" "${proto_output_path}/${file_name}.pb.h"
42- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
43- COMMAND ${CMAKE_COMMAND} -E make_directory "${proto_output_path}"
44- COMMAND ${CMAKE_COMMAND} -E echo "generate proto cpp_out ${comp} by ${abs_file}"
45- COMMAND host_protoc -I${file_dir} ${extra_option} --cpp_out=${proto_output_path} ${abs_file}
46- DEPENDS ${abs_file} host_protoc
47- COMMENT "Running C++ protocol buffer compiler on ${file}" VERBATIM )
48- endforeach()
49- 
50- if(_add_target)
51- add_custom_target(
52- ${comp} DEPENDS ${${c_var}} ${${h_var}}
53- )
54- endif()
55- 
56- set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)
57- set(${c_var} ${${c_var}} PARENT_SCOPE)
58- set(${h_var} ${${h_var}} PARENT_SCOPE)
59-endfunction()
@@ -40,7 +40,7 @@ bash install_deps.sh
40| eigen | 5.0.0 | [eigen-5.0.0.tar.gz](https://gitcode.com/cann-src-third-party/eigen/releases/download/5.0.0-h0.trunk/eigen-5.0.0.tar.gz) |40| eigen | 5.0.0 | [eigen-5.0.0.tar.gz](https://gitcode.com/cann-src-third-party/eigen/releases/download/5.0.0-h0.trunk/eigen-5.0.0.tar.gz) |
41| protobuf | 25.1 | [protobuf-25.1.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/protobuf/protobuf-25.1.tar.gz) |41| protobuf | 25.1 | [protobuf-25.1.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/protobuf/protobuf-25.1.tar.gz) |
42| abseil-cpp | 20230802.1 | [abseil-cpp-20230802.1.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/abseil-cpp/abseil-cpp-20230802.1.tar.gz) |42| abseil-cpp | 20230802.1 | [abseil-cpp-20230802.1.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/abseil-cpp/abseil-cpp-20230802.1.tar.gz) |
43-| cann-cmake | master-049 | [cmake-master-049.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/cmake/cmake-master-049.tar.gz) |43+| cann-cmake | master-053 | [cmake-master-053.tar.gz](https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/cmake/cmake-master-053.tar.gz) |
44 44 
45若您的编译环境可以访问网络,请参考[联网编译](#联网编译),编译脚本会自动联网下载第三方软件。否则,请参考[未联网编译](#未联网编译)手动下载第三方软件。45若您的编译环境可以访问网络,请参考[联网编译](#联网编译),编译脚本会自动联网下载第三方软件。否则,请参考[未联网编译](#未联网编译)手动下载第三方软件。
46 46 
@@ -8,7 +8,6 @@
8│ ├── third_party # 项目依赖的第三方相关编译配置目录8│ ├── third_party # 项目依赖的第三方相关编译配置目录
9│ ├── aarch64-hcc-toolchain.cmake # 项目工程编译工具链配置文件9│ ├── aarch64-hcc-toolchain.cmake # 项目工程编译工具链配置文件
10│ ├── config.cmake # 项目工程编译选项配置文件 10│ ├── config.cmake # 项目工程编译选项配置文件
11-│ ├── func.cmake # 项目工程编译protobuf文件
12│ ├── makeself.cmake # 项目工程自定义makeself打包文件11│ ├── makeself.cmake # 项目工程自定义makeself打包文件
13│ ├── package.cmake # 项目工程编译打包安装相关配置文件12│ ├── package.cmake # 项目工程编译打包安装相关配置文件
14│ ├── Third_Party_Open_Source_Software_List.yaml # 项目依赖的第三方软件库清单13│ ├── Third_Party_Open_Source_Software_List.yaml # 项目依赖的第三方软件库清单
@@ -53,7 +53,7 @@ if __name__ == "__main__":
53 "https://gitcode.com/cann-src-third-party/protobuf/releases/download/v25.1/protobuf-25.1.tar.gz",53 "https://gitcode.com/cann-src-third-party/protobuf/releases/download/v25.1/protobuf-25.1.tar.gz",
54 ("https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/abseil-cpp/"54 ("https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/abseil-cpp/"
55 "abseil-cpp-20230802.1.tar.gz"),55 "abseil-cpp-20230802.1.tar.gz"),
56- "https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/cmake/cmake-master-049.tar.gz"56+ "https://cann-3rd.obs.cn-north-4.myhuaweicloud.com/cmake/cmake-master-053.tar.gz"
57 ]57 ]
58 58 
59 failed_downloads = down_files_native(my_urls)59 failed_downloads = down_files_native(my_urls)
@@ -105,9 +105,9 @@ add_subdirectory(individual_op)
105# generate protobuff files105# generate protobuff files
106set(AICPU_PATH ${NNOPBASE_PATH}/aicpu)106set(AICPU_PATH ${NNOPBASE_PATH}/aicpu)
107file(GLOB utils_proto_src_files ${AICPU_PATH}/proto/*.proto)107file(GLOB utils_proto_src_files ${AICPU_PATH}/proto/*.proto)
108-protobuf_generate(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})108+generate_cann_protobuf(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})
109file(GLOB cpu_proto_src_files ${AICPU_PATH}/cpu_proto/*.proto)109file(GLOB cpu_proto_src_files ${AICPU_PATH}/cpu_proto/*.proto)
110-protobuf_generate(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})110+generate_cann_protobuf(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})
111# aicpu111# aicpu
112add_subdirectory(aicpu)112add_subdirectory(aicpu)
113 113 
@@ -41,9 +41,9 @@ message(STATUS "OPS_BASE_PATH: ${OPS_BASE_PATH}")
41 41 
42# generate protobuff files42# generate protobuff files
43file(GLOB utils_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/proto/*.proto)43file(GLOB utils_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/proto/*.proto)
44-protobuf_generate(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})44+generate_cann_protobuf(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})
45file(GLOB cpu_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/cpu_proto/*.proto)45file(GLOB cpu_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/cpu_proto/*.proto)
46-protobuf_generate(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})46+generate_cann_protobuf(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})
47message(STATUS "generate aicpu successfully")47message(STATUS "generate aicpu successfully")
48 48 
49set(NNOPBASE_STEST_HEADERS49set(NNOPBASE_STEST_HEADERS
@@ -40,9 +40,9 @@ message(STATUS "OPS_BASE_PATH: ${OPS_BASE_PATH}")
40 40 
41# generate protobuff files41# generate protobuff files
42file(GLOB utils_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/proto/*.proto)42file(GLOB utils_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/proto/*.proto)
43-protobuf_generate(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})43+generate_cann_protobuf(aicpu PROTO_SRCS PROTO_HDRS ${utils_proto_src_files})
44file(GLOB cpu_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/cpu_proto/*.proto)44file(GLOB cpu_proto_src_files ${OPS_BASE_PATH}/src/nnopbase/aicpu/cpu_proto/*.proto)
45-protobuf_generate(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})45+generate_cann_protobuf(aicpu_proto CPU_PROTO_SRCS CPU_PROTO_HDRS ${cpu_proto_src_files})
46message(STATUS "generate aicpu successfully")46message(STATUS "generate aicpu successfully")
47 47 
48# op_proto ut48# op_proto ut