[CMake] Gathering up required shared libraries

Gregory Crosswhite gcrosswhite at gmail.com
Mon Aug 1 21:12:15 EDT 2011


Hey everyone,

I am using CMake to build a package which has the normal unix layout,
i.e. programs are in bin/, libraries are in lib/, etc., and I would like
to simply copy all of the required shared non-system libraries into lib/
and make sure that the executable is updated to look for them there so
that I can have an standalone distribution.  CMake *almost* supports
this with fixup_bundle, but unless I am missing something it doesn't
seem to give me any control as to where the shared libraries are
installed, and it doesn't update the executable except on OSX --- though
the latter is not a big deal since if I understand correctly I can just
add @executable_path@/../lib to the RPATH.  Furthermore, on Linux it
incorrectly assumes that libraries in /usr/lib should be considered
system libraries (that is, guaranteed to be available everywhere), when
in fact only libraries in /lib should be, which means that I can't even
easily use get_prerequisites directly to find all of the libraries that
I need and then copy them to the correct location myself.

(Of course, an alternative would be to just statically-link everything,
but frankly having searched around it looks like it is simply impossible
for me to force all non-system libraries to be statically linked,
especially since once of them is libgfortran which is included
automatically by the gfortran compiler and I can't figure out a good way
to get CMake to reliably link statically to libgfortran instead of
dynamically.  If anyone has any recommendations on this front I would be
happy to hear them.)

So anyway, at the moment to do what I want it looks like I would have to
make my own project-specific copies of GetPrerequisites.cmake and
BundleUtilities.cmake and then hack them up in order to force them to do
what I want.  But I can't help but think that there must have lots of
people out there who have wanted to do what I want to do and so this
problem must have been solved in a much better way.  So does anyone have
advice for a way to do what I want, i.e. an easy way to copy all
non-system libraries (where only /lib is interpreted to be the location
of system libraries) to a directory of my choosing relative to the
installation prefix and to modify the executable to make sure it finds
them?  Or is my only option really to copy into my project and hack up
GetPrerequisites.cmake and BundleUtilities.cmake?

Thanks a lot in advance!  :-)

Cheers,
Greg


More information about the CMake mailing list