f36e3db0创建于 2022年12月22日历史提交
cmake_minimum_required(VERSION 3.12)
project(Lite)

set(BUILD_LITE "on")

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/secure_option.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compile_link_option.cmake)

if(TOOLCHAIN_NAME STREQUAL "himix200")
  set(TARGET_HIMIX200 on)
  add_compile_definitions(SUPPORT_NNIE)
elseif(TOOLCHAIN_NAME STREQUAL "ohos-lite")
  set(TARGET_OHOS_LITE on)
  SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0 AND NOT TARGET_HIMIX200)
    message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
endif()

#Options that can be configured through environment variables or manually
set(MSLITE_GPU_BACKEND "" CACHE STRING "enable gpu backend, \
    only arm64 support opencl, only x86_64 support tensorrt, opencl/cuda/tensorrt/off")
option(MSLITE_ENABLE_NPU "enable npu, only arm64 or arm32 support" off)
option(MSLITE_ENABLE_TRAIN "enable train" on)
option(MSLITE_ENABLE_SSE "enable SSE instruction set, only x86_64 support" off)
option(MSLITE_ENABLE_AVX "enable AVX instruction set, only x86_64 support" off)
option(MSLITE_ENABLE_CONVERTER "enable converter, only x86_64 support" on)
option(MSLITE_ENABLE_TOOLS "enable tools" on)
option(MSLITE_ENABLE_TESTCASES "enable testcase" off)
option(MSLITE_ENABLE_NNIE "enable NNIE" off)
option(MSLITE_ENABLE_RUNTIME_PASS "enable runtime pass" on)
option(MSLITE_COMPILE_NNIE "compile NNIE" off)
option(MSLITE_ENABLE_HIGH_PERFORMANCE "enable high performance" off)
option(MSLITE_ENABLE_STRING_KERNEL "enable string kernel" on)
option(MSLITE_ENABLE_CONTROLFLOW "enable control and tensorlist" on)
option(MSLITE_ENABLE_AUTO_PARALLEL "enable automatic parallelism" on)
option(MSLITE_ENABLE_WEIGHT_DECODE "enable weight decode" on)
option(MSLITE_ENABLE_CUSTOM_KERNEL "enable extend kernel registry" on)
option(MSLITE_ENABLE_MINDRT "enable mindrt use" on)
option(MSLITE_ENABLE_DELEGATE "enable delegate use" on)
option(MSLITE_ENABLE_V0 "support v0 schema" on)
option(MSLITE_ENABLE_FP16 "Whether to compile Fp16 operator" off)
option(MSLITE_ENABLE_ACL "enable ACL" off)
option(MSLITE_ENABLE_MODEL_ENCRYPTION "enable model encryption, only converter support" on)
option(MSLITE_ENABLE_NNRT "enable NNRT" off)

#Option that can be configured through manually
option(ENABLE_VERBOSE "" off)
option(ENABLE_MODEL_OBF "if support model obfuscation" off)
set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv, wrapper or full")

if(DEFINED ENV{MSLITE_GPU_BACKEND})
    set(MSLITE_GPU_BACKEND $ENV{MSLITE_GPU_BACKEND})
endif()
if(DEFINED ENV{MSLITE_ENABLE_NPU})
    set(MSLITE_ENABLE_NPU $ENV{MSLITE_ENABLE_NPU})
endif()
if(DEFINED ENV{MSLITE_ENABLE_TRAIN})
    set(MSLITE_ENABLE_TRAIN $ENV{MSLITE_ENABLE_TRAIN})
endif()
if(DEFINED ENV{MSLITE_ENABLE_SSE})
    set(MSLITE_ENABLE_SSE $ENV{MSLITE_ENABLE_SSE})
endif()
if(DEFINED ENV{MSLITE_ENABLE_AVX})
    set(MSLITE_ENABLE_AVX $ENV{MSLITE_ENABLE_AVX})
endif()
if(DEFINED ENV{MSLITE_ENABLE_CONVERTER})
    set(MSLITE_ENABLE_CONVERTER $ENV{MSLITE_ENABLE_CONVERTER})
