From e3d031bc7cef6f61c287b1f642c0c928612c018c Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Thu, 4 Jan 2024 13:21:58 -0600 Subject: [PATCH] [CMake][MSVC] Disable permissive mode for MSVC builds (#16343) [CMake][MSVC] Use /permissive- flag for MSVC builds The C++ standard requires two-phase name resolution for templates. By default, MSVC uses a non-standard name resolution, in which all names are looked up when a template is instantiated. This has caused MSVC-specific compilation errors, ([example](https://github.com/apache/tvm/actions/runs/7400684492/job/20134841480?pr=16183)), which are quite difficult to debug. This commit updates adds the `/permissive-` flag when building TVM with MSVC, disabling the non-standard name resolution. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a55a629bd8c..09c656f8ccec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,11 @@ if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") add_compile_options(/bigobj) + # Use standard-conforming two-phase name resolution for templates. + # This minimizes the differences between g++/clang builds on Linux, + # and MSVC builds on Windows. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") + # MSVC already errors on undefined symbols, no additional flag needed. set(TVM_NO_UNDEFINED_SYMBOLS "")