From 3027e783b1cba83546dab50610a9d244bc2632b2 Mon Sep 17 00:00:00 2001 From: Sacha Date: Tue, 2 Apr 2019 13:15:10 -0700 Subject: [PATCH] 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 | 16 +++------------- torch/CMakeLists.txt | 6 ------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/cmake/public/cuda.cmake b/cmake/public/cuda.cmake index 43665df..a4d87e9 100644 --- a/cmake/public/cuda.cmake +++ b/cmake/public/cuda.cmake @@ -364,20 +364,10 @@ endif() # Debug and Release symbol support if (MSVC) - if ((${CMAKE_BUILD_TYPE} MATCHES "Release") OR (${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo") OR (${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel")) - if (${CAFFE2_USE_MSVC_STATIC_RUNTIME}) - list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MT") - else() - list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MD") - endif() - elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug") - if (${CAFFE2_USE_MSVC_STATIC_RUNTIME}) - list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MTd") - else() - list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MDd") - endif() + if (${CAFFE2_USE_MSVC_STATIC_RUNTIME}) + list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MT$<$:d>") else() - message(FATAL_ERROR "Unknown cmake build type: " ${CMAKE_BUILD_TYPE}) + list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MD$<$:d>") endif() elseif (CUDA_DEVICE_DEBUG) list(APPEND CUDA_NVCC_FLAGS "-g" "-G") # -G enables device code debugging symbols diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index 7da46b6..6cd237f 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -270,12 +270,6 @@ target_compile_definitions(torch PUBLIC _THP_CORE) # until they can be unified, keep these lists synced with setup.py if(MSVC) - if (${CMAKE_BUILD_TYPE} MATCHES "Debug") - set (MSVC_RUNTIME_LIBRARY_FLAG "/MDd") - else() - set (MSVC_RUNTIME_LIBRARY_FLAG "/MD") - endif() - target_compile_options(torch PUBLIC ${MSVC_RUNTIME_LIBRARY_OPTION} /Z7 -- 2.7.4