CMakeLists.txt 1.7 KB
Newer Older
H
Huihuang Zheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
if ((NOT WITH_LITE) OR (NOT WITH_JAVA))
  return()
endif()

include(UseJava)
find_package(Java REQUIRED)

# We are only interested in finding jni.h: we do not care about extended JVM
# functionality or the AWT library.
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)

# Generate PaddlePredictor.jar
include_directories(${JNI_INCLUDE_DIRS})
add_jar(PaddlePredictor src/com/baidu/paddle/lite/PaddlePredictor.java)
get_target_property(_jarFile PaddlePredictor JAR_FILE)
get_target_property(_classDir PaddlePredictor CLASSDIR)
set(_stubDir "${CMAKE_CURRENT_BINARY_DIR}")

# Generate paddle_lite_jni.h
add_custom_target(
    paddle_lite_jni_header ALL
    COMMAND ${Java_JAVAH_EXECUTABLE} -verbose
        -classpath ${_classDir}
        -o paddle_lite_jni.h
        -jni
        com.baidu.paddle.lite.PaddlePredictor
    DEPENDS PaddlePredictor
)

# Generate paddle_lite_jni.so
include_directories(${JNI_INCLUDE_DIRS} ${_classDir} ${_stubDir})
lite_cc_library(paddle_lite_jni MODULE SRCS paddle_lite_jni.cc 
    DEPS light_api_lite cxx_api_lite
        paddle_api_full paddle_api_lite paddle_api_light op_registry_lite
        ${ops_lite} ${lite_kernel_deps}
    ARM_DEPS ${arm_kernels})
if (APPLE)
    # MacOS only accepts JNI lib ends with .jnilib or .dylib
    set_target_properties(paddle_lite_jni PROPERTIES SUFFIX ".jnilib")
elseif (WIN32)
    # Windows only accepts JNI lib ends with .dll
    set_target_properties(paddle_lite_jni PROPERTIES SUFFIX ".dll")
endif (APPLE)
target_link_libraries(paddle_lite_jni light_api_lite cxx_api_lite
    paddle_api_full paddle_api_lite paddle_api_light op_registry_lite 
    ${ops_lite} ${arm_kernels} ${lite_kernel_deps})