endif()
if(DEFINED ENV{MSLITE_ENABLE_TOOLS})
    set(MSLITE_ENABLE_TOOLS $ENV{MSLITE_ENABLE_TOOLS})
endif()
if(DEFINED ENV{MSLITE_ENABLE_TESTCASES})
    set(MSLITE_ENABLE_TESTCASES $ENV{MSLITE_ENABLE_TESTCASES})
endif()
if(DEFINED ENV{MSLITE_ENABLE_NNIE})
    set(MSLITE_ENABLE_NNIE $ENV{MSLITE_ENABLE_NNIE})
endif()
if(DEFINED ENV{MSLITE_COMPILE_NNIE})
    set(MSLITE_COMPILE_NNIE $ENV{MSLITE_COMPILE_NNIE})
endif()
if(DEFINED ENV{MSLITE_ENABLE_RUNTIME_PASS})
    set(MSLITE_ENABLE_RUNTIME_PASS $ENV{MSLITE_ENABLE_RUNTIME_PASS})
endif()
if(DEFINED ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
    set(MSLITE_ENABLE_HIGH_PERFORMANCE $ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
endif()
if(DEFINED ENV{MSLITE_ENABLE_STRING_KERNEL})
    set(MSLITE_ENABLE_STRING_KERNEL $ENV{MSLITE_ENABLE_STRING_KERNEL})
endif()
if(DEFINED ENV{MSLITE_ENABLE_CONTROLFLOW})
    set(MSLITE_ENABLE_CONTROLFLOW $ENV{MSLITE_ENABLE_CONTROLFLOW})
endif()
if(DEFINED ENV{MSLITE_ENABLE_AUTO_PARALLEL})
    set(MSLITE_ENABLE_AUTO_PARALLEL $ENV{MSLITE_ENABLE_AUTO_PARALLEL})
endif()
if(DEFINED ENV{MSLITE_ENABLE_WEIGHT_DECODE})
    set(MSLITE_ENABLE_WEIGHT_DECODE $ENV{MSLITE_ENABLE_WEIGHT_DECODE})
endif()
if(DEFINED ENV{MSLITE_ENABLE_CUSTOM_KERNEL})
    set(MSLITE_ENABLE_CUSTOM_KERNEL $ENV{MSLITE_ENABLE_CUSTOM_KERNEL})
endif()
if(DEFINED ENV{MSLITE_ENABLE_MINDRT})
    set(MSLITE_ENABLE_MINDRT $ENV{MSLITE_ENABLE_MINDRT})
endif()
if(DEFINED ENV{MSLITE_ENABLE_DELEGATE})
    set(MSLITE_ENABLE_DELEGATE $ENV{MSLITE_ENABLE_DELEGATE})
endif()
if(DEFINED ENV{MSLITE_ENABLE_V0})
    set(MSLITE_ENABLE_V0 $ENV{MSLITE_ENABLE_V0})
endif()
if(DEFINED ENV{MSLITE_ENABLE_FP16})
    set(MSLITE_ENABLE_FP16 $ENV{MSLITE_ENABLE_FP16})
endif()
if(DEFINED ENV{MSLITE_ENABLE_ACL})
    set(MSLITE_ENABLE_ACL $ENV{MSLITE_ENABLE_ACL})
endif()
if(DEFINED ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
    set(MSLITE_ENABLE_MODEL_ENCRYPTION $ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
endif()
if(DEFINED ENV{MSLITE_ENABLE_NNRT})
    set(MSLITE_ENABLE_NNRT $ENV{MSLITE_ENABLE_NNRT})
endif()

if(NOT MSLITE_ENABLE_ACL)
    set(ENABLE_GLIBCXX ON)
endif()

if(PLATFORM_ARM64)
    if(MSLITE_GPU_BACKEND STREQUAL "")
        set(MSLITE_GPU_BACKEND "opencl")
    endif()
    if((NOT MSLITE_GPU_BACKEND STREQUAL "opencl") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off"))
        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for arm64, MSLITE_GPU_BACKEND is set to off.")
        set(MSLITE_GPU_BACKEND "off")
    endif()
elseif(PLATFORM_ARM32)
    if((NOT MSLITE_GPU_BACKEND STREQUAL "opencl") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off") AND
    (NOT MSLITE_GPU_BACKEND STREQUAL ""))
        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for arm32, MSLITE_GPU_BACKEND is set to off.")
        set(MSLITE_GPU_BACKEND "off")
    endif()
elseif(WIN32)
    set(MSLITE_GPU_BACKEND "off")
else()
    if(MSLITE_GPU_BACKEND STREQUAL "")
        set(MSLITE_GPU_BACKEND "off")
    endif()
    if((NOT MSLITE_GPU_BACKEND STREQUAL "tensorrt") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off"))
        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for x86_64, MSLITE_GPU_BACKEND is set to off.")
        set(MSLITE_GPU_BACKEND "off")
    endif()
endif()

if(PLATFORM_ARM64 OR PLATFORM_ARM32)
    set(PLATFORM_ARM "on")
    set(MSLITE_ENABLE_SSE off)
    set(MSLITE_ENABLE_AVX off)
    set(MSLITE_ENABLE_CONVERTER off)
#set for cross - compiling toolchain
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
else()
    set(MSLITE_ENABLE_NPU off)
endif()

if(MSLITE_ENABLE_TRAIN)
    set(SUPPORT_TRAIN on)
    set(BUILD_MINDDATA full)
endif()

if(MSLITE_ENABLE_NPU)
    set(SUPPORT_NPU on)
    if(NOT PLATFORM_ARM)
        message(FATAL_ERROR "NPU only support platform arm.")
    endif()
    if(DEFINED ENV{HWHIAI_DDK})
        message("HWHIAI_DDK=$ENV{HWHIAI_DDK}")
    else()
        message(FATAL_ERROR "please set HWHIAI_DDK, example: export HWHIAI_DDK=/root/usr/hwhiai-ddk-100.510.010.010/")
    endif()
endif()

if(TARGET_HIMIX200 OR TARGET_OHOS_LITE)
  set(MSLITE_ENABLE_MINDRT off)
endif()

if(MSVC)
  set(MSLITE_ENABLE_CONVERTER off)
endif()

if((MSLITE_ENABLE_CONVERTER OR MSLITE_ENABLE_TESTCASES) AND (
        NOT MSLITE_ENABLE_MINDRT
        OR NOT MSLITE_ENABLE_STRING_KERNEL
        OR NOT MSLITE_ENABLE_CONTROLFLOW
        OR NOT MSLITE_ENABLE_WEIGHT_DECODE
        OR NOT MSLITE_ENABLE_CUSTOM_KERNEL))
    message(FATAL_ERROR "If one of 'MSLITE_ENABLE_MINDRT MSLITE_ENABLE_STRING_KERNEL "
            "MSLITE_ENABLE_CONTROLFLOW MSLITE_ENABLE_WEIGHT_DECODE MSLITE_ENABLE_CUSTOM_KERNEL'"
            "is configured as off, MSLITE_ENABLE_CONVERTER and MSLITE_ENABLE_TESTCASES must also be configured as off")
endif()

if(((MSLITE_GPU_BACKEND STREQUAL tensorrt) OR MSLITE_ENABLE_NPU) AND (
        NOT MSLITE_ENABLE_DELEGATE))
    message(FATAL_ERROR "If MSLITE_ENABLE_DELEGATE use is configured as off, MSLITE_ENABLE_NPU must also be configured
    as off and MSLITE_GPU_BACKEND nor can it be configured as tensorrt.")
endif()

if(MSLITE_ENABLE_FP16 AND PLATFORM_ARM32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
        AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
    message(STATUS "If you want to build fp16 in arm82_a32, \
    your Clang version:[${CMAKE_CXX_COMPILER_VERSION}] must not be less than 9.0 and please use android nkd r21e!")
    set(MSLITE_ENABLE_FP16 off)
endif()

message(STATUS "************MindSpore Lite Build Option:************")
message(STATUS "\tMSLITE_GPU_BACKEND                = \t${MSLITE_GPU_BACKEND}")
message(STATUS "\tMSLITE_ENABLE_NPU                 = \t${MSLITE_ENABLE_NPU}")
message(STATUS "\tMSLITE_ENABLE_TRAIN               = \t${MSLITE_ENABLE_TRAIN}")
message(STATUS "\tMSLITE_ENABLE_SSE                 = \t${MSLITE_ENABLE_SSE}")
message(STATUS "\tMSLITE_ENABLE_AVX                 = \t${MSLITE_ENABLE_AVX}")
message(STATUS "\tMSLITE_ENABLE_CONVERTER           = \t${MSLITE_ENABLE_CONVERTER}")
message(STATUS "\tMSLITE_ENABLE_TOOLS               = \t${MSLITE_ENABLE_TOOLS}")
message(STATUS "\tMSLITE_ENABLE_TESTCASES           = \t${MSLITE_ENABLE_TESTCASES}")
message(STATUS "\tMSLITE_ENABLE_HIGH_PERFORMANCE    = \t${MSLITE_ENABLE_HIGH_PERFORMANCE}")
message(STATUS "\tMSLITE_ENABLE_RUNTIME_PASS        = \t${MSLITE_ENABLE_RUNTIME_PASS}")
message(STATUS "\tMSLITE_ENABLE_STRING_KERNEL       = \t${MSLITE_ENABLE_STRING_KERNEL}")
message(STATUS "\tMSLITE_ENABLE_CONTROLFLOW         = \t${MSLITE_ENABLE_CONTROLFLOW}")
message(STATUS "\tMSLITE_ENABLE_AUTO_PARALLEL       = \t${MSLITE_ENABLE_AUTO_PARALLEL}")
message(STATUS "\tMSLITE_ENABLE_WEIGHT_DECODE       = \t${MSLITE_ENABLE_WEIGHT_DECODE}")
message(STATUS "\tMSLITE_ENABLE_CUSTOM_KERNEL       = \t${MSLITE_ENABLE_CUSTOM_KERNEL}")
message(STATUS "\tMSLITE_ENABLE_MINDRT              = \t${MSLITE_ENABLE_MINDRT}")
message(STATUS "\tMSLITE_ENABLE_V0                  = \t${MSLITE_ENABLE_V0}")
message(STATUS "\tBUILD_MINDDATA                    = \t${BUILD_MINDDATA}")
message(STATUS "\tMSLITE_ENABLE_DELEGATE            = \t${MSLITE_ENABLE_DELEGATE}")
message(STATUS "\tMSLITE_ENABLE_FP16                = \t${MSLITE_ENABLE_FP16}")
message(STATUS "\tMSLITE_ENABLE_MODEL_ENCRYPTION    = \t${MSLITE_ENABLE_MODEL_ENCRYPTION}")

if(MSLITE_ENABLE_HIGH_PERFORMANCE)
    add_compile_definitions(ENABLE_HIGH_PERFORMANCE)
endif()

if(ENABLE_ASAN)
    add_definitions(-fsanitize=address -fno-omit-frame-pointer)
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        add_definitions(-mllvm -asan-use-private-alias=1)
    endif()
    add_link_options(-fsanitize=address)
endif()

if(MSLITE_ENABLE_ACL)
    add_definitions(-D ENABLE_LITE_ACL)
    add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
    if(DEFINED ENV{ASCEND_CUSTOM_PATH})
        set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
    else()
        set(ASCEND_PATH /usr/local/Ascend)
    endif()
    set(ASCEND_RUNTIME_PATH ${ASCEND_PATH}/fwkacllib/lib64)
    set(ASCEND_TOOLKIT_RUNTIME_PATH ${ASCEND_PATH}/ascend-toolkit/latest/fwkacllib/lib64)
endif()

set(PKG_NAME_PREFIX mindspore-lite-${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION})

if(SUPPORT_NPU)
    set(DDK_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib")
    set(DDK_INCLUDE_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib/include")
    if(PLATFORM_ARM64)
        set(DDK_LIB_PATH ${DDK_PATH}/lib64)
    elseif(PLATFORM_ARM32)
        set(DDK_LIB_PATH ${DDK_PATH}/lib)
    endif()
    add_compile_definitions(SUPPORT_NPU)
endif()

add_compile_definitions(NO_DLIB)

if(NOT MSVC)
    add_compile_options(-fPIC)
endif()

if(PLATFORM_ARM64)
    set(RUNTIME_COMPONENT_NAME "android-aarch64")
elseif(PLATFORM_ARM32)
    set(RUNTIME_COMPONENT_NAME "android-aarch32")
    if(TARGET_HIMIX200)
        set(RUNTIME_COMPONENT_NAME "linux-aarch32")
    elseif(TARGET_OHOS_LITE)
        set(RUNTIME_COMPONENT_NAME "ohos-aarch32")
    endif()
elseif(WIN32)
    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
        set(RUNTIME_COMPONENT_NAME "win-x86")
    else()
        set(RUNTIME_COMPONENT_NAME "win-x64")
    endif()
else()
    set(RUNTIME_COMPONENT_NAME "linux-x64")
endif()

if(MSLITE_COMPILE_NNIE AND (NOT PLATFORM_ARM))
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter/nnie)
endif()

string(REPLACE "/mindspore/lite" "" TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CORE_DIR ${TOP_DIR}/mindspore/core)
set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
set(NNACL_DIR ${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl)
include_directories(${TOP_DIR})
include_directories(${CORE_DIR})
include_directories(${CORE_DIR}/ir)
include_directories(${CCSRC_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
include_directories(${TOP_DIR}/third_party)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CCSRC_DIR}/minddata/dataset)

include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/dependency_utils.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)

if(MSLITE_GPU_BACKEND STREQUAL opencl)
    include(${TOP_DIR}/cmake/external_libs/opencl.cmake)
endif()

if(MSLITE_ENABLE_CONVERTER OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper" OR
    MSLITE_ENABLE_TOOLS)
    include(${TOP_DIR}/cmake/external_libs/json.cmake)
endif()

if(DEFINED ARCHS)
    add_definitions(-DMS_COMPILE_IOS)
endif()

file(GLOB FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.fbs)
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src ${CMAKE_BINARY_DIR}/schema "")
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_inner_src ${CMAKE_BINARY_DIR}/schema/inner
        "inner")

if(ENABLE_VERBOSE)
    set(CMAKE_VERBOSE_MAKEFILE on)
endif()
if(SUPPORT_TRAIN)
    add_compile_definitions(SUPPORT_TRAIN)
endif()
if(ENABLE_NEON)
    add_compile_definitions(ENABLE_NEON)
endif()
if(MSLITE_ENABLE_FP16)
    add_compile_definitions(ENABLE_FP16)
    if(PLATFORM_ARM32)
        add_compile_definitions(ENABLE_ARM82_A32)
    endif()
endif()
if(MSLITE_GPU_BACKEND STREQUAL opencl)
    add_definitions(-DGPU_OPENCL)
    gene_opencl(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/opencl/cl)
    gene_opencl(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/opencl/cl/int8)
    add_definitions(-DUSE_OPENCL_WRAPPER)
    add_definitions(-DMS_OPENCL_PROFILE=false)
    add_definitions(-DCL_TARGET_OPENCL_VERSION=200)
    add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=120)
    add_definitions(-DCL_HPP_MINIMUM_OPENCL_VERSION=120)
    add_compile_definitions(SUPPORT_GPU)
    include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-headers-src/)
    include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-clhpp-src/include)
endif()

if(MSLITE_GPU_BACKEND STREQUAL cuda)
    add_definitions(-DGPU_CUDA)
    add_compile_definitions(SUPPORT_GPU)
endif()
if(MSLITE_GPU_BACKEND STREQUAL tensorrt)
    add_compile_definitions(SUPPORT_GPU)
    set(SUPPORT_TENSORRT on)
    if(DEFINED ENV{TENSORRT_PATH})
        message("TENSORRT_PATH = $ENV{TENSORRT_PATH}")
    else()
        message(FATAL_ERROR "please set TENSORRT_PATH, example: export TENSORRT_PATH=/root/usr/TensorRT-6.0.1.5/")
    endif()
    if(DEFINED ENV{CUDA_HOME})
        message("CUDA_HOME = $ENV{CUDA_HOME}")
    else()
        message(FATAL_ERROR "please set CUDA_HOME, example: export CUDA_HOME=/usr/local/cuda-10.1/")
    endif()
endif()

if(MSLITE_ENABLE_NNRT)
set(SUPPORT_NNRT on)
    add_compile_definitions(SUPPORT_NNRT)
    add_compile_definitions(MS_COMPILE_OHOS)
    include_directories(../../../base/hiviewdfx/hilog/interfaces/native/innerkits/include)
endif()

if(WIN32)
    add_compile_definitions(BUILDING_DLL)
endif()

include_directories(${CORE_DIR}/mindrt/include)
include_directories(${CORE_DIR}/mindrt/src)

if(NOT WIN32 AND NOT APPLE)
    if(ENABLE_MODEL_OBF)
        add_compile_definitions(ENABLE_MODEL_OBF)
    endif()
endif()

if(ENABLE_MODEL_OBF)
    if(PLATFORM_ARM32)
        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch32)
    elseif(PLATFORM_ARM64)
        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch64)
    else()
        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/linux-x64)
    endif()
    set(OBF_LIBS libmsdeobfuscator-lite.so)
endif()

if(MSLITE_ENABLE_CONVERTER)
    include(${TOP_DIR}/cmake/external_libs/opencv.cmake)
    include_directories(${PYTHON_INCLUDE_DIRS})
    include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
    include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
    include(${TOP_DIR}/cmake/external_libs/glog.cmake)
    if(MSLITE_ENABLE_MODEL_ENCRYPTION)
        find_package(Patch)
        include(${TOP_DIR}/cmake/external_libs/openssl.cmake)
    endif()
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
endif()

if(MSLITE_ENABLE_MINDRT)
    add_compile_definitions(ENABLE_MINDRT)
endif()

if(PLATFORM_ARM32)
    add_definitions(-mfloat-abi=softfp -mfpu=neon)
    add_compile_definitions(ENABLE_ARM32)
    add_compile_definitions(ENABLE_ARM)
endif()
if(PLATFORM_ARM64)
    add_compile_definitions(ENABLE_ARM64)
    add_compile_definitions(ENABLE_ARM)
endif()

if(NOT PLATFORM_ARM)
    if(MSLITE_ENABLE_AVX)
        set(X86_64_SIMD "avx")
        add_compile_definitions(ENABLE_SSE)
        add_compile_definitions(ENABLE_AVX)
        if(NOT MSVC)
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx -mfma")
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx -mfma")
        endif()
    elseif(MSLITE_ENABLE_SSE)
        set(X86_64_SIMD "sse")
        add_compile_definitions(ENABLE_SSE)
        if(NOT MSVC)
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
        endif()
    endif()
endif()

if(BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper")
    add_compile_definitions(ENABLE_ANDROID)
    if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
        add_compile_definitions(ENABLE_MD_LITE_X86_64)
    endif()
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
endif()

if(BUILD_MINDDATA STREQUAL "lite_cv")
    add_compile_definitions(ENABLE_ANDROID)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
endif()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl build)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)

if(MSLITE_ENABLE_TOOLS)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
    if(SUPPORT_TRAIN)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark_train)
    endif()
    if(NOT PLATFORM_ARM AND NOT WIN32)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/cropper)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen)
        add_dependencies(fbs_src gen_ops)
        add_dependencies(fbs_inner_src gen_ops)
    endif()
endif()

if(NOT WIN32 AND MSLITE_ENABLE_TESTCASES)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()

if(NOT APPLE)
    include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/file_list.cmake)
    include(${TOP_DIR}/cmake/package_lite.cmake)
endif()