pytorch/modules/module_test/CMakeLists.txt
Chen Lai 7605ce4ed8 [PyTorch] Enable test_lite_interpreter_runtime running in android (#54579)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54579

## Summary

1. Eliminate a few more tests when BUILD_LITE_INTERPRETER is on, such that test_lite_interpreter_runtime can build and run on device.
2. Remove `#include <torch/torch.h>`, because it's not needed.

## Test plan

Set the BUILD_TEST=ON `in build_android.sh`, then run
` BUILD_LITE_INTERPRETER=1 ./scripts/build_pytorch_android.sh x86`

push binary to android device:
```
 adb push ./build_android_x86/bin/test_lite_interpreter_runtime /data/local/tmp
```

Reorganize the folder in `/data/local/tmp` so the test binary and model file is like following:
```
/data/local/tmp/test_bin/test_lite_interpreter_runtime
/data/local/tmp/test/cpp/lite_interpreter_runtime/sequence.ptl
```
such that the model file is in the correct path and can be found by the test_lite_interpreter_runtime.

![image](https://user-images.githubusercontent.com/16430979/112276332-d89d1900-8c3d-11eb-91de-7bf10d1e418d.png)

Test Plan: Imported from OSS

Reviewed By: iseeyuan

Differential Revision: D27300720

Pulled By: cccclai

fbshipit-source-id: d9526c7d3db8c0d3e76c5a4d604c6877c78afdf9
2021-03-24 14:45:27 -07:00

24 lines
870 B
CMake

if(NOT CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
# If we are building the standalone module, we set the proper cmake variables.
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
find_package(Caffe2 REQUIRED)
set(BUILD_TEST ON)
option(BUILD_SHARED_LIBS "Build shared libs." ON)
endif()
if(BUILD_TEST AND NOT BUILD_LITE_INTERPRETER)
add_library(
caffe2_module_test_dynamic
${CMAKE_CURRENT_SOURCE_DIR}/module_test_dynamic.cc)
if(HAVE_SOVERSION)
set_target_properties(caffe2_module_test_dynamic PROPERTIES
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
endif()
target_link_libraries(caffe2_module_test_dynamic torch_library)
install(TARGETS caffe2_module_test_dynamic DESTINATION lib)
if(MSVC AND BUILD_SHARED_LIBS)
install(FILES $<TARGET_PDB_FILE:caffe2_module_test_dynamic> DESTINATION lib OPTIONAL)
endif()
endif()