• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.10)
2project(Lite-java)
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(TARGET_HIMIX200)
10    set(CMAKE_CXX_FLAGS "-Wno-error=maybe-uninitialized ${CMAKE_CXX_FLAGS}")
11endif()
12
13if(PLATFORM_ARM64 OR PLATFORM_ARM32)
14    set(PLATFORM_ARM "on")
15    add_compile_definitions(PLATFORM_ARM)
16endif()
17
18if(PLATFORM_ARM32 OR PLATFORM_ARM64)
19    #for performance
20    if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
21        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
22        -fdata-sections -ffast-math -fno-rtti -fno-exceptions")
23        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
24        -fdata-sections -ffast-math -fno-rtti -fno-exceptions")
25        if(TARGET_HIMIX200)
26            string(REPLACE "-fno-rtti " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
27        endif()
28    endif()
29endif()
30
31set(MS_VERSION_MAJOR ${MS_VERSION_MAJOR})
32set(MS_VERSION_MINOR ${MS_VERSION_MINOR})
33set(MS_VERSION_REVISION ${MS_VERSION_REVISION})
34set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} \
35  -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
36set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} \
37  -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
38set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
39
40#set for cross-compiling toolchain
41set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
42set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
43set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
44
45if(ENABLE_VERBOSE)
46    set(CMAKE_VERBOSE_MAKEFILE on)
47endif()
48
49if(PLATFORM_ARM32)
50    add_compile_definitions(ENABLE_ARM32)
51endif()
52if(PLATFORM_ARM64)
53    add_compile_definitions(ENABLE_ARM64)
54endif()
55
56set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
57set(LITE_DIR ${TOP_DIR}/mindspore/lite)
58
59include_directories(${CMAKE_CURRENT_SOURCE_DIR})
60include_directories(${LITE_DIR}) ## lite include
61include_directories(${TOP_DIR}) ## api include
62include_directories(${TOP_DIR}/mindspore/core/) ## core include
63include_directories(${LITE_DIR}/build) ## flatbuffers
64if(PLATFORM_ARM64 OR PLATFORM_ARM32)
65    link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/)
66else()
67    link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/linux_x86/)
68    set(JAVA_HOME "$ENV{JAVA_HOME}")
69    include_directories(${JAVA_HOME}/include/) ## jni
70    include_directories(${JAVA_HOME}/include/linux) ## jni
71endif()
72set(JNI_SRC
73        ${CMAKE_CURRENT_SOURCE_DIR}/runtime/model.cpp
74        ${CMAKE_CURRENT_SOURCE_DIR}/runtime/version.cpp
75        ${CMAKE_CURRENT_SOURCE_DIR}/runtime/ms_config.cpp
76        ${CMAKE_CURRENT_SOURCE_DIR}/runtime/ms_tensor.cpp
77        ${CMAKE_CURRENT_SOURCE_DIR}/runtime/lite_session.cpp
78        ${CMAKE_CURRENT_SOURCE_DIR}/common/jni_utils.cpp
79  )
80
81set(LITE_SO_NAME mindspore-lite)
82
83add_library(mindspore-lite-jni SHARED ${JNI_SRC})
84
85if(PLATFORM_ARM64 OR PLATFORM_ARM32)
86    find_library(log-lib log)
87    target_link_libraries(mindspore-lite-jni ${LITE_SO_NAME} ${log-lib})
88else()
89    target_link_libraries(mindspore-lite-jni ${LITE_SO_NAME})
90endif()
91
92if(SUPPORT_TRAIN)
93    set(LITE_TRAIN_SO_NAME mindspore-lite-train minddata-lite)
94    set(JNI_TRAIN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/train_session.cpp)
95    add_library(mindspore-lite-train-jni SHARED ${JNI_TRAIN_SRC})
96    if(PLATFORM_ARM64 OR PLATFORM_ARM32)
97        find_library(log-lib log)
98        target_link_libraries(mindspore-lite-train-jni ${LITE_TRAIN_SO_NAME} ${log-lib})
99    else()
100        target_link_libraries(mindspore-lite-train-jni ${LITE_TRAIN_SO_NAME})
101    endif()
102endif()
103