Fix conda build for Windows (#19824)

Summary:
Let's test it before merging.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19824

Differential Revision: D15116111

Pulled By: soumith

fbshipit-source-id: 0a73de3f045ee1349061674f5f8e2aaba382493c
This commit is contained in:
peter
2019-04-27 23:02:35 -07:00
committed by Facebook Github Bot
parent 9b69da2b55
commit 3803d1c901
2 changed files with 55 additions and 0 deletions

View File

@ -338,6 +338,22 @@ if(BUILD_TEST)
if (NOT CAFFE2_USE_MSVC_STATIC_RUNTIME)
set(gtest_force_shared_crt ON CACHE BOOL "force shared crt on gtest" FORCE)
endif()
# We need to replace googletest cmake scripts too.
# Otherwise, it will sometimes break the build.
# To make the git clean after the build, we make a backup first.
if (MSVC AND MSVC_Z7_OVERRIDE)
execute_process(
COMMAND ${CMAKE_COMMAND}
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
"-DREVERT=0"
"-P"
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
RESULT_VARIABLE _exitcode)
if(NOT ${_exitcode} EQUAL 0)
message(WARNING "Patching failed for Google Test. The build may fail.")
endif()
endif()
# Add googletest subdirectory but make sure our INCLUDE_DIRECTORIES
# don't bleed into it. This is because libraries installed into the root conda
@ -363,6 +379,21 @@ if(BUILD_TEST)
# Recover build options.
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
# To make the git clean after the build, we revert the changes here.
if (MSVC AND MSVC_Z7_OVERRIDE)
execute_process(
COMMAND ${CMAKE_COMMAND}
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
"-DREVERT=1"
"-P"
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
RESULT_VARIABLE _exitcode)
if(NOT ${_exitcode} EQUAL 0)
message(WARNING "Reverting changes failed for Google Test. The build may fail.")
endif()
endif()
endif()
# ---[ FBGEMM

View File

@ -0,0 +1,24 @@
# CMake file to replace the string contents in Google Test and Google Mock
# Usage example:
# Patch the cmake file
# cmake -DFILENAME=internal_utils.cmake
# -DBACKUP=internal_utils.cmake.bak
# -DREVERT=0
# -P GoogleTestPatch.cmake
# Revert the changes
# cmake -DFILENAME=internal_utils.cmake
# -DBACKUP=internal_utils.cmake.bak
# -DREVERT=1
# -P GoogleTestPatch.cmake
if(REVERT)
file(READ ${BACKUP} content)
file(WRITE ${FILENAME} "${content}")
file(REMOVE ${BACKUP})
else(REVERT)
file(READ ${FILENAME} content)
file(WRITE ${BACKUP} "${content}")
string(REGEX REPLACE "[-/]Z[iI]" "/Z7" content "${content}")
file(WRITE ${FILENAME} "${content}")
endif(REVERT)