Fix random "C1041: cannot open program database" errors when compiling on Windows (#88084)

Adds `/FS` option to `CMAKE_CXX_FLAGS` and `CMAKE_CUDA_FLAGS`.

So far I've encountered this kind of errors:

```
C:\Users\MyUser\AppData\Local\Temp\tmpxft_00004728_00000000-7_cuda.cudafe1.cpp: fatal error C1041: cannot open program database 'C:\Projects\pytorch\build\third_party\gloo\gloo\CMakeFiles\gloo_cuda.dir\vc140.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
```
when building with VS 2022.

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm

Related issues:
- https://github.com/pytorch/pytorch/issues/87691
- https://github.com/pytorch/pytorch/issues/39989
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88084
Approved by: https://github.com/ezyang
This commit is contained in:
Radek Bartoň 2022-10-31 21:11:16 +00:00 committed by PyTorch MergeBot
parent 73379acaf3
commit ba26bc0fc2
2 changed files with 4 additions and 1 deletions

View file

@ -545,6 +545,9 @@ if(MSVC)
# Try harder
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler /w -w")
string(APPEND CMAKE_CXX_FLAGS " /FS")
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler /FS")
endif(MSVC)
string(APPEND CMAKE_CUDA_FLAGS " -Xfatbin -compress-all")

View file

@ -795,7 +795,7 @@ def configure_extension_build():
# /EHsc is about standard C++ exception handling
# /DNOMINMAX removes builtin min/max functions
# /wdXXXX disables warning no. XXXX
extra_compile_args = ['/MD', '/EHsc', '/DNOMINMAX',
extra_compile_args = ['/MD', '/FS', '/EHsc', '/DNOMINMAX',
'/wd4267', '/wd4251', '/wd4522', '/wd4522', '/wd4838',
'/wd4305', '/wd4244', '/wd4190', '/wd4101', '/wd4996',
'/wd4275']