[cmake-developers] Use linker build phase for Xcode 4 generator

Nicolas Tessore n.tessore at gmail.com
Mon Jun 3 15:38:47 EDT 2013


Hello,

after initial discussion at http://www.cmake.org/Bug/view.php?id=14185, I
would like to propose to change the Xcode generator for version 4 to use
the regular "Link Binary With Libraries" build phase for linking.

Instead of adding libraries to the OTHER_LDFLAGS setting, it should be
possible to use the regular build phase for qualified libraries. A library
is qualified if all target configurations contain *exactly one* library
with the same name.

Adding libraries to the build phase should be done in exactly the same way
Xcode 4 does it:

- If the library is part of the project, add a PBXBuildFile referencing the
"libfoo.a" build product.
- If the library is not part of the project and its path is known, add a
PBXBuildFile referencing a new PBXFileReference with name = "libfoo.a",
path = "/path/to/debug/libfoo.a". Add the configuration-specific paths to
the library to each LIBRARY_SEARCH_PATHS. Add the reference to the target
group.
- If the library's path is not known, add a PBXBuildFile referencing a new
PBXFileReference with name="libfoo.a", path = "libfoo.a". Add the reference
to the target group.

The order in which the libraries are added to the build phase is preserved.
The same goes for paths added to LIBRARY_SEARCH_PATHS.

Linking libraries in this way has the huge advantage that when using
multiple projects in a workspace, Xcode will automatically resolve
dependencies and build libraries as necessary. Without this, it's
impossible to have both a library and executable project together in a
Xcode workspace because Xcode builds the library in its DerivedData folder,
and the executable will not find it. Plus, it would be nice to skip the
"hackish" post-build phase.

As far as I can see, there is just one possible issue with this. Say there
is "libfoo.a" in two locations, ie. "/usr/lib" and "/usr/local/lib". If
"/usr/lib" comes first in LIBRARY_SEARCH_PATHS, it is impossible to link to
"/usr/local/lib/libfoo.a". This is however a limitation of Xcode, and the
same problem occurs when manually setting up a project.

Please let me know if you think this is feasible. I have created a rough
version of the generator that uses the build phase, and everything seems to
be working fine, both for projects and for workspaces.

Nic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20130603/5bfbdec8/attachment.html>


More information about the cmake-developers mailing list