[CMake] padding link arguments to the linker

Mike Jackson imikejackson at gmail.com
Thu Feb 9 11:13:12 EST 2006


On Feb 8, 2006, at 7:39 PM, Brad King wrote:

> Mike Jackson wrote:
>> So if I turn on RPATH, and rpath uses -install_name, where do I   
>> actually specify the RPATH to use? or can I specify the path at all?
>
> Enabling VTK_USE_RPATH is intended for developers to be able to run  
> VTK programs from the build tree without installing or setting any  
> environment variables.  It always sets the install_name to point to  
> the full path to each library in the build tree.  This is why  
> installation is disabled.
>
> CMake does not currently support a user-configured rpath or  
> install_name.  If CMAKE_SKIP_RPATH is ON then no rpath is generated  
> and install_name is set to the name of the library.  If  
> CMAKE_SKIP_RPATH is OFF then rpath and install_name both point to  
> the build tree locations.
>
> CMake support for specifying an rpath/install-name is planned but  
> has not yet been implemented.
>
> If you intend to just distribute a binary for your application then  
> you can work around this limitation as follows.  First build VTK  
> with VTK_USE_RPATH set to ON.  Use a build tree with a really long  
> name. Then build your application against the VTK build tree.  Copy  
> the libraries to your application tree and use install_name_tool to  
> change the install_name.  There will easily be enough room  
> allocated because of the long build tree name.
>
> -Brad

I wrote a script that changes all the built vtkLibs to have a path  
that is usable inside an OS X App package. I will include it here in  
case someone else would find it useful

#! /bin/bash

###############################################################
# This script was designed to change the internal paths
# that are encoded into Mach-O dynamic libraries. The encoded
# path that is inserted into the dynamic libraries allows
# the VTK libs to be packaged into an OS X .app package instead
# of having to be installed into /usr/local/ or where ever else.
# This should allow you to distribute your application as a
# stand alone application and not need an installer, which
# usually requires admin privileges.
#
# When you build VTK, turn ON RPATH, and be sure that the path
# to the built sources is AT LEAST 28 characters long. This is
# due to a limitation of the "install_name_tool" program. A new
# path can only be ecoded if the new path is the SAME LENGTH or
# SHORTER than the original path that was encoded. See the man
# page for "install_name_tool" for a further explanation.
#
# If you are using Xcode build your Application as normal. In the
# "Targets" section of Xcode, add a new "Copy Files" build phase.
# Set the copy to the "Plugins" directory (this should be in a drop
# down menu in the "Copy Files" Get info window). Now drag you
# vtk libs onto this build phase to include them in the copy phase.
# Now when you build your application, the VTK libs will be copied
# from where ever they are into your Application package.
#
# This script takes 1 input parameter which is the absolute path
# to the built vtk binaries. This SHOULD be the same as the
# encoded path in the libraries. If you have any doubt use the
# "otool -L [library]" command to check.
#
# Lastly, if you have built static libraries, there is no need
# to use this script.
#
# This Original Code is distributed on an "AS IS" basis, WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND I HEREBY
# DISCLAIM ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
# OR NON-INFRINGEMENT.
###############################################################

newId="@executable_path/../Plugins/"
rootId="$1"

common="libvtkCommon.dylib"
dicom="libvtkDICOMParser.dylib"
filtering="libvtkFiltering.dylib"
genFilter="libvtkGenericFiltering.dylib"
graphics="libvtkGraphics.dylib"
hybrid="libvtkHybrid.dylib"
io="libvtkIO.dylib"
imaging="libvtkImaging.dylib"
mpeg2="libvtkMPEG2Encode.dylib"
netcdf="libvtkNetCDF.dylib"
rendering="libvtkRendering.dylib"
volume="libvtkVolumeRendering.dylib"
widgets="libvtkWidgets.dylib"
exoiic="libvtkexoIIc.dylib"
expat="libvtkexpat.dylib"
freetype="libvtkfreetype.dylib"
ftgl="libvtkftgl.dylib"
jpeg="libvtkjpeg.dylib"
png="libvtkpng.dylib"
sys="libvtksys.dylib"
tiff="libvtktiff.dylib"
zlib="libvtkzlib.dylib"

version=".5.0.0"
partial=".5.0"


# Change Common
install_name_tool -change \
${rootId}${sys}${partial} ${newId}${sys} \
-id ${newId}${common} \
"${rootId}${common}${version}"

#change DICOM
install_name_tool -id ${newId}${dicom} \
"${rootId}${dicom}${version}"

#change Filtering
install_name_tool \
-change \
${rootId}${sys}${partial} ${newId}${sys} \
-change \
${rootId}${common}${partial} ${newId}${common} \
-id ${newId}${filtering} \
"${rootId}${filtering}${version}"

#Change GenericFiltering
install_name_tool \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${graphics}${partial} ${newId}${graphics} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-id ${newId}${genFilter} "${rootId}${genFilter}${version}"

