There are several ways to set up multiple toolchains with different CUDA versions when using CLion. The easiest way I found was to use micromamba, a lightweight (mini|ana)conda variant, and then use the environment script to configure the toolchains in CLion.
The idea is to be able to quickly switch from one sdk to the other, like the following
Micromamba (conda) environments
You can install micromamba by following the instructions here
Once installed, please take note of the code between
It will be needed later when we create the environment script for the toolchains.
Once you installed micromamba, you can start to install the CUDA sdks, like for example 11.8.0
For 12.3.0 and 12.3.1
Now you have the environments ready, with all the files installed in ~/micromamba/envs/… and not polluting the systems. So it is easy to get rid of them or update them.
CLion Toolchains
Now we need to create a shell script for each of the conda environments we created, to be used to configure the toolchain in CLion. One script could be called load_cuda_11.8.0.sh with the following content
Now we can add a toolchain in CLion, by using the above script as an environment file. Here I show my toolchains
You add a toolchain for every environment you want to use. Once you defined the toolchains, you need to create a Debug|Release configuration based on each toolchain, like here
Now when you set up your project, three configurations will be used, as I can show with these three screenshots
Troubleshooting
The amount of things that can go wrong is huge :-) For example, for the cuda sdk 11.8.0, I found that the libcudadevrt.a from the conda channel was not the correct one (at least for the version of the Nvidia drivers I had) so I had to take that library from the Nvidia sdk distribution and copy to my environment, like this
The nice thing is that I am not messing with my system libraries, just with a local conda environment.