加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CMakeLists.txt 9.50 KB
一键复制 编辑 原始数据 按行查看 历史
詹隽 提交于 2024-04-08 12:57 . !4904 编译脚本归一
cmake_minimum_required(VERSION 3.14)
project (MetaDef[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()
if (NOT DEFINED protoc_ROOT)
set(protoc_ROOT ${ASCEND_OPENSDK_DIR}/protoc)
endif()
if (NOT DEFINED protobuf_grpc_ROOT)
set(protobuf_grpc_ROOT ${ASCEND_OPENSDK_DIR}/grpc)
endif()
if (NOT DEFINED protobuf_static_ROOT)
set(protobuf_static_ROOT ${ASCEND_OPENSDK_DIR}/protobuf_static)
endif()
if (NOT DEFINED ascend_protobuf_shared_ROOT)
set(ascend_protobuf_shared_ROOT ${ASCEND_OPENSDK_DIR}/ascend_protobuf)
endif()
if (NOT DEFINED ascend_protobuf_static_ROOT)
set(ascend_protobuf_static_ROOT ${ASCEND_OPENSDK_DIR}/ascend_protobuf_static)
endif()
include(CMakePrintHelpers)
message(STATUS "Variables in metadef 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_METADEF_UT ENABLE_METADEF_ST ENABLE_METADEF_COV ENABLE_BENCHMARK GE_ONLY)
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(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR})
option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE)
if (ENABLE_OPEN_SRC)
set(HI_PYTHON python3)
include(cmake/test_funcs.cmake)
# 开源软件包
find_package(json MODULE)
find_package(protoc MODULE)
find_package(protobuf_static 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)
if (ENABLE_METADEF_UT OR ENABLE_METADEF_ST)
add_library(mmpa_headers INTERFACE)
target_include_directories(mmpa_headers INTERFACE
${ASCEND_OPENSDK_DIR}/include
${ASCEND_OPENSDK_DIR}/include/mmpa
${ASCEND_OPENSDK_DIR}/include/sub_inc
)
else()
find_package(mmpa CONFIG REQUIRED)
endif()
find_package(cce CONFIG REQUIRED)
find_package(msprof CONFIG REQUIRED)
find_package(runtime CONFIG REQUIRED)
find_package(platform CONFIG REQUIRED)
if (BUILD_WITHOUT_AIR)
find_package(air CONFIG REQUIRED)
endif()
include(cmake/intf_pub_linux.cmake)
endif()
include(cmake/common_funcs.cmake)
add_subdirectory(inc)
add_subdirectory(proto)
add_subdirectory(graph)
add_subdirectory(exe_graph)
add_subdirectory(error_manager)
add_subdirectory(register)
if (ENABLE_METADEF_UT OR ENABLE_METADEF_ST OR ENABLE_BENCHMARK)
include(cmake/external_libs/gbenchmark.cmake)
add_subdirectory(tests)
endif()
install(TARGETS exe_graph error_manager graph graph_base flow_graph register rt2_registry_static metadef_headers
EXPORT metadef-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
)
# 下列头文件发布是非法的,需要在后续整改中删掉
# --------------------start------------------------
install(FILES ${METADEF_DIR}/third_party/transformer/inc/axis_util.h
${METADEF_DIR}/third_party/transformer/inc/expand_dimension.h
${METADEF_DIR}/third_party/transformer/inc/transfer_shape_utils.h
${METADEF_DIR}/third_party/transformer/inc/transfer_range_according_to_format.h
${METADEF_DIR}/third_party/transformer/inc/transfer_shape_according_to_format.h
DESTINATION ${INSTALL_INCLUDE_DIR}/metadef/transformer COMPONENT opensdk EXCLUDE_FROM_ALL
)
install(FILES ${METADEF_DIR}/register/op_tiling/op_tiling_constants.h
${METADEF_DIR}/register/op_tiling/op_compile_info_manager.h
${METADEF_DIR}/register/op_tiling/op_tiling_utils.h
DESTINATION ${INSTALL_INCLUDE_DIR}/metadef/register/op_tiling COMPONENT opensdk EXCLUDE_FROM_ALL
)
install(FILES ${METADEF_DIR}/graph/operator_impl.h
${METADEF_DIR}/graph/op_io.h
DESTINATION ${INSTALL_INCLUDE_DIR}/metadef/graph COMPONENT opensdk EXCLUDE_FROM_ALL
)
install(FILES ${METADEF_DIR}/graph/debug/ge_log.h
${METADEF_DIR}/graph/debug/ge_util.h # 被air使用
${METADEF_DIR}/graph/debug/ge_op_types.h # 被parser使用
DESTINATION ${INSTALL_INCLUDE_DIR}/metadef/graph/debug COMPONENT opensdk EXCLUDE_FROM_ALL
)
install(FILES ${METADEF_DIR}/graph/utils/dumper/ge_graph_dumper.h
DESTINATION ${INSTALL_INCLUDE_DIR}/metadef/graph/utils/dumper COMPONENT opensdk EXCLUDE_FROM_ALL
)
# ---------------------end-------------------------
install(DIRECTORY ${METADEF_DIR}/inc/ DESTINATION ${INSTALL_INCLUDE_DIR}/metadef
COMPONENT opensdk EXCLUDE_FROM_ALL FILES_MATCHING PATTERN "*.h"
)
install(DIRECTORY ${METADEF_DIR}/proto/ DESTINATION proto
COMPONENT opensdk EXCLUDE_FROM_ALL FILES_MATCHING PATTERN "*.proto"
)
if (PACKAGE STREQUAL "opensdk")
install(EXPORT metadef-targets DESTINATION ${INSTALL_CONFIG_DIR}
FILE metadef-targets.cmake COMPONENT opensdk EXCLUDE_FROM_ALL
)
set(PKG_NAME metadef)
configure_package_config_file(${TOP_DIR}/cmake/config/pkg_config_template.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/metadef-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}/metadef-config.cmake
DESTINATION ${INSTALL_CONFIG_DIR} COMPONENT opensdk EXCLUDE_FROM_ALL
)
endif()
install(TARGETS error_manager
exe_graph
graph
graph_base
register
rt2_registry_static
LIBRARY DESTINATION runtime/lib64 OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
ARCHIVE DESTINATION runtime/lib64 OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
RUNTIME DESTINATION runtime/bin OPTIONAL COMPONENT packages EXCLUDE_FROM_ALL
)
install(TARGETS error_manager
exe_graph
graph
graph_base
register
rt2_registry_static
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 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=runtime\;compiler" > ${install_script_dir}/version.info
COMMAND echo "backup_dir=metadef" >> ${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_metadef
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_metadef generate_install_script)
set(CPACK_COMPONENTS_ALL ".;packages")
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(CPACK_PACKAGE_DESCRIPTION "CPack metadef project")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CPack metadef project")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/package)
set(CPACK_PACKAGE_FILE_NAME "CANN-metadef-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 助手
尝试更多
代码解读
代码找茬
代码优化