CMakeLists.txt 8.0 KB
Newer Older
H
hangq 已提交
1 2 3 4 5 6 7
cmake_minimum_required(VERSION 3.14)
project (Lite)

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

8
set(MS_VERSION_MAJOY 0)
9
set(MS_VERSION_MINOR 7)
10 11 12 13 14
set(MS_VERSION_REVISION 0)

set(DIR_PREFIX mindspore-lite)
set(MS_VERSION ${MS_VERSION_MAJOY}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION})
set(MAIN_DIR ${DIR_PREFIX}-${MS_VERSION})
H
hangq 已提交
15 16
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMS_VERSION_MAJOY=${MS_VERSION_MAJOY} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMS_VERSION_MAJOY=${MS_VERSION_MAJOY} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
17 18 19 20 21 22 23 24 25 26 27 28 29 30

if (SUPPORT_GPU)
    set(PROCESS_UNIT gpu)
else ()
    set(PROCESS_UNIT cpu)
endif ()

if (PLATFORM_ARM64)
    set(COMPONENT_NAME runtime-arm64-${PROCESS_UNIT})
elseif (PLATFORM_ARM32)
    set(COMPONENT_NAME runtime-arm32-${PROCESS_UNIT})
else ()
    set(COMPONENT_NAME convert-ubuntu)
endif()
31
set(RUN_X86_COMPONENT_NAME runtime-x86-${PROCESS_UNIT})
32

H
hangq 已提交
33 34 35 36 37 38 39 40
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CORE_DIR ${TOP_DIR}/mindspore/core)
set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
include_directories(${TOP_DIR})
include_directories(${CORE_DIR})
include_directories(${CCSRC_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Z
zhanyuan 已提交
41
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm)
H
hangq 已提交
42 43 44
include_directories(${TOP_DIR}/third_party)
include_directories(${TOP_DIR}/third_party/flatbuffers/include)

H
hangq 已提交
45 46 47
include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/dependency_utils.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
48 49 50 51
if (WIN32)
    include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
    include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
endif()
H
hangq 已提交
52

53
option(CMAKE_BUILD_TYPE "build type" Release)
H
hangq 已提交
54 55 56 57 58 59 60 61
option(BUILD_DEVICE "if build device" on)
option(SUPPORT_TRAIN "if build for on-device train" off)
option(PLATFORM_ARM64 "if build device for arm64" off)
option(PLATFORM_ARM32 "if build device for arm32" off)
option(BUILD_CONVERTER "if build converter" on)
option(ENABLE_FP16 "if build fp16 ops" off)
option(SUPPORT_GPU "if support gpu" off)
option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
H
hangq 已提交
62
option(BUILD_MINDDATA "" off)
H
hangq 已提交
63

64 65 66 67
set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_definitions(USE_ANDROID_LOG)
add_compile_definitions(NO_DLIB)
add_compile_options(-fPIC)
W
wsc 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDebug -g")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDebug -g")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
else ()
    ## enable for binscope for release
    set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}")
    if (NOT WIN32)
        set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_SHARED_LINKER_FLAGS}")
        set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_EXE_LINKER_FLAGS}")
    endif()
    string(REPLACE    " -g " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
W
wsc 已提交
82
endif ()
83

H
hangq 已提交
84 85
if (BUILD_DEVICE)
    add_compile_definitions(BUILD_DEVICE)
W
wsc 已提交
86
endif ()
H
hangq 已提交
87 88 89 90 91 92 93 94 95 96 97 98
if (SUPPORT_TRAIN)
    add_compile_definitions(SUPPORT_TRAIN)
endif()
if (ENABLE_NEON)
    add_compile_definitions(ENABLE_NEON)
endif ()
if (ENABLE_FP16)
    add_compile_definitions(ENABLE_FP16)
endif ()
if (SUPPORT_GPU)
    add_definitions(-DUSE_OPENCL_WRAPPER)
    add_definitions(-DMS_OPENCL_PROFILE=false)
C
chenzupeng 已提交
99
    add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=200)
H
hangq 已提交
100
    add_compile_definitions(SUPPORT_GPU)
W
wsc 已提交
101
    if (OFFLINE_COMPILE)
H
hangq 已提交
102
        add_compile_definitions(PROGRAM_WITH_IL)
W
wsc 已提交
103
    endif ()
H
hangq 已提交
104 105
    include_directories(${TOP_DIR}/third_party/OpenCL-Headers)
    include_directories(${TOP_DIR}/third_party/OpenCL-CLHPP/include)
W
wsc 已提交
106
endif ()
H
hangq 已提交
107

108 109 110
if (WIN32)
    add_compile_definitions(LITE_EXPORTS)
    add_compile_definitions(BUILDING_DLL)
W
wsc 已提交
111
endif ()
112

