[CMake] INSTALL_NAME_DIR on MacOSX

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Oct 24 14:57:02 EDT 2007


On 2007-10-24 12:16-0600 James Bigler wrote:

> So, I had a dynamic library with the following:
>
> SET_TARGET_PROPERTIES(narfencode
>  PROPERTIES BUILD_WITH_INSTALL_RPATH OFF
>  INSTALL_NAME_DIR "@executable_path"
>  )
>
> When I compile it I get this:
>
> /usr/bin/c++    -dynamiclib -headerpad_max_install_names  -o 
> libnarfencode.dylib -install_name /Users/bigler/cibc/cpack_install/ 
> opt/libnarfencode.dylib "CMakeFiles/narfencode.dir/encode.o"
>
> Note that the -install_name is the local build directory.  This works well 
> for when I run the binary out of the build directory, but if I run "make 
> install" it doesn't relink the library with the *installed* -install_name.
>
> I believe it should be relinking the library during installation to match 
> where it will be after it's installed.
>
> Note that if I set it to ON, it works for the installed version (and may not 
> work for the build tree version).

Here is what works for us:

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   # No rpath on Darwin. Setting it will only cause trouble.
else(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   option(USE_RPATH "Use -rpath when linking libraries, executables" ON)
endif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")

if(USE_RPATH)
   set_target_properties(
   plplot${LIB_TAG}
   PROPERTIES
   SOVERSION ${plplot_SOVERSION}
   VERSION ${plplot_VERSION}
   INSTALL_RPATH "${LIB_INSTALL_RPATH}"
   INSTALL_NAME_DIR "${LIB_DIR}"
   )
else(USE_RPATH)
   set_target_properties(
   plplot${LIB_TAG}
   PROPERTIES
   SOVERSION ${plplot_SOVERSION}
   VERSION ${plplot_VERSION}
   INSTALL_NAME_DIR "${LIB_DIR}"
   )
endif(USE_RPATH)

For completeness I left in the SOVERSION and VERSION properties we set for
the PLplot principal library, but the only difference between the two
alternatives is INSTALL_RPATH "${LIB_INSTALL_RPATH}"

I only have access to Linux, and the above works great there both for the
build tree (where CMake does all the required rpath stuff automatically so
that build-tree tests work without having to set LD_LIBRARY_PATH).  For
Linux, the above also works great for the install tree where rpath is set
appropriately unless the user specifically wants to turn it off with
-DUSE_RPATH=OFF.  (This no-rpath option for the install tree is useful for
the case of a system install location where rpath is not necessary, and
normally not desired as well).

I hear from PLplot OS X users that the above CMake logic also works well on
that platform both for the build tree (where I assume CMake automatically
does not use rpath for the Darwin case) and install tree (where because
of the above logic CMake does not use rpath for the Darwin case).

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list