Newer versions of CMake (3.18 and later), are "aware" of the choice of CUDA architectures which compilation of CUDA code targets. Targets have a CUDA_ARCHITECTURES property, which, when set, generates the appropriate -gencode arch=whatever,code=whatever compilation options for you. You will even get a warning if you don't set this value:
CMake Error in CMakeLists.txt:
CUDA_ARCHITECTURES is empty for target "my_cuda_app".
by default, this target property is initialized to CMAKE_CUDA_ARCHITECTURES. But CMAKE_CUDA_ARCHITECTURES itself is not initialized to anything (!)
How can we have CMake auto-detect an appropriate value for CUDA_ARCHITECTURES or the global CMAKD_CUDA_ARCHITECTURES? That is, use the architectures of GPUs installed on the system?