#change Graphics
install_name_tool \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-id ${newId}${graphics} "${rootId}${graphics}${version}"

#change hybrid
install_name_tool \
-change ${rootId}${rendering}${partial} ${newId}${rendering} \
-change ${rootId}${io}${partial} ${newId}${io} \
-change ${rootId}${exoiic}${partial} ${newId}${exoiic} \
-change ${rootId}${graphics}${partial} ${newId}${graphics} \
-change ${rootId}${imaging}${partial} ${newId}${imaging} \
-change ${rootId}${ftgl}${partial} ${newId}${ftgl} \
-change ${rootId}${freetype}${partial} ${newId}${freetype} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${dicom}${partial} ${newId}${dicom} \
-change ${rootId}${png}${partial} ${newId}${png} \
-change ${rootId}${tiff}${partial} ${newId}${tiff} \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-change ${rootId}${expat}${partial} ${newId}${expat} \
-change ${rootId}${mpeg2}${partial} ${newId}${mpeg2} \
-change ${rootId}${netcdf}${partial} ${newId}${netcdf} \
-id ${newId}${hybrid} "${rootId}${hybrid}${version}"

#Change IO
install_name_tool \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-change ${rootId}${dicom}${partial} ${newId}${dicom} \
-change ${rootId}${png}${partial} ${newId}${png} \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-change ${rootId}${tiff}${partial} ${newId}${tiff} \
-change ${rootId}${expat}${partial} ${newId}${expat} \
-change ${rootId}${mpeg2}${partial} ${newId}${mpeg2} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-id ${newId}${io} "${rootId}${io}${version}"

#change Imaging
install_name_tool \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-id ${newId}${imaging} "${rootId}${imaging}${version}"

#change MPEG2Encode
install_name_tool \
-id ${newId}${mpeg2} "${rootId}${mpeg2}${version}"

#change NetCDF
install_name_tool \
-id ${newId}${netcdf} "${rootId}${netcdf}${version}"

#change Rendering
install_name_tool \
-change ${rootId}${graphics}${partial} ${newId}${graphics} \
-change ${rootId}${imaging}${partial} ${newId}${imaging} \
-change ${rootId}${io}${partial} ${newId}${io} \
-change ${rootId}${ftgl}${partial} ${newId}${ftgl} \
-change ${rootId}${freetype}${partial} ${newId}${freetype} \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-change ${rootId}${dicom}${partial} ${newId}${dicom} \
-change ${rootId}${png}${partial} ${newId}${png} \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-change ${rootId}${tiff}${partial} ${newId}${tiff} \
-change ${rootId}${expat}${partial} ${newId}${expat} \
-change ${rootId}${mpeg2}${partial} ${newId}${mpeg2} \
-id ${newId}${rendering} "${rootId}${rendering}${version}"

#change VolumeRendering
install_name_tool \
-change ${rootId}${rendering}${partial} ${newId}${rendering} \
-change ${rootId}${io}${partial} ${newId}${io} \
-change ${rootId}${graphics}${partial} ${newId}${graphics} \
-change ${rootId}${imaging}${partial} ${newId}${imaging} \
-change ${rootId}${ftgl}${partial} ${newId}${ftgl} \
-change ${rootId}${freetype}${partial} ${newId}${freetype} \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-change ${rootId}${dicom}${partial} ${newId}${dicom} \
-change ${rootId}${png}${partial} ${newId}${png} \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-change ${rootId}${tiff}${partial} ${newId}${tiff} \
-change ${rootId}${expat}${partial} ${newId}${expat} \
-change ${rootId}${mpeg2}${partial} ${newId}${mpeg2} \
-id ${newId}${volume} "${rootId}${volume}${version}"

#change widgets
install_name_tool \
-change ${rootId}${rendering}${partial} ${newId}${rendering} \
-change ${rootId}${hybrid}${partial} ${newId}${hybrid} \
-change ${rootId}${graphics}${partial} ${newId}${graphics} \
-change ${rootId}${imaging}${partial} ${newId}${imaging} \
-change ${rootId}${ftgl}${partial} ${newId}${ftgl} \
-change ${rootId}${freetype}${partial} ${newId}${freetype} \
-change ${rootId}${io}${partial} ${newId}${io} \
-change ${rootId}${sys}${partial} ${newId}${sys} \
-change ${rootId}${common}${partial} ${newId}${common} \
-change ${rootId}${filtering}${partial} ${newId}${filtering} \
-change ${rootId}${dicom}${partial} ${newId}${dicom} \
-change ${rootId}${png}${partial} ${newId}${png} \
-change ${rootId}${tiff}${partial} ${newId}${tiff} \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-change ${rootId}${expat}${partial} ${newId}${expat} \
-change ${rootId}${mpeg2}${partial} ${newId}${mpeg2} \
-change ${rootId}${exoiic}${partial} ${newId}${exoiic} \
-change ${rootId}${netcdf}${partial} ${newId}${netcdf} \
-id ${newId}${widgets} "${rootId}${widgets}${version}"


