Skip to content

Add option to build the library using the python's torch installation #3004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0074 NEW)
project(torchvision)
set(CMAKE_CXX_STANDARD 14)
set(TORCHVISION_VERSION 0.7.0)

option(WITH_CUDA "Enable CUDA support" OFF)
option(USE_PYTHON_TORCH "Use python installation of torch" OFF)

if(WITH_CUDA)
enable_language(CUDA)
Expand All @@ -14,6 +16,18 @@ endif()

find_package(Python3 COMPONENTS Development)

if(USE_PYTHON_TORCH)
execute_process(COMMAND python3 -c "import torch; print(torch.__file__)"
RESULT_VARIABLE COMMAND_RESULT
OUTPUT_VARIABLE PYTORCH_INIT_FILE
ERROR_VARIABLE PYTHON_ERROR)
if(NOT ${COMMAND_RESULT} STREQUAL "0")
message(FATAL_ERROR "Failed to find Python's torch module.\n${PYTHON_ERROR}")
endif()
get_filename_component(Torch_ROOT ${PYTORCH_INIT_FILE} DIRECTORY)
message(STATUS "Using Python's torch installation located at ${Torch_ROOT}")
endif()

find_package(Torch REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
Expand Down