How to compile same file in same target with different macro?

I have a c++ library, to build it, I need to compile the same file several time with different macro. How to do it?

It seems i can create object library several times with different name to do it. But i need manually add something like -fPIC to those object library, while -fPIC is not a cross platform option.

Finally, I use configure_file to generate different files when configure.