#change exoiic
install_name_tool \
-change ${rootId}${netcdf}${partial} ${newId}${netcdf} \
-id ${newId}${exoiic} "${rootId}${exoiic}${version}"

#change expat
install_name_tool \
-id ${newId}${expat} "${rootId}${expat}${version}"

#change freetype
install_name_tool \
-id ${newId}${freetype} "${rootId}${freetype}${version}"

#change ftgl
install_name_tool \
-change ${rootId}${freetype}${partial} ${newId}${freetype} \
-id ${newId}${ftgl} "${rootId}${ftgl}${version}"

#change jpeg
install_name_tool \
-id ${newId}${jpeg} "${rootId}${jpeg}${version}"

#change png
install_name_tool \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-id ${newId}${png} "${rootId}${png}${version}"

#change sys
install_name_tool \
-id ${newId}${sys} "${rootId}${sys}${version}"

#change tiff
install_name_tool \
-change ${rootId}${zlib}${partial} ${newId}${zlib} \
-change ${rootId}${jpeg}${partial} ${newId}${jpeg} \
-id ${newId}${tiff} "${rootId}${tiff}${version}"

#change zlib
install_name_tool \
-id ${newId}${zlib} "${rootId}${zlib}${version}"


#remove the symlinks
rm "${rootId}${common}${partial}"
rm "${rootId}${dicom}${partial}"
rm "${rootId}${filtering}${partial}"
rm "${rootId}${genFilter}${partial}"
rm "${rootId}${graphics}${partial}"
rm "${rootId}${hybrid}${partial}"
rm "${rootId}${io}${partial}"
rm "${rootId}${imaging}${partial}"
rm "${rootId}${mpeg2}${partial}"
rm "${rootId}${netcdf}${partial}"
rm "${rootId}${rendering}${partial}"
rm "${rootId}${volume}${partial}"
rm "${rootId}${widgets}${partial}"
rm "${rootId}${exoiic}${partial}"
rm "${rootId}${expat}${partial}"
rm "${rootId}${freetype}${partial}"
rm "${rootId}${ftgl}${partial}"
rm "${rootId}${jpeg}${partial}"
rm "${rootId}${png}${partial}"
rm "${rootId}${sys}${partial}"
rm "${rootId}${tiff}${partial}"
rm "${rootId}${zlib}${partial}"

#remove the symlinks
rm "${rootId}${common}"
rm "${rootId}${dicom}"
rm "${rootId}${filtering}"
rm "${rootId}${genFilter}"
rm "${rootId}${graphics}"
rm "${rootId}${hybrid}"
rm "${rootId}${io}"
rm "${rootId}${imaging}"
rm "${rootId}${mpeg2}"
rm "${rootId}${netcdf}"
rm "${rootId}${rendering}"
rm "${rootId}${volume}"
rm "${rootId}${widgets}"
rm "${rootId}${exoiic}"
rm "${rootId}${expat}"
rm "${rootId}${freetype}"
rm "${rootId}${ftgl}"
rm "${rootId}${jpeg}"
rm "${rootId}${png}"
rm "${rootId}${sys}"
rm "${rootId}${tiff}"
rm "${rootId}${zlib}"

#Now change all the library names to match what we just encoded
mv "${rootId}${common}${version}" "${rootId}${common}"
mv "${rootId}${dicom}${version}" "${rootId}${dicom}"
mv "${rootId}${filtering}${version}" "${rootId}${filtering}"
mv "${rootId}${genFilter}${version}" "${rootId}${genFilter}"
mv "${rootId}${graphics}${version}" "${rootId}${graphics}"
mv "${rootId}${hybrid}${version}" "${rootId}${hybrid}"
mv "${rootId}${io}${version}" "${rootId}${io}"
mv "${rootId}${imaging}${version}" "${rootId}${imaging}"
mv "${rootId}${mpeg2}${version}" "${rootId}${mpeg2}"
mv "${rootId}${netcdf}${version}" "${rootId}${netcdf}"
mv "${rootId}${rendering}${version}" "${rootId}${rendering}"
mv "${rootId}${volume}${version}" "${rootId}${volume}"
mv "${rootId}${widgets}${version}" "${rootId}${widgets}"
mv "${rootId}${exoiic}${version}" "${rootId}${exoiic}"
mv "${rootId}${expat}${version}" "${rootId}${expat}"
mv "${rootId}${freetype}${version}" "${rootId}${freetype}"
mv "${rootId}${ftgl}${version}" "${rootId}${ftgl}"
mv "${rootId}${jpeg}${version}" "${rootId}${jpeg}"
mv "${rootId}${png}${version}" "${rootId}${png}"
mv "${rootId}${sys}${version}" "${rootId}${sys}"
mv "${rootId}${tiff}${version}" "${rootId}${tiff}"
mv "${rootId}${zlib}${version}" "${rootId}${zlib}"

# --- END OF SCRIPT ------

--------
Mike Jackson
imikejackson <at> gmail <dot> com





More information about the CMake mailing list