From e682d6bc28af2d8c5737d349cd63020726a279b0 Mon Sep 17 00:00:00 2001 From: Natsuki Subaru Date: Wed, 1 Apr 2026 14:38:29 +0300 Subject: [PATCH 1/2] Fix CUDA build with MSVC by enabling /Zc:preprocessor for nvcc host compilation on MSVC version greter then 1925 (VS 16.5) --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d700c32cfc..9f0a8fdaa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,6 +198,13 @@ if((USE_CUDA OR USE_TRT_RTX) AND CMAKE_CUDA_COMPILER) $<$:-Wno-deprecated-gpu-targets> $<$,$>:-Xcompiler=/wd4996> ) + + # nvcc compiles CUDA code with cl.exe, so we need to pass the /Zc:preprocessor option to avoid compilation errors + if(MSVC_VERSION GREATER_EQUAL 1925) + add_compile_options( + $<$,$>:-Xcompiler=/Zc:preprocessor> + ) + endif() if(WIN32) add_library(onnxruntime-genai-cuda SHARED ${generator_cudalib_srcs} "${GENERATORS_ROOT}/dll/onnxruntime-genai.rc") From 0b76951b43be2a99a878502d6446d617e80347ed Mon Sep 17 00:00:00 2001 From: NSubaru Date: Wed, 1 Apr 2026 14:45:40 +0300 Subject: [PATCH 2/2] Update CMakeLists.txt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f0a8fdaa7..1159acc486 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,7 @@ if((USE_CUDA OR USE_TRT_RTX) AND CMAKE_CUDA_COMPILER) ) # nvcc compiles CUDA code with cl.exe, so we need to pass the /Zc:preprocessor option to avoid compilation errors - if(MSVC_VERSION GREATER_EQUAL 1925) + if(WIN32 AND MSVC AND MSVC_VERSION GREATER_EQUAL 1925) add_compile_options( $<$,$>:-Xcompiler=/Zc:preprocessor> )