• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.12)
2project(Lite)
3
4set(BUILD_LITE "on")
5
6include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/secure_option.cmake)
7include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compile_link_option.cmake)
8
9if(TOOLCHAIN_NAME STREQUAL "himix200")
10  set(TARGET_HIMIX200 on)
11  add_compile_definitions(SUPPORT_NNIE)
12elseif(TOOLCHAIN_NAME STREQUAL "ohos-lite")
13  set(TARGET_OHOS_LITE on)
14  SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
15endif()
16
17if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0 AND NOT TARGET_HIMIX200)
18    message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
19endif()
20
21#Options that can be configured through environment variables or manually
22set(MSLITE_GPU_BACKEND "" CACHE STRING "enable gpu backend, \
23    only arm64 support opencl, only x86_64 support tensorrt, opencl/cuda/tensorrt/off")
24option(MSLITE_ENABLE_NPU "enable npu, only arm64 or arm32 support" off)
25option(MSLITE_ENABLE_TRAIN "enable train" on)
26option(MSLITE_ENABLE_SSE "enable SSE instruction set, only x86_64 support" off)
27option(MSLITE_ENABLE_AVX "enable AVX instruction set, only x86_64 support" off)
28option(MSLITE_ENABLE_CONVERTER "enable converter, only x86_64 support" on)
29option(MSLITE_ENABLE_TOOLS "enable tools" on)
30option(MSLITE_ENABLE_TESTCASES "enable testcase" off)
31option(MSLITE_ENABLE_NNIE "enable NNIE" off)
32option(MSLITE_ENABLE_RUNTIME_PASS "enable runtime pass" on)
33option(MSLITE_COMPILE_NNIE "compile NNIE" off)
34option(MSLITE_ENABLE_HIGH_PERFORMANCE "enable high performance" off)
35option(MSLITE_ENABLE_STRING_KERNEL "enable string kernel" on)
36option(MSLITE_ENABLE_CONTROLFLOW "enable control and tensorlist" on)
37option(MSLITE_ENABLE_AUTO_PARALLEL "enable automatic parallelism" on)
38option(MSLITE_ENABLE_WEIGHT_DECODE "enable weight decode" on)
39option(MSLITE_ENABLE_CUSTOM_KERNEL "enable extend kernel registry" on)
40option(MSLITE_ENABLE_MINDRT "enable mindrt use" on)
41option(MSLITE_ENABLE_DELEGATE "enable delegate use" on)
42option(MSLITE_ENABLE_V0 "support v0 schema" on)
43option(MSLITE_ENABLE_FP16 "Whether to compile Fp16 operator" off)
44option(MSLITE_ENABLE_ACL "enable ACL" off)
45option(MSLITE_ENABLE_MODEL_ENCRYPTION "enable model encryption, only converter support" on)
46option(MSLITE_ENABLE_NNRT "enable NNRT" off)
47
48#Option that can be configured through manually
49option(ENABLE_VERBOSE "" off)
50option(ENABLE_MODEL_OBF "if support model obfuscation" off)
51set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv, wrapper or full")
52
53if(DEFINED ENV{MSLITE_GPU_BACKEND})
54    set(MSLITE_GPU_BACKEND $ENV{MSLITE_GPU_BACKEND})
55endif()
56if(DEFINED ENV{MSLITE_ENABLE_NPU})
57    set(MSLITE_ENABLE_NPU $ENV{MSLITE_ENABLE_NPU})
58endif()
59if(DEFINED ENV{MSLITE_ENABLE_TRAIN})
60    set(MSLITE_ENABLE_TRAIN $ENV{MSLITE_ENABLE_TRAIN})
61endif()
62if(DEFINED ENV{MSLITE_ENABLE_SSE})
63    set(MSLITE_ENABLE_SSE $ENV{MSLITE_ENABLE_SSE})
64endif()
65if(DEFINED ENV{MSLITE_ENABLE_AVX})
66    set(MSLITE_ENABLE_AVX $ENV{MSLITE_ENABLE_AVX})
67endif()
68if(DEFINED ENV{MSLITE_ENABLE_CONVERTER})
69    set(MSLITE_ENABLE_CONVERTER $ENV{MSLITE_ENABLE_CONVERTER})
70endif()
71if(DEFINED ENV{MSLITE_ENABLE_TOOLS})
72    set(MSLITE_ENABLE_TOOLS $ENV{MSLITE_ENABLE_TOOLS})
73endif()
74if(DEFINED ENV{MSLITE_ENABLE_TESTCASES})
75    set(MSLITE_ENABLE_TESTCASES $ENV{MSLITE_ENABLE_TESTCASES})
76endif()
77if(DEFINED ENV{MSLITE_ENABLE_NNIE})
78    set(MSLITE_ENABLE_NNIE $ENV{MSLITE_ENABLE_NNIE})
79endif()
80if(DEFINED ENV{MSLITE_COMPILE_NNIE})
81    set(MSLITE_COMPILE_NNIE $ENV{MSLITE_COMPILE_NNIE})
82endif()
83if(DEFINED ENV{MSLITE_ENABLE_RUNTIME_PASS})
84    set(MSLITE_ENABLE_RUNTIME_PASS $ENV{MSLITE_ENABLE_RUNTIME_PASS})
85endif()
86if(DEFINED ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
87    set(MSLITE_ENABLE_HIGH_PERFORMANCE $ENV{MSLITE_ENABLE_HIGH_PERFORMANCE})
88endif()
89if(DEFINED ENV{MSLITE_ENABLE_STRING_KERNEL})
90    set(MSLITE_ENABLE_STRING_KERNEL $ENV{MSLITE_ENABLE_STRING_KERNEL})
91endif()
92if(DEFINED ENV{MSLITE_ENABLE_CONTROLFLOW})
93    set(MSLITE_ENABLE_CONTROLFLOW $ENV{MSLITE_ENABLE_CONTROLFLOW})
94endif()
95if(DEFINED ENV{MSLITE_ENABLE_AUTO_PARALLEL})
96    set(MSLITE_ENABLE_AUTO_PARALLEL $ENV{MSLITE_ENABLE_AUTO_PARALLEL})
97endif()
98if(DEFINED ENV{MSLITE_ENABLE_WEIGHT_DECODE})
99    set(MSLITE_ENABLE_WEIGHT_DECODE $ENV{MSLITE_ENABLE_WEIGHT_DECODE})
100endif()
101if(DEFINED ENV{MSLITE_ENABLE_CUSTOM_KERNEL})
102    set(MSLITE_ENABLE_CUSTOM_KERNEL $ENV{MSLITE_ENABLE_CUSTOM_KERNEL})
103endif()
104if(DEFINED ENV{MSLITE_ENABLE_MINDRT})
105    set(MSLITE_ENABLE_MINDRT $ENV{MSLITE_ENABLE_MINDRT})
106endif()
107if(DEFINED ENV{MSLITE_ENABLE_DELEGATE})
108    set(MSLITE_ENABLE_DELEGATE $ENV{MSLITE_ENABLE_DELEGATE})
109endif()
110if(DEFINED ENV{MSLITE_ENABLE_V0})
111    set(MSLITE_ENABLE_V0 $ENV{MSLITE_ENABLE_V0})
112endif()
113if(DEFINED ENV{MSLITE_ENABLE_FP16})
114    set(MSLITE_ENABLE_FP16 $ENV{MSLITE_ENABLE_FP16})
115endif()
116if(DEFINED ENV{MSLITE_ENABLE_ACL})
117    set(MSLITE_ENABLE_ACL $ENV{MSLITE_ENABLE_ACL})
118endif()
119if(DEFINED ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
120    set(MSLITE_ENABLE_MODEL_ENCRYPTION $ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
121endif()
122if(DEFINED ENV{MSLITE_ENABLE_NNRT})
123    set(MSLITE_ENABLE_NNRT $ENV{MSLITE_ENABLE_NNRT})
124endif()
125
126if(NOT MSLITE_ENABLE_ACL)
127    set(ENABLE_GLIBCXX ON)
128endif()
129
130if(PLATFORM_ARM64)
131    if(MSLITE_GPU_BACKEND STREQUAL "")
132        set(MSLITE_GPU_BACKEND "opencl")
133    endif()
134    if((NOT MSLITE_GPU_BACKEND STREQUAL "opencl") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off"))
135        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for arm64, MSLITE_GPU_BACKEND is set to off.")
136        set(MSLITE_GPU_BACKEND "off")
137    endif()
138elseif(PLATFORM_ARM32)
139    if((NOT MSLITE_GPU_BACKEND STREQUAL "opencl") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off") AND
140    (NOT MSLITE_GPU_BACKEND STREQUAL ""))
141        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for arm32, MSLITE_GPU_BACKEND is set to off.")
142        set(MSLITE_GPU_BACKEND "off")
143    endif()
144elseif(WIN32)
145    set(MSLITE_GPU_BACKEND "off")
146else()
147    if(MSLITE_GPU_BACKEND STREQUAL "")
148        set(MSLITE_GPU_BACKEND "off")
149    endif()
150    if((NOT MSLITE_GPU_BACKEND STREQUAL "tensorrt") AND (NOT MSLITE_GPU_BACKEND STREQUAL "off"))
151        message("invalid MSLITE_GPU_BACKEND value ${MSLITE_GPU_BACKEND} for x86_64, MSLITE_GPU_BACKEND is set to off.")
152        set(MSLITE_GPU_BACKEND "off")
153    endif()
154endif()
155
156if(PLATFORM_ARM64 OR PLATFORM_ARM32)
157    set(PLATFORM_ARM "on")
158    set(MSLITE_ENABLE_SSE off)
159    set(MSLITE_ENABLE_AVX off)
160    set(MSLITE_ENABLE_CONVERTER off)
161#set for cross - compiling toolchain
162    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
163    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
164    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
165else()
166    set(MSLITE_ENABLE_NPU off)
167endif()
168
169if(MSLITE_ENABLE_TRAIN)
170    set(SUPPORT_TRAIN on)
171    set(BUILD_MINDDATA full)
172endif()
173
174if(MSLITE_ENABLE_NPU)
175    set(SUPPORT_NPU on)
176    if(NOT PLATFORM_ARM)
177        message(FATAL_ERROR "NPU only support platform arm.")
178    endif()
179    if(DEFINED ENV{HWHIAI_DDK})
180        message("HWHIAI_DDK=$ENV{HWHIAI_DDK}")
181    else()
182        message(FATAL_ERROR "please set HWHIAI_DDK, example: export HWHIAI_DDK=/root/usr/hwhiai-ddk-100.510.010.010/")
183    endif()
184endif()
185
186if(TARGET_HIMIX200 OR TARGET_OHOS_LITE)
187  set(MSLITE_ENABLE_MINDRT off)
188endif()
189
190if(MSVC)
191  set(MSLITE_ENABLE_CONVERTER off)
192endif()
193
194if((MSLITE_ENABLE_CONVERTER OR MSLITE_ENABLE_TESTCASES) AND (
195        NOT MSLITE_ENABLE_MINDRT
196        OR NOT MSLITE_ENABLE_STRING_KERNEL
197        OR NOT MSLITE_ENABLE_CONTROLFLOW
198        OR NOT MSLITE_ENABLE_WEIGHT_DECODE
199        OR NOT MSLITE_ENABLE_CUSTOM_KERNEL))
200    message(FATAL_ERROR "If one of 'MSLITE_ENABLE_MINDRT MSLITE_ENABLE_STRING_KERNEL "
201            "MSLITE_ENABLE_CONTROLFLOW MSLITE_ENABLE_WEIGHT_DECODE MSLITE_ENABLE_CUSTOM_KERNEL'"
202            "is configured as off, MSLITE_ENABLE_CONVERTER and MSLITE_ENABLE_TESTCASES must also be configured as off")
203endif()
204
205if(((MSLITE_GPU_BACKEND STREQUAL tensorrt) OR MSLITE_ENABLE_NPU) AND (
206        NOT MSLITE_ENABLE_DELEGATE))
207    message(FATAL_ERROR "If MSLITE_ENABLE_DELEGATE use is configured as off, MSLITE_ENABLE_NPU must also be configured
208    as off and MSLITE_GPU_BACKEND nor can it be configured as tensorrt.")
209endif()
210
211if(MSLITE_ENABLE_FP16 AND PLATFORM_ARM32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
212        AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
213    message(STATUS "If you want to build fp16 in arm82_a32, \
214    your Clang version:[${CMAKE_CXX_COMPILER_VERSION}] must not be less than 9.0 and please use android nkd r21e!")
215    set(MSLITE_ENABLE_FP16 off)
216endif()
217
218message(STATUS "************MindSpore Lite Build Option:************")
219message(STATUS "\tMSLITE_GPU_BACKEND                = \t${MSLITE_GPU_BACKEND}")
220message(STATUS "\tMSLITE_ENABLE_NPU                 = \t${MSLITE_ENABLE_NPU}")
221message(STATUS "\tMSLITE_ENABLE_TRAIN               = \t${MSLITE_ENABLE_TRAIN}")
222message(STATUS "\tMSLITE_ENABLE_SSE                 = \t${MSLITE_ENABLE_SSE}")
223message(STATUS "\tMSLITE_ENABLE_AVX                 = \t${MSLITE_ENABLE_AVX}")
224message(STATUS "\tMSLITE_ENABLE_CONVERTER           = \t${MSLITE_ENABLE_CONVERTER}")
225message(STATUS "\tMSLITE_ENABLE_TOOLS               = \t${MSLITE_ENABLE_TOOLS}")
226message(STATUS "\tMSLITE_ENABLE_TESTCASES           = \t${MSLITE_ENABLE_TESTCASES}")
227message(STATUS "\tMSLITE_ENABLE_HIGH_PERFORMANCE    = \t${MSLITE_ENABLE_HIGH_PERFORMANCE}")
228message(STATUS "\tMSLITE_ENABLE_RUNTIME_PASS        = \t${MSLITE_ENABLE_RUNTIME_PASS}")
229message(STATUS "\tMSLITE_ENABLE_STRING_KERNEL       = \t${MSLITE_ENABLE_STRING_KERNEL}")
230message(STATUS "\tMSLITE_ENABLE_CONTROLFLOW         = \t${MSLITE_ENABLE_CONTROLFLOW}")
231message(STATUS "\tMSLITE_ENABLE_AUTO_PARALLEL       = \t${MSLITE_ENABLE_AUTO_PARALLEL}")
232message(STATUS "\tMSLITE_ENABLE_WEIGHT_DECODE       = \t${MSLITE_ENABLE_WEIGHT_DECODE}")
233message(STATUS "\tMSLITE_ENABLE_CUSTOM_KERNEL       = \t${MSLITE_ENABLE_CUSTOM_KERNEL}")
234message(STATUS "\tMSLITE_ENABLE_MINDRT              = \t${MSLITE_ENABLE_MINDRT}")
235message(STATUS "\tMSLITE_ENABLE_V0                  = \t${MSLITE_ENABLE_V0}")
236message(STATUS "\tBUILD_MINDDATA                    = \t${BUILD_MINDDATA}")
237message(STATUS "\tMSLITE_ENABLE_DELEGATE            = \t${MSLITE_ENABLE_DELEGATE}")
238message(STATUS "\tMSLITE_ENABLE_FP16                = \t${MSLITE_ENABLE_FP16}")
239message(STATUS "\tMSLITE_ENABLE_MODEL_ENCRYPTION    = \t${MSLITE_ENABLE_MODEL_ENCRYPTION}")
240
241if(MSLITE_ENABLE_HIGH_PERFORMANCE)
242    add_compile_definitions(ENABLE_HIGH_PERFORMANCE)
243endif()
244
245if(ENABLE_ASAN)
246    add_definitions(-fsanitize=address -fno-omit-frame-pointer)
247    if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
248        add_definitions(-mllvm -asan-use-private-alias=1)
249    endif()
250    add_link_options(-fsanitize=address)
251endif()
252
253if(MSLITE_ENABLE_ACL)
254    add_definitions(-D ENABLE_LITE_ACL)
255    add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
256    if(DEFINED ENV{ASCEND_CUSTOM_PATH})
257        set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
258    else()
259        set(ASCEND_PATH /usr/local/Ascend)
260    endif()
261    set(ASCEND_RUNTIME_PATH ${ASCEND_PATH}/fwkacllib/lib64)
262    set(ASCEND_TOOLKIT_RUNTIME_PATH ${ASCEND_PATH}/ascend-toolkit/latest/fwkacllib/lib64)
263endif()
264
265set(PKG_NAME_PREFIX mindspore-lite-${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION})
266
267if(SUPPORT_NPU)
268    set(DDK_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib")
269    set(DDK_INCLUDE_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib/include")
270    if(PLATFORM_ARM64)
271        set(DDK_LIB_PATH ${DDK_PATH}/lib64)
272    elseif(PLATFORM_ARM32)
273        set(DDK_LIB_PATH ${DDK_PATH}/lib)
274    endif()
275    add_compile_definitions(SUPPORT_NPU)
276endif()
277
278add_compile_definitions(NO_DLIB)
279
280if(NOT MSVC)
281    add_compile_options(-fPIC)
282endif()
283
284if(PLATFORM_ARM64)
285    set(RUNTIME_COMPONENT_NAME "android-aarch64")
286elseif(PLATFORM_ARM32)
287    set(RUNTIME_COMPONENT_NAME "android-aarch32")
288    if(TARGET_HIMIX200)
289        set(RUNTIME_COMPONENT_NAME "linux-aarch32")
290    elseif(TARGET_OHOS_LITE)
291        set(RUNTIME_COMPONENT_NAME "ohos-aarch32")
292    endif()
293elseif(WIN32)
294    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
295        set(RUNTIME_COMPONENT_NAME "win-x86")
296    else()
297        set(RUNTIME_COMPONENT_NAME "win-x64")
298    endif()
299else()
300    set(RUNTIME_COMPONENT_NAME "linux-x64")
301endif()
302
303if(MSLITE_COMPILE_NNIE AND (NOT PLATFORM_ARM))
304    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter/nnie)
305endif()
306
307string(REPLACE "/mindspore/lite" "" TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
308set(CORE_DIR ${TOP_DIR}/mindspore/core)
309set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
310set(NNACL_DIR ${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl)
311include_directories(${TOP_DIR})
312include_directories(${CORE_DIR})
313include_directories(${CORE_DIR}/ir)
314include_directories(${CCSRC_DIR})
315include_directories(${CMAKE_CURRENT_SOURCE_DIR})
316include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm)
317include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
318include_directories(${TOP_DIR}/third_party)
319include_directories(${CMAKE_BINARY_DIR})
320include_directories(${CCSRC_DIR}/minddata/dataset)
321
322include(${TOP_DIR}/cmake/utils.cmake)
323include(${TOP_DIR}/cmake/dependency_utils.cmake)
324include(${TOP_DIR}/cmake/dependency_securec.cmake)
325include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
326
327if(MSLITE_GPU_BACKEND STREQUAL opencl)
328    include(${TOP_DIR}/cmake/external_libs/opencl.cmake)
329endif()
330
331if(MSLITE_ENABLE_CONVERTER OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper" OR
332    MSLITE_ENABLE_TOOLS)
333    include(${TOP_DIR}/cmake/external_libs/json.cmake)
334endif()
335
336if(DEFINED ARCHS)
337    add_definitions(-DMS_COMPILE_IOS)
338endif()
339
340file(GLOB FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.fbs)
341ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src ${CMAKE_BINARY_DIR}/schema "")
342ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_inner_src ${CMAKE_BINARY_DIR}/schema/inner
343        "inner")
344
345if(ENABLE_VERBOSE)
346    set(CMAKE_VERBOSE_MAKEFILE on)
347endif()
348if(SUPPORT_TRAIN)
349    add_compile_definitions(SUPPORT_TRAIN)
350endif()
351if(ENABLE_NEON)
352    add_compile_definitions(ENABLE_NEON)
353endif()
354if(MSLITE_ENABLE_FP16)
355    add_compile_definitions(ENABLE_FP16)
356    if(PLATFORM_ARM32)
357        add_compile_definitions(ENABLE_ARM82_A32)
358    endif()
359endif()
360if(MSLITE_GPU_BACKEND STREQUAL opencl)
361    add_definitions(-DGPU_OPENCL)
362    gene_opencl(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/opencl/cl)
363    gene_opencl(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/opencl/cl/int8)
364    add_definitions(-DUSE_OPENCL_WRAPPER)
365    add_definitions(-DMS_OPENCL_PROFILE=false)
366    add_definitions(-DCL_TARGET_OPENCL_VERSION=200)
367    add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=120)
368    add_definitions(-DCL_HPP_MINIMUM_OPENCL_VERSION=120)
369    add_compile_definitions(SUPPORT_GPU)
370    include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-headers-src/)
371    include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-clhpp-src/include)
372endif()
373
374if(MSLITE_GPU_BACKEND STREQUAL cuda)
375    add_definitions(-DGPU_CUDA)
376    add_compile_definitions(SUPPORT_GPU)
377endif()
378if(MSLITE_GPU_BACKEND STREQUAL tensorrt)
379    add_compile_definitions(SUPPORT_GPU)
380    set(SUPPORT_TENSORRT on)
381    if(DEFINED ENV{TENSORRT_PATH})
382        message("TENSORRT_PATH = $ENV{TENSORRT_PATH}")
383    else()
384        message(FATAL_ERROR "please set TENSORRT_PATH, example: export TENSORRT_PATH=/root/usr/TensorRT-6.0.1.5/")
385    endif()
386    if(DEFINED ENV{CUDA_HOME})
387        message("CUDA_HOME = $ENV{CUDA_HOME}")
388    else()
389        message(FATAL_ERROR "please set CUDA_HOME, example: export CUDA_HOME=/usr/local/cuda-10.1/")
390    endif()
391endif()
392
393if(MSLITE_ENABLE_NNRT)
394set(SUPPORT_NNRT on)
395    add_compile_definitions(SUPPORT_NNRT)
396    add_compile_definitions(MS_COMPILE_OHOS)
397    include_directories(../../../base/hiviewdfx/hilog/interfaces/native/innerkits/include)
398endif()
399
400if(WIN32)
401    add_compile_definitions(BUILDING_DLL)
402endif()
403
404include_directories(${CORE_DIR}/mindrt/include)
405include_directories(${CORE_DIR}/mindrt/src)
406
407if(NOT WIN32 AND NOT APPLE)
408    if(ENABLE_MODEL_OBF)
409        add_compile_definitions(ENABLE_MODEL_OBF)
410    endif()
411endif()
412
413if(ENABLE_MODEL_OBF)
414    if(PLATFORM_ARM32)
415        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch32)
416    elseif(PLATFORM_ARM64)
417        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch64)
418    else()
419        set(OBF_LIB_DIR ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/linux-x64)
420    endif()
421    set(OBF_LIBS libmsdeobfuscator-lite.so)
422endif()
423
424if(MSLITE_ENABLE_CONVERTER)
425    include(${TOP_DIR}/cmake/external_libs/opencv.cmake)
426    include_directories(${PYTHON_INCLUDE_DIRS})
427    include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
428    include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
429    include(${TOP_DIR}/cmake/external_libs/glog.cmake)
430    if(MSLITE_ENABLE_MODEL_ENCRYPTION)
431        find_package(Patch)
432        include(${TOP_DIR}/cmake/external_libs/openssl.cmake)
433    endif()
434    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
435endif()
436
437if(MSLITE_ENABLE_MINDRT)
438    add_compile_definitions(ENABLE_MINDRT)
439endif()
440
441if(PLATFORM_ARM32)
442    add_definitions(-mfloat-abi=softfp -mfpu=neon)
443    add_compile_definitions(ENABLE_ARM32)
444    add_compile_definitions(ENABLE_ARM)
445endif()
446if(PLATFORM_ARM64)
447    add_compile_definitions(ENABLE_ARM64)
448    add_compile_definitions(ENABLE_ARM)
449endif()
450
451if(NOT PLATFORM_ARM)
452    if(MSLITE_ENABLE_AVX)
453        set(X86_64_SIMD "avx")
454        add_compile_definitions(ENABLE_SSE)
455        add_compile_definitions(ENABLE_AVX)
456        if(NOT MSVC)
457            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx -mfma")
458            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx -mfma")
459        endif()
460    elseif(MSLITE_ENABLE_SSE)
461        set(X86_64_SIMD "sse")
462        add_compile_definitions(ENABLE_SSE)
463        if(NOT MSVC)
464            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
465            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
466        endif()
467    endif()
468endif()
469
470if(BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper")
471    add_compile_definitions(ENABLE_ANDROID)
472    if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
473        add_compile_definitions(ENABLE_MD_LITE_X86_64)
474    endif()
475    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
476endif()
477
478if(BUILD_MINDDATA STREQUAL "lite_cv")
479    add_compile_definitions(ENABLE_ANDROID)
480    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
481endif()
482
483add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
484add_subdirectory(${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl build)
485
486add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)
487
488if(MSLITE_ENABLE_TOOLS)
489    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
490    if(SUPPORT_TRAIN)
491        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark_train)
492    endif()
493    if(NOT PLATFORM_ARM AND NOT WIN32)
494        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/cropper)
495        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen)
496        add_dependencies(fbs_src gen_ops)
497        add_dependencies(fbs_inner_src gen_ops)
498    endif()
499endif()
500
501if(NOT WIN32 AND MSLITE_ENABLE_TESTCASES)
502    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
503endif()
504
505if(NOT APPLE)
506    include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/file_list.cmake)
507    include(${TOP_DIR}/cmake/package_lite.cmake)
508endif()
509