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

**URL:** <https://discourse.cmake.org/t/how-to-compile-same-file-in-same-target-with-different-macro/5372>\
**Category:** Code\
**Created:** [April 5, 2022, 11:58am UTC](https://discourse.cmake.org/t/how-to-compile-same-file-in-same-target-with-different-macro/5372 "2022-04-05T11:58:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hzhangxyz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hzhangxyz/32/2323_2.png) [@hzhangxyz](https://discourse.cmake.org/u/hzhangxyz)\
**Post date:** [April 5, 2022, 11:58am UTC](https://discourse.cmake.org/t/how-to-compile-same-file-in-same-target-with-different-macro/5372/1 "2022-04-05T11:58:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hzhangxyz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hzhangxyz/32/2323_2.png) [@hzhangxyz](https://discourse.cmake.org/u/hzhangxyz)\
**Post date:** [April 5, 2022, 1:19pm UTC](https://discourse.cmake.org/t/how-to-compile-same-file-in-same-target-with-different-macro/5372/2 "2022-04-05T13:19:11Z")

</div>

Finally, I use configure\_file to generate different files when configure.
