Page MenuHomePhabricator

[CMake] Bug 25059 - CMake$MAJOR.$MINOR shared object name not compatible with ldconfig

Authored by beanz on Oct 16 2015, 7:09 PM.



This change makes the CMake build system generate libraries for Linux and Darwin matching the makefile build system.

Linux libraries follow the pattern lib${name}.${MAJOR}.${MINOR}.so so that ldconfig won't pick it up incorrectly.

Darwin libraries are not versioned.

Note: On linux the non-versioned symlink is generated at install-time not build time. I plan to fix that eventually, but I expect that is good enough for the purposes of fixing this bug.

Diff Detail


Event Timeline

beanz updated this revision to Diff 37668.Oct 16 2015, 7:09 PM
beanz retitled this revision from to [CMake] Bug 25059 - CMake$MAJOR.$MINOR shared object name not compatible with ldconfig.
beanz updated this object.
beanz added reviewers: tstellarAMD, loladiro.
beanz added a subscriber: llvm-commits.
tstellarAMD edited edge metadata.EditedOct 19 2015, 6:42 AM

This change makes the CMake build system generate libraries for Linux and Darwin matching the makefile build system.

The shared object name for cmake with this patch is still a little different from autoconf:


autoconf also creates a symlink with the stable release number: libLLVM-3.8.0svn ->

beanz updated this revision to Diff 37789.Oct 19 2015, 1:42 PM
beanz edited edge metadata.

Updates based on feedback from Tom and a bug fix for installing the symlinks. Turns out I need to add the symlink install actions after the library is installed otherwise the cmake commands to make the links fails.

With this change the output lib directory has these files:
-rwxr-xr-x 1 cbieneman staff 40585176 Oct 19 13:22 libLLVM-3.8.0svn.dylib
lrwxr-xr-x 1 cbieneman staff 16 Oct 19 13:37 libLLVM.dylib -> libLLVM3.8.dylib
lrwxr-xr-x 1 cbieneman staff 22 Oct 19 13:37 libLLVM3.8.dylib -> libLLVM-3.8.0svn.dylib

tstellarAMD accepted this revision.Nov 2 2015, 11:22 AM
tstellarAMD edited edge metadata.

I've tested this and it resolves my issues. Thanks.

This revision is now accepted and ready to land.Nov 2 2015, 11:22 AM
axw added a subscriber: axw.Nov 2 2015, 4:40 PM
axw added inline comments.
546–548 ↗(On Diff #37789)

Setting NO_SONAME means SONAME isn't set *at all*, which doesn't seem desirable.

$ objdump -p lib/  | grep -c SONAME

That doesn't seem desirable. I would expect to see the SONAME set to the same as the output name. I think you just want to not set SOVERSION/VERSION instead? Did you mean to set NO_SONAME only for Apple?

beanz updated this revision to Diff 39119.Nov 3 2015, 2:10 PM
beanz edited edge metadata.
  • Fixed setting the SONAME in the binary on Linux
  • Make SONAME goop optional, in autoconf we only apply it to libLLVM, not any of the other libraries

It is my belief that this patch makes our output on Linux and Darwin match autoconf.

axw added a comment.Nov 3 2015, 6:23 PM

In an autoconf build I get: ->

With this patch, in a CMake build I get: -> ->

I think what you should do is

  • change api_name to: set(api_name ${name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX})
  • set OUTPUT_NAME to ${api_name}
  • use ${api_name} in the -Wl,--soname flag
  • switch the order of ${api_name} and ${library_name} in the first llvm_install_library_symlink

Making these changes locally, I get: -> ->

which is exactly the same as autoconf, but with the extra symlink.

Do we still need to set SOVERSION/VERSION in llvm_add_library?

554 ↗(On Diff #39119)

setting LINK_FLAGS needs a separate set_target_properties with APPEND_STRING

beanz updated this revision to Diff 39220.Nov 4 2015, 11:03 AM

Feedback and fixes based on feedback from axw.

  • Properly setting LINK_FLAGS
  • Not setting VERSION or SOVERSION, this also means I don't need to set NO_SONAME
  • Re-structuring the symlink magic to actually match autoconf this time
axw added inline comments.Nov 4 2015, 3:07 PM
547 ↗(On Diff #39220)

Sorry, I actually meant to delete the comment about APPEND_STRING. I think set_target_properties' LINK_FLAGS is a special case.

Anyway, it turns out you can just delete this. If you don't specify SOVERSION, VERSION or NO_SONAME, CMake automatically set SONAME to the same as the output name.

LGTM with this last change. Thank you.

This revision was automatically updated to reflect the committed changes.
loladiro edited edge metadata.Jul 24 2016, 7:00 PM

I realize I may have missed my window of opportunity here, but do the Mac shared lib names no longer include the version? When I build a recent LLVM, I only get libLLVM.dylib, without any version numbers or even symlinks. Was that intentional?