From faf3d7d224ae2292e88b8238271a7ff97950ddf9 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Wed, 10 Oct 2018 13:23:07 -0400
Subject: VS: Add workaround for CUDA compiler PDB location with space

CUDA Toolkit Visual Studio Integration for version 9.2 and above does
honor the `ClCompile.ProgramDataBaseFileName` field when telling `nvcc`
how to invoke `cl`.  Unfortunately it does not quote paths with spaces
correctly:

    -Xcompiler "... /Fd"C:\path\with space\foo.pdb" ..."

Work around this by converting the PDB location to a relative path.
Likely we could always do this, but for now make a minimal change
just for CUDA support.

Fixes: #18440
---
 Source/cmVisualStudio10TargetGenerator.cxx | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 9c95cc5..2c2342e 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -2671,6 +2671,13 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
     // Specify the compiler program database file if configured.
     std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
     if (!pdb.empty()) {
+      if (this->GlobalGenerator->IsCudaEnabled()) {
+        // CUDA does not quote paths with spaces correctly when forwarding
+        // this to the host compiler.  Use a relative path to avoid spaces.
+        // FIXME: We can likely do this even when CUDA is not involved,
+        // but for now we will make a minimal change.
+        pdb = this->ConvertPath(pdb, true);
+      }
       ConvertToWindowsSlash(pdb);
       e2.Element("ProgramDataBaseFileName", pdb);
     }
-- 
cgit v0.12