Fix multi-configuration on Windows CMake (CUDA) (#18548)
authorSacha <xsacha@gmail.com>
Tue, 2 Apr 2019 20:15:10 +0000 (13:15 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 2 Apr 2019 20:19:07 +0000 (13:19 -0700)
commit3027e783b1cba83546dab50610a9d244bc2632b2
treed827584a42a9e7d4c19d20f4c9f2a5b9442d24f5
parent36237c489373e907803354852d2001828339a51a
Fix multi-configuration on Windows CMake (CUDA) (#18548)

Summary:
Multiple configurations is the default (eg. Release;Debug) on Windows and this check always broke this configuration as CMAKE_BUILD_TYPE was not set. The workaround was to always set CMAKE_BUILD_TYPE to Debug or Release, which was very unfortunate.

The correct method is to use generator expressions that expand depending on the current CONFIG being processed.

Side note: Anywhere else CMAKE_BUILD_TYPE is checked should probably be fixed too.
Note that the CMakeLists.txt forces it in to Release mode. However, I came across this error when importing the prebuilt Config in to another project, where CMAKE_BUILD_TYPE was not set.

> 3>CMake Error at pre_built/pytorch-1.0.1/share/cmake/Caffe2/public/cuda.cmake:380 (message):
> 3>  Unknown cmake build type:

Proper support for configurations would mean we can build debug and release at the same time and as you can see, it is less CMake code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18548

Differential Revision: D14730790

Pulled By: ezyang

fbshipit-source-id: 70ae16832870d742c577c34a50ec7564c3da0afb
cmake/public/cuda.cmake
torch/CMakeLists.txt