Skip to content

Commit 3803d1c

Browse files
peterjc123facebook-github-bot
authored andcommittedApr 28, 2019
Fix conda build for Windows (pytorch#19824)
Summary: Let's test it before merging. Pull Request resolved: pytorch#19824 Differential Revision: D15116111 Pulled By: soumith fbshipit-source-id: 0a73de3f045ee1349061674f5f8e2aaba382493c
1 parent 9b69da2 commit 3803d1c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
 

‎cmake/Dependencies.cmake

+31
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,22 @@ if(BUILD_TEST)
338338
if (NOT CAFFE2_USE_MSVC_STATIC_RUNTIME)
339339
set(gtest_force_shared_crt ON CACHE BOOL "force shared crt on gtest" FORCE)
340340
endif()
341+
# We need to replace googletest cmake scripts too.
342+
# Otherwise, it will sometimes break the build.
343+
# To make the git clean after the build, we make a backup first.
344+
if (MSVC AND MSVC_Z7_OVERRIDE)
345+
execute_process(
346+
COMMAND ${CMAKE_COMMAND}
347+
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
348+
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
349+
"-DREVERT=0"
350+
"-P"
351+
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
352+
RESULT_VARIABLE _exitcode)
353+
if(NOT ${_exitcode} EQUAL 0)
354+
message(WARNING "Patching failed for Google Test. The build may fail.")
355+
endif()
356+
endif()
341357

342358
# Add googletest subdirectory but make sure our INCLUDE_DIRECTORIES
343359
# don't bleed into it. This is because libraries installed into the root conda
@@ -363,6 +379,21 @@ if(BUILD_TEST)
363379

364380
# Recover build options.
365381
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
382+
383+
# To make the git clean after the build, we revert the changes here.
384+
if (MSVC AND MSVC_Z7_OVERRIDE)
385+
execute_process(
386+
COMMAND ${CMAKE_COMMAND}
387+
"-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake"
388+
"-DBACKUP=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake.bak"
389+
"-DREVERT=1"
390+
"-P"
391+
"${CMAKE_CURRENT_LIST_DIR}/GoogleTestPatch.cmake"
392+
RESULT_VARIABLE _exitcode)
393+
if(NOT ${_exitcode} EQUAL 0)
394+
message(WARNING "Reverting changes failed for Google Test. The build may fail.")
395+
endif()
396+
endif()
366397
endif()
367398

368399
# ---[ FBGEMM

‎cmake/GoogleTestPatch.cmake

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# CMake file to replace the string contents in Google Test and Google Mock
2+
# Usage example:
3+
# Patch the cmake file
4+
# cmake -DFILENAME=internal_utils.cmake
5+
# -DBACKUP=internal_utils.cmake.bak
6+
# -DREVERT=0
7+
# -P GoogleTestPatch.cmake
8+
# Revert the changes
9+
# cmake -DFILENAME=internal_utils.cmake
10+
# -DBACKUP=internal_utils.cmake.bak
11+
# -DREVERT=1
12+
# -P GoogleTestPatch.cmake
13+
14+
15+
if(REVERT)
16+
file(READ ${BACKUP} content)
17+
file(WRITE ${FILENAME} "${content}")
18+
file(REMOVE ${BACKUP})
19+
else(REVERT)
20+
file(READ ${FILENAME} content)
21+
file(WRITE ${BACKUP} "${content}")
22+
string(REGEX REPLACE "[-/]Z[iI]" "/Z7" content "${content}")
23+
file(WRITE ${FILENAME} "${content}")
24+
endif(REVERT)

0 commit comments

Comments
 (0)
Please sign in to comment.