How to share CUDA library with cpp code in CMake?

I was trying to build a piece of model that can be compiled to run on both GPU and CPU. Obviously I don’t want to write it twice, but I have a hard time to set it up. You can take a look at the question I asked here. Thanks.