When the NVPTX target is enabled, MLIR provides the MLIRGPUtoCUDATransforms conversion library and the MLIRTestTransforms test library as well as the MLIRMlirOptMain one depend on this transform. If a local LLVM build with enabled NVPTX is installed, the information about the libraries and their dependencies is stored into a generated lib\cmake\mlir\MLIRTargets.cmake file.
But when NVPTX is disabled and LLVM is build without NVPTX (only with X86 for example), the MLIRGPUtoCUDATransforms conversion library is not created and there is no information about the library in the generated lib\cmake\mlir\MLIRTargets.cmake file. Regardless this fact, the MLIRTestTransforms still depends on the conversion library and the MLIRTargets.cmake file contains the following line:
set_target_properties(MLIRTestTransforms PROPERTIES INTERFACE_LINK_LIBRARIES "MLIRAffineOps;MLIRAnalysis;MLIREDSC;MLIRGPU;MLIRGPUtoCUDATransforms;... )
The patch wraps MLIRGPUtoCUDATransforms into a condition: MLIRTestTransforms depends on the library iff MLIR_CUDA_CONVERSIONS_ENABLED is true.