Enable torch static build on Windows
authorpeter <peterghost86@gmail.com>
Tue, 8 Jan 2019 21:03:10 +0000 (13:03 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 8 Jan 2019 21:19:57 +0000 (13:19 -0800)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15769

Reviewed By: yf225, pjh5

Differential Revision: D13597845

Pulled By: orionr

fbshipit-source-id: 99640e22974990ae570a4795ce07274c4447cb01

tools/build_pytorch_libs.bat
torch/CMakeLists.txt
torch/csrc/WindowsTorchApiMacro.h

index 390f25e..5848023 100755 (executable)
@@ -242,7 +242,7 @@ goto:eof
                   -DCMAKE_CXX_FLAGS="/EHa %USER_CFLAGS%" ^
                   -DCMAKE_EXE_LINKER_FLAGS="%USER_LDFLAGS%" ^
                   -DCMAKE_SHARED_LINKER_FLAGS="%USER_LDFLAGS%" ^
-                  -DUSE_ROCM=%USE_ROCM%
+                  -DUSE_ROCM=%USE_ROCM% %EXTRA_CAFFE2_CMAKE_FLAGS%
   IF ERRORLEVEL 1 exit 1
   IF NOT ERRORLEVEL 0 exit 1
 
index 578cd0e..f5343a8 100644 (file)
@@ -264,6 +264,7 @@ endif()
 
 
 if (TORCH_STATIC)
+  target_compile_definitions(torch PUBLIC TORCH_BUILD_STATIC_LIBS)
   add_library(torch STATIC ${TORCH_SRCS})
 else()
   add_library(torch SHARED ${TORCH_SRCS})
index 8b17709..371355a 100644 (file)
@@ -1,11 +1,15 @@
 #pragma once
 
 #ifdef _WIN32
+#if !defined(TORCH_BUILD_STATIC_LIBS)
 #if defined(torch_EXPORTS)
 #define TORCH_API __declspec(dllexport)
 #else
 #define TORCH_API __declspec(dllimport)
 #endif
+#else
+#define TORCH_API
+#endif
 #elif defined(__GNUC__)
 #if defined(torch_EXPORTS)
 #define TORCH_API __attribute__((__visibility__("default")))