How to compile using nvcc

I’m trying to implement some CUDA API into my original program, but I don’t know how to compile it.

In my program, there’s a main.cpp file and two directory A and B. For each director, there’re some .cpp files. I first use g++ to compile each cpp including the main.cpp to get .o and .d files. Then I use ar to get libA.a and libB.a. Finally compile the main.o with libA and libB to generate final execution file.

Now, I add some GPU code only in one of the files in directory A and want to compile this program. What should I change in my compilation. I found that CUDA enables separate compilation. I wonder which part in my program should use nvcc to compile and which part should use g++.