1cmake_minimum_required(VERSION 3.4.1) 2set(PROJECT_NAME pytorch_testapp_jni) 3project(${PROJECT_NAME} CXX) 4set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested to build this target.") 5set(CMAKE_VERBOSE_MAKEFILE ON) 6 7set(build_DIR ${CMAKE_SOURCE_DIR}/build) 8 9set(pytorch_testapp_cpp_DIR ${CMAKE_CURRENT_LIST_DIR}/src/main/cpp) 10message(STATUS "ANDROID_STL:${ANDROID_STL}") 11file(GLOB pytorch_testapp_SOURCES 12 ${pytorch_testapp_cpp_DIR}/pytorch_testapp_jni.cpp 13) 14 15add_library(${PROJECT_NAME} SHARED 16 ${pytorch_testapp_SOURCES} 17) 18 19file(GLOB PYTORCH_INCLUDE_DIRS "${build_DIR}/pytorch_android*.aar/headers") 20file(GLOB PYTORCH_LINK_DIRS "${build_DIR}/pytorch_android*.aar/jni/${ANDROID_ABI}") 21 22target_compile_options(${PROJECT_NAME} PRIVATE 23 -fexceptions 24) 25 26set(BUILD_SUBDIR ${ANDROID_ABI}) 27 28target_include_directories(${PROJECT_NAME} PRIVATE 29 ${PYTORCH_INCLUDE_DIRS} 30) 31 32find_library(PYTORCH_LIBRARY pytorch_jni 33 PATHS ${PYTORCH_LINK_DIRS} 34 NO_CMAKE_FIND_ROOT_PATH) 35 36target_link_libraries(${PROJECT_NAME} 37 ${PYTORCH_LIBRARY} 38 log) 39