Compiling opencv c++ with cuda

Opencv 4.7 generating compile errors in the CUDA .cu files. Reading in other forums it seems that there is a specific combination of Opencv, cmake and Visual Studio versions that play well together. I tried with Opencv 4.7, CUSA 12.1 and 11.5, cmake 3.26 and VS 2022 no go.
The error seems to come from the cmake generated CUDA compile command, I guess cmake is doing it wrong. Does anyone know how to fix this error?

There isn’t really a specific combination anymore (previously there were specific combinations of Visual Studio and CUDA). The latest stable version of everything (CUDA 12.1 , OpenCV 4.7.0, VS 2022 and CMake 3.25) should work.

As you haven’t posted the errors I’m going to assume that your error is the same as detailed here

If so you need to use the latest release candidate for CMake 3.26 where the bug is fixed.

In future if you want to build a new library I would advise you to use a stable version of CMake.