# Best way to support different CUDA version

**URL:** https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313
**Category:** Code
**Tags:** os:windows, gen:vs, lang:cuda
**Created:** [January 24, 2023, 11:12am UTC](https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313 "2023-01-24T11:12:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![GiovaBx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/giovabx/32/3104_2.png) [@GiovaBx](https://discourse.cmake.org/u/GiovaBx)
#### Post date: [January 24, 2023, 11:12am UTC](https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313/1 "2023-01-24T11:12:57Z")

</div>

Hi all,  
I’m moving some of our internal libraries that use CUDA to cmake to generate a solution for Visual Studio (and then create conan packages from them).

I need to support different versions of CUDA (at the moment at least 10.0 and 11.1 , but more will be come in future).

I use the FindCUDAToolkit module to find the selected CUDA version, but I’m not able to force cmake to use these information when I specify CUDA as language to “cross compile” .cu files (i.e. `project(${TARGET_NAME} LANGUAGES CXX CUDA VERSION ${TARGET_VERSION})` )

Some details:  
I have a (cache) variable that defines the required CUDA version (`AIENGINE_CUDA_VERSION="10.0"`)

FindCUDAToolkit is able to find the required cuda version, I use

```auto
# Set the CUDA toolkit root to point to our desiderate version
set(CUDAToolkit_ROOT "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v${AIENGINE_CUDA_VERSION}")
# Check if the desiderate CUDA version exist
find_package(CUDAToolkit "${AIENGINE_CUDA_VERSION}" REQUIRED EXACT )

```

succeed with

```auto
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include (found suitable exact version "10.0.130")

```

But for some reason i’m not able to force cmake to actually use this version.

After the  
`project(${TARGET_NAME} LANGUAGES CXX CUDA VERSION ${TARGET_VERSION})`  
i get

```auto
-- The CUDA compiler identification is NVIDIA 11.1.74
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done

```

and then the generate solution is invalid.

I tweak some variables before the project command and apparently I’m able to force cuda 10.0

```auto
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done

```

but when I open the solution it still want to use the nvcc from cuda 11.1.

I’m sure that i miss something.

Someone can help me or gives me some hints?

Thanks

---

<div class="post-metadata">

### Author: ![GiovaBx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/giovabx/32/3104_2.png) [@GiovaBx](https://discourse.cmake.org/u/GiovaBx)
#### Post date: [January 25, 2023, 4:48pm UTC](https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313/2 "2023-01-25T16:48:18Z")

</div>

After further investigation I understand that I cannot actually change the CUDA Toolkit version from the CMakeLists.txt but the only way is to call cmake passing the option -T cuda=path\_to\_cuda\_toolkit.

Now I manage to make this both when the library solution is generate directly from cmake or from conan using cmake as generator.