H
hangq 已提交
113 114
set(ANF_SRC
        ${CMAKE_CURRENT_SOURCE_DIR}/../core/ir/meta_tensor.cc
115 116
        ${CORE_DIR}/gvar/logging_level.cc
        ${CORE_DIR}/gvar/typeid_manager.cc
H
hangq 已提交
117
        ${CMAKE_CURRENT_SOURCE_DIR}/../core/base/base.cc
X
xuanyue 已提交
118
        ${CMAKE_CURRENT_SOURCE_DIR}/src/common/log_adapter.cc
H
hangq 已提交
119 120 121 122 123 124
        )
if (BUILD_CONVERTER)
    if (PLATFORM_ARM64 OR PLATFORM_ARM32)
        MESSAGE(FATAL_ERROR "Cannot build converter in arm platform")
    endif()
    find_package(Python3 3.7 COMPONENTS Interpreter Development)
W
wsc 已提交
125
    if (Python3_FOUND)
H
hangq 已提交
126 127 128 129 130
        set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
        set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
        if (WIN32)
            if (Python3_DIR)
                message("Python3_DIR set already: " ${Python3_DIR})
W
wsc 已提交
131
            else ()
H
hangq 已提交
132 133 134 135 136
                string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
                string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
                math(EXPR Python3_DIR_LEN  ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
                string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
                message("Python3_DIR: " ${Python3_DIR})
W
wsc 已提交
137
            endif ()
H
hangq 已提交
138
            link_directories(${Python3_DIR})
W
wsc 已提交
139 140
        endif ()
    else ()
H
hangq 已提交
141 142 143
        find_python_package(py_inc py_lib)
        set(PYTHON_INCLUDE_DIRS "${py_inc}")
        set(PYTHON_LIBRARIES "${py_lib}")
W
wsc 已提交
144
    endif ()
H
hangq 已提交
145
    include_directories(${PYTHON_INCLUDE_DIRS})
146
    include(${TOP_DIR}/cmake/external_libs/json.cmake)
H
hangq 已提交
147 148 149 150 151
    include(${TOP_DIR}/cmake/external_libs/pybind11.cmake)
    include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
    include_directories(${TOP_DIR}/third_party/protobuf/build/include)
    link_directories(${TOP_DIR}/third_party/protobuf/build/lib)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
W
wsc 已提交
152
endif ()
H
hangq 已提交
153 154 155 156 157

if (BUILD_DEVICE)
    if (PLATFORM_ARM32 OR PLATFORM_ARM64)
        if (NOT DEFINED ENV{ANDROID_NDK})
            message(FATAL_ERROR "env ANDROID_NDK should be setted for ARM compile")
W
wsc 已提交
158
        endif ()
H
hangq 已提交
159
        add_compile_definitions(ENABLE_ARM)
W
wsc 已提交
160
    endif ()
H
hangq 已提交
161 162 163
    if (PLATFORM_ARM32)
        add_definitions(-mfloat-abi=softfp -mfpu=neon)
        add_compile_definitions(ENABLE_ARM32)
W
wsc 已提交
164
    endif ()
H
hangq 已提交
165 166 167
    if (PLATFORM_ARM64)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod+fp16")
        add_compile_definitions(ENABLE_ARM64)
168 169 170
        if (ENABLE_FP16)
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+dotprod+fp16")
        endif ()
W
wsc 已提交
171 172
    endif ()
endif ()
E
ervinzhang 已提交
173 174 175 176 177 178

if (BUILD_MINDDATA)
    # opencv
    set(OpenCV_DIR ${TOP_DIR}/third_party/opencv/build)
    find_package(OpenCV REQUIRED)
    include_directories(${OpenCV_INCLUDE_DIRS})
E
ervinzhang 已提交
179 180 181
    # json
    if (NOT BUILD_CONVERTER)
        include(${TOP_DIR}/cmake/external_libs/json.cmake)
W
wsc 已提交
182
    endif ()
E
ervinzhang 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    # eigen
    include_directories(${TOP_DIR}/third_party/eigen/)
    # jpeg-turbo
    add_library(jpeg-turbo SHARED IMPORTED)
    set_target_properties(jpeg-turbo PROPERTIES
        IMPORTED_LOCATION ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so
    )
    add_library(jpeg SHARED IMPORTED)
    set_target_properties(jpeg PROPERTIES
        IMPORTED_LOCATION ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so
    )
    include_directories(${TOP_DIR}/third_party/libjpeg-turbo/include)

    add_compile_definitions(ENABLE_ANDROID)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
W
wsc 已提交
198
endif ()
E
ervinzhang 已提交
199 200

if (BUILD_DEVICE)
H
hangq 已提交
201
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
C
chenjianping 已提交
202
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl)
203 204 205 206
    if (NOT WIN32)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/time_profile)
W
wsc 已提交
207 208
    endif ()
endif ()
209

W
wangshaocong 已提交
210
include(${TOP_DIR}/cmake/package_lite.cmake)