# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# 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 FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
if ((CMAKE_BUILD_TYPE MATCHES GCOV) OR (CMAKE_BUILD_TYPE MATCHES Debug))
set(OPTIMIZE_OPTION "-O0")
else ()
set(OPTIMIZE_OPTION "-O2")
endif ()
include_guard(GLOBAL)
if(TARGET intf_pub AND NOT ENABLE_UNIFIED_BUILD)
message(STATUS "Found intf_pub")
add_library(ge_intf_pub ALIAS intf_pub)
add_library(ge_intf_pub_Os INTERFACE)
target_compile_options(ge_intf_pub_Os INTERFACE
-Os
)
target_link_libraries(ge_intf_pub_Os INTERFACE
$<BUILD_INTERFACE:intf_pub>
)
add_library(ge_intf_pub_cxx14 ALIAS intf_pub_cxx14)
return()
endif()
########## imported intf_pub_base|intf_pub ##########
add_cann_target_options()
########## ge_intf_pub_base ##########
add_library(ge_intf_pub_base INTERFACE)
target_link_libraries(ge_intf_pub_base INTERFACE
$<BUILD_INTERFACE:intf_pub_base>
)
target_compile_options(ge_intf_pub_base INTERFACE
-Werror
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_GREATER_EQUAL:${CMAKE_CXX_COMPILER_VERSION},14.0>>:-Wno-free-nonheap-object>
$<$<CONFIG:Debug>:-g>
$<$<BOOL:${ENABLE_ASAN}>:-Wno-maybe-uninitialized>
$<$<BOOL:${ENABLE_GCOV}>:
-g
-DFUNC_VISIBILITY
-DFMK_SUPPORT_DUMP
-DFWK_SUPPORT_TRAINING_TRACE>
)
target_compile_definitions(ge_intf_pub_base INTERFACE
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},device>,$<BOOL:${MDC_COMPILE_RUNTIME}>>:_GLIBCXX_USE_CXX11_ABI=1>
$<$<AND:$<NOT:$<STREQUAL:${PRODUCT_SIDE},device>>,$<NOT:$<BOOL:${MDC_COMPILE_RUNTIME}>>>:_GLIBCXX_USE_CXX11_ABI=0>
$<$<BOOL:${ENABLE_TEST}>:SUPPORT_LARGE_MODEL_ENABLE=1>
)
target_link_options(ge_intf_pub_base INTERFACE
$<$<AND:$<BOOL:${ENABLE_ASAN}>,$<BOOL:${MDC_COMPILE_RUNTIME}>>:-lunwind -shared-libasan>
)
target_link_libraries(ge_intf_pub_base INTERFACE
-lrt
-ldl
)
########## ge_intf_pub ##########
add_library(ge_intf_pub INTERFACE)
target_compile_options(ge_intf_pub INTERFACE
${OPTIMIZE_OPTION}
$<$<NOT:$<STREQUAL:${OPTIMIZE_OPTION},-O0>>:-D_FORTIFY_SOURCE=2>
)
target_link_libraries(ge_intf_pub INTERFACE
$<BUILD_INTERFACE:intf_pub>
$<BUILD_INTERFACE:ge_intf_pub_base>
)
########## ge_intf_pub_Os ##########
add_library(ge_intf_pub_Os INTERFACE)
target_compile_options(ge_intf_pub_Os INTERFACE
-Os
)
target_link_libraries(ge_intf_pub_Os INTERFACE
$<BUILD_INTERFACE:intf_pub>
$<BUILD_INTERFACE:ge_intf_pub_base>
)
########## ge_intf_pub c++14 ##########
add_library(ge_intf_pub_cxx14 INTERFACE)
target_link_libraries(ge_intf_pub_cxx14 INTERFACE
$<BUILD_INTERFACE:intf_pub_cxx14>
$<BUILD_INTERFACE:ge_intf_pub_base>
)
# 屏蔽pybind里的编译告警
add_library(pybind_options INTERFACE)
target_compile_options(pybind_options INTERFACE
-Wno-float-equal
-Wno-missing-field-initializers
)
########## ccache ##########
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND} CACHE PATH "cache Compiler")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND} CACHE PATH "cache Compiler")
endif()
message(STATUS "CMAKE_C_COMPILER_LAUNCHER:${CMAKE_C_COMPILER_LAUNCHER}")
message(STATUS "CMAKE_CXX_COMPILER_LAUNCHER:${CMAKE_CXX_COMPILER_LAUNCHER}")