Browse Source

FindCUDA: Disallow with CMP0147 under Visual Studio

FindCUDA's custom commands invoke `nvcc`, which invokes `cl`.  Under VS
this is done without a `/FS` flag, so `.pdb` generation races if we
use `BuildInParallel`.  The FindCUDA module has already been removed by
policy CMP0146 after being deprecated since CMake 3.10, so it is
simplest to just disallow this combination of features.

Issue: #24576
Brad King 2 years ago
parent
commit
7a7793e6d7

+ 7 - 0
Modules/FindCUDA.cmake

@@ -565,6 +565,13 @@ if(_FindCUDA_CMP0146 STREQUAL "NEW")
   message(FATAL_ERROR "The FindCUDA module has been removed by policy CMP0146.")
 endif()
 
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
+  cmake_policy(GET CMP0147 _FindCUDA_CMP0147)
+  if(_FindCUDA_CMP0147 STREQUAL "NEW")
+    message(FATAL_ERROR "The FindCUDA module does not work in Visual Studio with policy CMP0147.")
+  endif()
+endif()
+
 if(_FindCUDA_testing)
   set(_FindCUDA_included TRUE)
   return()

+ 1 - 0
Tests/RunCMake/find_package/CMP0147-NEW-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
Tests/RunCMake/find_package/CMP0147-NEW-stderr.txt

@@ -0,0 +1,7 @@
+^CMake Error at [^
+]*/Modules/FindCUDA.cmake:[0-9]+ \(message\):
+  The FindCUDA module does not work in Visual Studio with policy CMP0147\.
+Call Stack \(most recent call first\):
+  CMP0147-common\.cmake:[0-9]+ \(find_package\)
+  CMP0147-NEW\.cmake:[0-9]+ \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)$

+ 2 - 0
Tests/RunCMake/find_package/CMP0147-NEW.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0147 NEW)
+include(CMP0147-common.cmake)

+ 2 - 0
Tests/RunCMake/find_package/CMP0147-OLD.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0147 OLD)
+include(CMP0147-common.cmake)

+ 2 - 0
Tests/RunCMake/find_package/CMP0147-WARN.cmake

@@ -0,0 +1,2 @@
+# leave CMP0147 unset
+include(CMP0147-common.cmake)

+ 3 - 0
Tests/RunCMake/find_package/CMP0147-common.cmake

@@ -0,0 +1,3 @@
+cmake_policy(SET CMP0146 OLD)
+set(_FindCUDA_testing TRUE)
+find_package(CUDA MODULE)

+ 5 - 0
Tests/RunCMake/find_package/RunCMakeTest.cmake

@@ -42,6 +42,11 @@ run_cmake(CMP0145-NEW)
 run_cmake(CMP0146-OLD)
 run_cmake(CMP0146-WARN)
 run_cmake(CMP0146-NEW)
+if(RunCMake_GENERATOR MATCHES "Visual Studio")
+  run_cmake(CMP0147-OLD)
+  run_cmake(CMP0147-WARN)
+  run_cmake(CMP0147-NEW)
+endif()
 run_cmake(WrongVersionRange)
 run_cmake(EmptyVersionRange)
 run_cmake(VersionRangeWithEXACT)