Skip to content

Xcode: Link libraries using "Link Binary With Libraries" build phase

Gusts Kaksis requested to merge gusc/cmake:xcode-link-libs into master

Try linking all target linked libraries through "Link Binary With Libraries" build phase instead of linker flags, thus letting Xcode manage build product paths correctly. Additional checks for configuration dependant linking - in case the library is not present in all configurations revert back to linker flags which are per-configuration, because Xcode does not support per-configuration "Link Binary With Libraries"

This does change the order of libraries linked, but that does not seem to matter for Apple linkers invoked by Xcode, even for static libraries. The linker will go back and re-consider a static library from earlier on the link line when more symbols from its objects are needed.

Problem description in detail:

It fixes a linker issue of missing libraries when building an .xcarchive, because any dependency targets that generate libraries are built in different build paths than for a regular build. The problem was that all the libraries are linked with hard-coded absolute paths through linker flags (OTHER_LDFLAGS). Instead we need to leave path and linker argument management to Xcode, but only for targets that are affected by the same Xcode build. Other libraries that are linked with absolute paths or -l argument are not affected.

Fixes: #14185 (closed)

Edited by Brad King

Merge request reports