support creating relocatable object target in add_library
Currently add_library only supports SHARED STATIC and OBJECT. When developing iOS programs I find relocatable object is very useful. It can solve many problems when distributing SDKs. An relocatable object is created by linker, gather object files into 1.
There are several advantages over static libraries:
- The linker can copy required code from static libraries into relocatable object. It's also called partial linking. If distributing a static library, you have to provide static libraries it depends on, and add linker flags of those dependencies. While distributing a relocatable object, nothing else is required.
- Avoid symbols conflicting. A relocatable object can hide the copied symbols from static libraries by linker, just like a shared library. If a program uses 2 SDKs (static libraries) and both depend on the same static library A, but both use modified version of A, so you can not use only one of them to let both SDKs work correctly, but linker will complain duplicated symbols if link both A.
I've tried to modify cmake source code to support relocatable object target, but It's difficult for me. Currently I use a SHARED library target and change linker flags to support relocatable object, see https://github.com/wang-bin/ios.cmake/blob/master/ios.cmake#L329 or https://github.com/wang-bin/cmake-tools/blob/master/tools.cmake#L301
Not only apple's toolchain, GNU toolchain (including mingw) also supports relocatable object.