[CMake] cmake variables to control full path in shared lib on OSX

Darren Weber darren.weber.lists at gmail.com
Thu Sep 18 20:03:46 EDT 2008


I'm exploring how to build and install VTK-5-2-0 on OSX.  I'm trying
to use shared libraries, but the default settings do not put full
paths in the .dylib file links for the libvtk* libraries.  I am using
a non-standard install path (macports /opt/local), so I may need to
set full paths for the libvtk* links.  For example, this is just one
of the dylib files and I may need all the links to libvtk* to contain
the full path (/opt/local/lib/vtk-5.2/):

[ dweber at elegans ~/src/kitware/VTK_build ]$ otool -L
/opt/local/lib/vtk-5.2/libvtkViewsTCL.5.2.0.dylib
/opt/local/lib/vtk-5.2/libvtkViewsTCL.5.2.0.dylib:
	libvtkViewsTCL.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
<snip, block of libvtk*>
	libvtkzlib.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 111.1.1)
	/opt/local/lib/libhistory.5.2.dylib (compatibility version 5.0.0,
current version 5.2.0)
	/opt/local/lib/libreadline.5.2.dylib (compatibility version 5.0.0,
current version 5.2.0)
	libvtkGraphicsTCL.5.2.dylib (compatibility version 0.0.0, current
version 0.0.0)
<snip, block of libvtk*>
	libvtkCommon.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
	/System/Library/Frameworks/Tcl.framework/Versions/8.4/Tcl
(compatibility version 8.4.0, current version 8.4.0)
	libvtkfreetype.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
	/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
(compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
(compatibility version 1.0.0, current version 12.0.0)
	libvtkexoIIc.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
<snip, block of libvtk*>
	libvtksys.5.2.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
[ dweber at elegans ~/src/kitware/VTK_build ]$


What are the right cmake variables that will enable full paths in the
shared libraries?

Potential candidates:

CMAKE_INSTALL_NAME_DIR  (eg: /opt/local/lib/vtk-5.2 ?)
CMAKE_SKIP_BUILD_RPATH (FALSE?)
CMAKE_SKIP_RPATH (FALSE?)

CMAKE_INSTALL_RPATH   (eg: /opt/local/lib/vtk-5.2 ?)
CMAKE_INSTALL_RPATH_USE_LINK_PATH  (TRUE?)

CMAKE_BUILD_WITH_INSTALL_RPATH (True?)


When I configured the build with just a switch to turn on shared libs,
then checked CMakeCache.txt, I can't see that any of these were set,
ie:

[ dweber at elegans ~/src/kitware/VTK_build ]$ cat CMakeCache.txt | grep RPATH
VTK_USE_RPATH:BOOL=OFF
//Advanced flag for variable: CMAKE_SKIP_RPATH
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
CMAKE_SKIP_RPATH:INTERNAL=1
//Advanced flag for variable: VTK_USE_RPATH
VTK_USE_RPATH-ADVANCED:INTERNAL=1


I then set VTK_USE_RPATH=ON and built again.  This time I got the
wrong paths because I had set CMAKE_INSTALL_NAME_DIR="/opt/local/lib/"

[ dweber at elegans ~/src/kitware/VTK_build ]$ otool -L
/opt/local/lib/vtk-5.2/libvtkInfovisTCL.5.2.0.dylib
/opt/local/lib/vtk-5.2/libvtkInfovisTCL.5.2.0.dylib:
	/opt/local/lib/libvtkInfovisTCL.5.2.dylib (compatibility version
0.0.0, current version 0.0.0)
	/opt/local/lib/libvtkInfovis.5.2.dylib (compatibility version 0.0.0,
current version 0.0.0)
etc.

So I changed CMAKE_INSTALL_NAME_DIR="${prefix}/lib/vtk-5.2" and it
seems right now:

[ dweber at elegans ~/src/kitware/VTK_build ]$ otool -L
/opt/local/lib/vtk-5.2/libvtkInfovisTCL.5.2.0.dylib
/opt/local/lib/vtk-5.2/libvtkInfovisTCL.5.2.0.dylib:
	/opt/local/lib/vtk-5.2/libvtkInfovisTCL.5.2.dylib (compatibility
version 0.0.0, current version 0.0.0)
	/opt/local/lib/vtk-5.2/libvtkInfovis.5.2.dylib (compatibility version
0.0.0, current version 0.0.0)
	/opt/local/lib/vtk-5.2/libvtkWidgetsTCL.5.2.dylib (compatibility
version 0.0.0, current version 0.0.0)
etc.


Are there any major problems with using this installation approach for
the vtk 5.2 library in the macports path?

As a noob to RPATH, I found these links informative:
http://en.wikipedia.org/wiki/Rpath_(linking)
http://wiki.debian.org/RpathIssue
http://www.the-martins.org/index.php?name=Sections&req=viewarticle&artid=6&allpages=1


Thanks, Darren


More information about the CMake mailing list