From ffd50b82201effa13c8272729e7f8bfc9b7e0884 Mon Sep 17 00:00:00 2001 From: gunandrose4u <52735340+gunandrose4u@users.noreply.github.com> Date: Wed, 30 Sep 2020 12:38:11 -0700 Subject: [PATCH] SET USE_DISTRIBUTED OFF when libuv is not installed (#45554) Summary: Fixes #{issue number} Pull Request resolved: https://github.com/pytorch/pytorch/pull/45554 Reviewed By: izdeby Differential Revision: D24016825 Pulled By: mrshenli fbshipit-source-id: 332d860429626a915c06f98cad31e6db1cbc4eb1 --- CMakeLists.txt | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a094271a80..0d1225ab450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,9 +227,29 @@ option(ONNX_ML "Enable traditional ONNX ML API." ON) option(HAVE_SOVERSION "Whether to add SOVERSION to the shared objects" OFF) # Since TensorPipe does not support Windows, set it to OFF when WIN32 detected +# On Windows platform, if user does not install libuv in build conda env and +# does not set libuv_ROOT environment variable. Set USE_DISTRIBUTED to OFF. if(WIN32) set(USE_TENSORPIPE OFF) message(WARNING "TensorPipe cannot be used on Windows. Set it to OFF") + + if(USE_DISTRIBUTED AND NOT DEFINED ENV{libuv_ROOT}) + find_library( + libuv_tmp_LIBRARY + NAMES uv libuv + HINTS $ENV{CONDA_PREFIX}\\Library + PATH_SUFFIXES lib + REQUIRED + NO_DEFAULT_PATH) + if(NOT EXISTS ${libuv_tmp_LIBRARY}) + set(USE_DISTRIBUTED OFF) + set(USE_GLOO OFF) + message( + WARNING "Libuv is not installed in current conda env. Set USE_DISTRIBUTED to OFF.") + else() + set(ENV{libuv_ROOT} $ENV{CONDA_PREFIX}\\Library) + endif() + endif() endif() # Linux distributions do not want too many embedded sources, in that sense we @@ -292,12 +312,6 @@ if(LINUX) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed") endif() -if(WIN32 AND USE_DISTRIBUTED) - if(NOT DEFINED ENV{libuv_ROOT}) - set(ENV{libuv_ROOT} $ENV{CONDA_PREFIX}\\Library) - endif() -endif() - if(MSVC) foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE