From c14a6e35511fffcc5637a671fb6def4d4d539268 Mon Sep 17 00:00:00 2001
From: Sam Yates <yates@cscs.ch>
Date: Wed, 29 Aug 2018 16:52:37 +0200
Subject: [PATCH] Fix cpu architecture specification vs nvcc bug. (#578)

Fixes #575.

* Guard CPU architecture option for nvcc with generator expression.
---
 cmake/CompilerOptions.cmake | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake
index 9ae81d6e..9fca7493 100644
--- a/cmake/CompilerOptions.cmake
+++ b/cmake/CompilerOptions.cmake
@@ -135,5 +135,12 @@ function(set_arch_target optvar arch)
         endif()
     endif()
 
-    set("${optvar}" "${arch_opt}" PARENT_SCOPE)
+    # Prefix architecture options with `-Xcompiler=` when compiling CUDA sources, i.e.
+    # with nvcc.
+    set(arch_opt_cuda_guarded)
+    foreach(opt ${arch_opt})
+        list(APPEND arch_opt_cuda_guarded "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=>${opt}")
+    endforeach()
+
+    set("${optvar}" "${arch_opt_cuda_guarded}" PARENT_SCOPE)
 endfunction()
-- 
GitLab