Is is possible to prevent NVCC promotion of warnings to errors?

I am unable to compile code with CUDA 10.2 because of an undefined option for WError. The error message thrown at compile time is:

nvcc fatal : Value 'return-type' is not defined for option 'Werror'

I searched hours to try to find what was setting the return-type value for WError, but to no avail. Ideally, it could simply be suppressed. I have tried setting these values in CMakeLists:

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ; -Wno-deprecated-gpu-targets -Xcudafe --diag_suppress=code_is_unreachable -Xcudafe --diag_suppress=loop_not_reachable -Xcudafe --diag_suppress=implicit_return_from_non_void_function -Xcudafe --diag_suppress=unsigned_compare_with_zero -Xcudafe --diag_suppress=undefined_identifier -Xcudafe --display_error_number)

These do absolutely nothing. No error number is displayed for the above mentioned error nor is undefined_identifier suppressed. Perhaps a better question is where is the return-type value coming from for WError, but then we are likely talking OpenCV code issues, and that particular repository doesn’t like to touch issues they see to be NVIDIA related.

By default, nvcc does not treat warning as errors. This has to be requested specifically with --Werror <kind>. return-type is not a valid kind. See chapter 4 of the nvcc documentation. If you are seeing something different, can you post the smallest self-contained CUDA program and the nvcc invocation used to compile it that demonstrates that?

If your build environment (makefile, Cmake, IDE) is passing an invalid --Werror kind to nvcc, I would suggest spending some quality time with it to find out where this is happening. Use whatever verbose modes it offers and it should become apparent.

My hypothesis is that the intention was to pass -Werror to the host compiler (specifically gcc for which return-type is a valid kind), in which case it needs to be prefixed with -Xcompiler. In other words, nvcc needs to be passed -Xcompiler -Werror=return-type.

Thank you, this clears up many details for me. I was eventually able to discover the problem. The source code was setting CUDA_HOST_COMPILER to nvcc instead of the required gcc-8 (for CUDA 10.2). Changing this value to /usr/bin/gcc-8 resolved the problem and it is compiling now. As for why nvcc had been specified as the host compiler, it is unclear. I will contact the repository owner to clarify.