Browse Source

FindCUDA: Fix varaible reset with CUDA_TOOLKIT_TARGET_DIR

CUDA_TOOLKIT_TARGET_DIR doesn't always exist in the cache or defined by the user
previous to using FindCUDA. In this case it will always reset the variables
making it impossible to manually change or set them. This can be fixed by
checking to see if the variable is defined before checking against the
previously used version stored in CUDA_TOOLKIT_TARGET_DIR_INTERNAL.
James Bigler 3 years ago
parent
commit
a7758394af
1 changed files with 3 additions and 1 deletions
  1. 3 1
      Modules/FindCUDA.cmake

+ 3 - 1
Modules/FindCUDA.cmake

@@ -799,7 +799,9 @@ if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}")
   unset(CUDA_VERSION CACHE)
 endif()
 
-if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}")
+# If CUDA_TOOLKIT_TARGET_DIR exists, check if it has changed.
+if(DEFINED CUDA_TOOLKIT_TARGET_DIR
+    AND NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}")
   cuda_unset_include_and_libraries()
 endif()