1 Star 0 Fork 137

张先生01/parser

forked from Ascend/parser 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CMakeLists.txt 14.60 KB
一键复制 编辑 原始数据 按行查看 历史
# Copyright (c) 2024 Huawei Technologies Co., Ltd
# [graph-engine] is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# ============================================================================
cmake_minimum_required(VERSION 3.14)
project (Parser[CXX])
if (NOT DEFINED ASCEND_OPENSDK_DIR)
set(ASCEND_OPENSDK_DIR ${ASCEND_CUSTOM_PATH}/opensdk/opensdk)
endif()
if (NOT DEFINED CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH ${ASCEND_OPENSDK_DIR}/cmake/modules)
endif()
if (NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${ASCEND_OPENSDK_DIR}/cmake
${ASCEND_OPENSDK_DIR}/c_sec
${ASCEND_OPENSDK_DIR}/json
${ASCEND_OPENSDK_DIR}/openssl
${ASCEND_OPENSDK_DIR}/zlib
${ASCEND_OPENSDK_DIR}/protoc
${ASCEND_OPENSDK_DIR}/protoc_grpc
${ASCEND_OPENSDK_DIR}/grpc
${ASCEND_OPENSDK_DIR}/protobuf_static
${ASCEND_OPENSDK_DIR}/ascend_protobuf
${ASCEND_OPENSDK_DIR}/ascend_protobuf_static
${ASCEND_OPENSDK_DIR}/gtest_shared/lib/cmake/GTest
${ASCEND_OPENSDK_DIR}/gtest_shared/lib64/cmake/GTest
)
endif()
include(CMakePrintHelpers)
message(STATUS "Variables in parser project :")
cmake_print_variables(ASCEND_CUSTOM_PATH)
cmake_print_variables(ASCEND_OPENSDK_DIR)
cmake_print_variables(CMAKE_BUILD_TYPE)
cmake_print_variables(CMAKE_INSTALL_PREFIX)
cmake_print_variables(CMAKE_PREFIX_PATH)
cmake_print_variables(CMAKE_MODULE_PATH)
cmake_print_variables(CMAKE_SYSTEM_PROCESSOR)
cmake_print_variables(protoc_ROOT)
cmake_print_variables(protobuf_grpc_ROOT)
cmake_print_variables(protobuf_static_ROOT)
cmake_print_variables(ascend_protobuf_shared_ROOT)
cmake_print_variables(ascend_protobuf_static_ROOT)
cmake_print_variables(ENABLE_OPEN_SRC ENABLE_GITEE ENABLE_PARSER_UT ENABLE_PARSER_ST ENABLE_PARSER_COV)
cmake_print_variables(BUILD_WITHOUT_AIR BUILD_METADEF METADEF_DIR)
set(INSTALL_BASE_DIR "")
set(INSTALL_LIBRARY_DIR lib)
set(INSTALL_RUNTIME_DIR bin)
set(INSTALL_INCLUDE_DIR include)
set(INSTALL_CONFIG_DIR cmake)
include(CMakePackageConfigHelpers)
set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR})
option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE)
if (ENABLE_OPEN_SRC)
set(HI_PYTHON python3)
# 开源软件包
find_package(json MODULE)
find_package(protoc MODULE)
find_package(ascend_protobuf_shared MODULE)
find_package(ascend_protobuf_static MODULE)
find_package(GTest CONFIG REQUIRED)
# 自研软件包
find_package(securec MODULE REQUIRED)
find_package(slog CONFIG REQUIRED)
find_package(mmpa CONFIG REQUIRED)
find_package(runtime CONFIG REQUIRED)
find_package(msprof CONFIG REQUIRED)
find_package(cce CONFIG REQUIRED)
if (BUILD_WITHOUT_AIR)
find_package(air CONFIG REQUIRED)
endif()
if (NOT BUILD_METADEF)
find_package(metadef CONFIG REQUIRED)
endif()
if (BUILD_METADEF)
# 使用medadef源码编译
if (BUILD_WITHOUT_AIR)
# parser集成metadef源码
set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef)
else ()
# air已经集成metadef源码,parser直接使用
message(STATUS "METADEF_DIR = ${METADEF_DIR}")
endif()
else ()
# 使用medadef发布包编译
set(METADEF_DIR ${ASCEND_OPENSDK_DIR})
endif()
include(cmake/intf_pub_linux.cmake)
include(cmake/function.cmake)
else()
# 使用全量源码构建框架集成的metadef源码
set(METADEF_DIR ${TOP_DIR}/metadef)
endif()
set(PARSER_PROTO_LIST
"${METADEF_DIR}/proto/onnx/ge_onnx.proto"
"${METADEF_DIR}/proto/om.proto"
"${METADEF_DIR}/proto/caffe/caffe.proto"
"${METADEF_DIR}/proto/tensorflow/graph_library.proto"
"${METADEF_DIR}/proto/tensorflow/graph.proto"
"${METADEF_DIR}/proto/tensorflow/node_def.proto"
"${METADEF_DIR}/proto/tensorflow/function.proto"
"${METADEF_DIR}/proto/tensorflow/versions.proto"
"${METADEF_DIR}/proto/tensorflow/attr_value.proto"
"${METADEF_DIR}/proto/tensorflow/op_def.proto"
"${METADEF_DIR}/proto/tensorflow/tensor.proto"
"${METADEF_DIR}/proto/tensorflow/tensor_shape.proto"
"${METADEF_DIR}/proto/tensorflow/types.proto"
"${METADEF_DIR}/proto/tensorflow/resource_handle.proto"
)
protobuf_generate(parser_protos PARSER_PROTO_SRCS PARSER_PROTO_HDRS ${PARSER_PROTO_LIST} TARGET)
add_library(parser_headers INTERFACE)
target_include_directories(parser_headers INTERFACE
$<BUILD_INTERFACE:${PARSER_DIR}/inc>
$<BUILD_INTERFACE:${PARSER_DIR}/inc/external>
$<BUILD_INTERFACE:${PARSER_DIR}/inc/external/parser>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/parser>
$<INSTALL_INTERFACE:include/parser/external>
$<INSTALL_INTERFACE:include/parser/external/parser>
)
set(PARSER_GRAPH_LIBRARY_PROTO_SRC
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph_library.pb.cc"
)
set(PARSER_TENSORFLOW_PROTO_SRCS
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/node_def.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/function.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/versions.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/attr_value.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/op_def.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor_shape.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/types.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/resource_handle.pb.cc"
)
set(PARSER_ONNX_PROTO_SRCS
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/onnx/ge_onnx.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/om.pb.cc"
)
set(PARSER_CAFFE_PROTO_SRC
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/caffe/caffe.pb.cc"
)
add_library(parser_graph_library_proto_obj OBJECT ${PARSER_GRAPH_LIBRARY_PROTO_SRC})
add_dependencies(parser_graph_library_proto_obj parser_protos)
target_compile_definitions(parser_graph_library_proto_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_graph_library_proto_obj PRIVATE ascend_protobuf intf_pub)
target_compile_options(parser_graph_library_proto_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_tensorflow_protos_obj OBJECT ${PARSER_TENSORFLOW_PROTO_SRCS})
add_dependencies(parser_tensorflow_protos_obj parser_protos)
target_compile_definitions(parser_tensorflow_protos_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_tensorflow_protos_obj PRIVATE ascend_protobuf intf_pub)
target_compile_options(parser_tensorflow_protos_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_onnx_protos_obj OBJECT ${PARSER_ONNX_PROTO_SRCS})
add_dependencies(parser_onnx_protos_obj parser_protos)
target_compile_definitions(parser_onnx_protos_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_onnx_protos_obj PRIVATE ascend_protobuf intf_pub)
target_compile_options(parser_onnx_protos_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_caffe_proto_obj OBJECT ${PARSER_CAFFE_PROTO_SRC})
add_dependencies(parser_caffe_proto_obj parser_protos)
target_compile_definitions(parser_caffe_proto_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_caffe_proto_obj PRIVATE ascend_protobuf intf_pub)
target_compile_options(parser_caffe_proto_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
############ lib_caffe_parser.so ############
add_library(_caffe_parser SHARED
$<TARGET_OBJECTS:parser_caffe_proto_obj>
)
target_compile_definitions(_caffe_parser PRIVATE
google=ascend_private
)
target_include_directories(_caffe_parser PRIVATE
${CMAKE_CURRENT_LIST_DIR}
)
target_link_options(_caffe_parser PRIVATE
-Wl,-Bsymbolic
)
target_link_libraries(_caffe_parser
PRIVATE
intf_pub
-Wl,--no-as-needed
ascend_protobuf
-Wl,--as-needed
PUBLIC
parser_headers
)
add_subdirectory(parser)
add_subdirectory(parser/common)
add_subdirectory(parser/func_to_graph)
add_subdirectory(parser/onnx)
if (BUILD_METADEF AND BUILD_WITHOUT_AIR)
add_subdirectory(metadef)
endif()
if(ENABLE_PARSER_UT OR ENABLE_PARSER_COV OR ENABLE_PARSER_ST)
add_subdirectory(tests)
endif()
install(TARGETS _caffe_parser parser_common fmk_onnx_parser fmk_parser parser_headers
EXPORT parser-targets
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} OPTIONAL COMPONENT opensdk
ARCHIVE DESTINATION ${INSTALL_LIBRARY_DIR} OPTIONAL COMPONENT opensdk
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} OPTIONAL COMPONENT opensdk
)
install(FILES ${PARSER_DIR}/inc/external/parser/onnx_parser.h
${PARSER_DIR}/inc/external/parser/caffe_parser.h
${PARSER_DIR}/inc/external/parser/tensorflow_parser.h
DESTINATION ${INSTALL_INCLUDE_DIR}/parser/external/parser COMPONENT opensdk EXCLUDE_FROM_ALL
)
# 下列头文件发布是非法的,需要在后续整改中删掉
# --------------------start------------------------
install(FILES ${PARSER_DIR}/parser/common/pre_checker.h
DESTINATION ${INSTALL_INCLUDE_DIR}/parser/parser/common COMPONENT opensdk EXCLUDE_FROM_ALL
)
install(FILES ${PARSER_DIR}/parser/common/convert/pb2json.h
DESTINATION ${INSTALL_INCLUDE_DIR}/parser/parser/common/convert COMPONENT opensdk EXCLUDE_FROM_ALL
)
# ---------------------end-------------------------
if (PACKAGE STREQUAL "opensdk")
install(EXPORT parser-targets DESTINATION ${INSTALL_CONFIG_DIR}
FILE parser-targets.cmake COMPONENT opensdk EXCLUDE_FROM_ALL
)
set(PKG_NAME parser)
configure_package_config_file(${TOP_DIR}/cmake/config/pkg_config_template.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/parser-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
PATH_VARS INSTALL_BASE_DIR INSTALL_INCLUDE_DIR INSTALL_LIBRARY_DIR INSTALL_RUNTIME_DIR INSTALL_CONFIG_DIR
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
)
unset(PKG_NAME)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/parser-config.cmake
DESTINATION ${INSTALL_CONFIG_DIR} COMPONENT opensdk EXCLUDE_FROM_ALL
)
endif()
install(TARGETS _caffe_parser
error_manager
fmk_onnx_parser
fmk_parser
graph
parser_common
register
LIBRARY DESTINATION compiler/lib64 OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
ARCHIVE DESTINATION compiler/lib64 OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
RUNTIME DESTINATION compiler/bin OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
)
set(install_script_dir ${CMAKE_CURRENT_BINARY_DIR}/install_scripts/)
add_custom_target(generate_install_script_parser ALL
COMMAND rm -rf ${install_script_dir}
COMMAND cp -rf ${ASCEND_CUSTOM_PATH}/toolkit/tools/ascend_project/open_install_scripts ${install_script_dir}
COMMAND chmod -R u+w ${install_script_dir}
COMMAND echo "base_package=compiler" > ${install_script_dir}/version.info
COMMAND echo "backup_dir=parser" >> ${install_script_dir}/version.info
)
install(DIRECTORY ${install_script_dir}
DESTINATION .
FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_READ
COMPONENT . EXCLUDE_FROM_ALL
)
add_custom_target(install_parser
COMMAND ${CMAKE_PROGRAM} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/package -DCOMPONENT=. -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
COMMAND ${CMAKE_PROGRAM} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/package -DCOMPONENT=packages -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
)
add_dependencies(install_parser generate_install_script_parser)
set(CPACK_COMPONENTS_ALL ".;packages")
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(CPACK_PACKAGE_DESCRIPTION "CPack parser project")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CPack parser project")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/package)
set(CPACK_PACKAGE_FILE_NAME "CANN-parser-linux.${CMAKE_SYSTEM_PROCESSOR}.run")
set(CPACK_GENERATOR External)
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
set(CPACK_EXTERNAL_ENABLE_STAGING TRUE)
set(CPACK_EXTERNAL_PACKAGE_SCRIPT ${ASCEND_CUSTOM_PATH}/toolkit/tools/ascend_project/cmake/makeself.cmake)
set(CPACK_EXTERNAL_BUILT_PACKAGES ${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/Linux/External/${CPACK_PACKAGE_FILE_NAME}/${CPACK_PACKAGE_FILE_NAME})
include(CPack)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mr_zhang_01/parser.git
git@gitee.com:mr_zhang_01/parser.git
mr_zhang_01
parser
parser
master

搜索帮助