@@ -89,14 +89,17 @@ from the internet, we turn this option OFF." ON)
8989set (SIMBODY_HOME $ENV{SIMBODY_HOME} CACHE
9090 PATH "The location of the Simbody installation to use; you can change this. Set as empty to let CMake search for Simbody automatically." )
9191
92+ # TODO rename to OPENSIM_COPY_DEPENDENCIES and handle BTK.
9293option (OPENSIM_COPY_SIMBODY "Copy Simbody headers and libraries into the
9394OpenSim installation. This way, you can treat OpenSim and Simbody as one
9495package, and you only need to set environment variables (e.g., PATH,
9596LD_LIBRARY_PATH, DYLD_LIBRARY_PATH) for OpenSim. On Windows, this also copies
9697Simbody dll's and exe's into the OpenSim build directory, so that you don't
9798need to set PATH to run OpenSim tests and examples; this is done via the
9899SimbodyFiles project. If OFF, you likely must set those environment variables
99- for both OpenSim and Simbody." ON )
100+ for both OpenSim and Simbody. To make a distributable installation on macOS,
101+ this should be set to ON to avoid using absolute paths for RPATHs to Simbody
102+ libraries." ON )
100103
101104option (BUILD_API_ONLY "Build/install only headers, libraries,
102105wrapping, tests; not applications (opensim, ik, rra, etc.)." OFF )
@@ -457,39 +460,40 @@ if(${CMAKE_C_COMPILER} MATCHES "cc" OR ${CMAKE_C_COMPILER} MATCHES "clang")
457460endif ()
458461
459462
460- ## On APPLE, use MACOSX_RPATH.
461- ## On Linux, this variable has no effect.
462- set (OPENSIM_USE_INSTALL_RPATH FALSE )
463+ ## RPATH
464+ # If it is necesasry to not put RPATHS in the installed binaries, set
465+ # set CMAKE_SKIP_INSTALL_RPATH to OFF.
463466if (APPLE )
464- option (OPENSIM_NO_LIBRARY_PATH_ENV_VAR
465- "If ON, you don't need to set
466- DYLD_LIBRARY_PATH (on OSX) to make use of OpenSim's executables.
467- Instead, we bake the location of OpenSim's libraries into the
468- executables, so the executables already know where to find the
469- libraries. This uses the RPATH mechanism." ON )
470- if (${OPENSIM_NO_LIBRARY_PATH_ENV_VAR} )
471- # CMake 2.8.12 introduced the ability to set RPATH for shared libraries on
472- # OSX. This helps executables find the libraries they depend on without
473- # having to set the DYLD_LIBRARY_PATH environment variable.
474- # The code below is all taken from the link below, and implements the
475- # scenario "Always use full RPATH".
476- # http://www.cmake.org/Wiki/CMake_RPATH_handling
477- # Note: the RPATH won't succeed if the libraries are moved; in this case,
478- # one will still need to set DYLD_LIBRARY_PATH (or alter the RPATH in the
479- # executables/libraries that depend on Simbody's libraries).
480- set (CMAKE_MACOSX_RPATH ON )
481-
482- # Add the automatically determined parts of the RPATH
483- # which point to directories outside the build tree to the install RPATH.
467+ # CMake 2.8.12 introduced the ability to set RPATH for shared libraries
468+ # on OSX. This helps executables find the libraries they depend on
469+ # without having to set the DYLD_LIBRARY_PATH environment variable.
470+ # See http://www.cmake.org/Wiki/CMake_RPATH_handling and `man dydl`.
471+ # We have attempted to make the RPATH work even if the
472+ # installation is relocated (using relative paths), but you may need to
473+ # use DYLD_LIBRARY_PATH (or alter the RPATH using install_name_tool) in
474+ # these cases.
475+ ## On Linux, this variable has no effect.
476+ set (CMAKE_MACOSX_RPATH ON )
477+
478+ if (NOT OPENSIM_COPY_SIMBODY)
479+ # Add the automatically determined parts of the RPATH which point
480+ # to directories outside the build tree to the install RPATH.
481+ # If we are copying Simbody into OpenSim's installation, then
482+ # there's no need to link to the libraries in Simbody's original
483+ # installation. Furthermore, we may be distributing OpenSim to
484+ # other computers that will not have our original Simbody
485+ # installation, and so the RPATH would point to a nonexistant
486+ # directory on others' computers.
487+ # TODO handle copying BTK.
484488 set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
489+ endif ()
485490
486- # The RPATH to be used when installing, but only if it's not a system
487- # directory.
488- list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
489- "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} " isSystemDir)
490- if ("${isSystemDir} " STREQUAL "-1" )
491- set (OPENSIM_USE_INSTALL_RPATH TRUE )
492- endif ()
491+ # Set RPATH so that OpenSim can find its own libraries, but only if
492+ # OpenSim is not installed into a system library directory.
493+ list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
494+ "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} " isSystemDir)
495+ if ("${isSystemDir} " STREQUAL "-1" )
496+ set (OPENSIM_USE_INSTALL_RPATH TRUE )
493497 endif ()
494498endif ()
495499## Add rpath to the binaries on Linux.
@@ -522,6 +526,7 @@ if(WITH_BTK)
522526 include (${BTK_USE_FILE} )
523527 add_definitions (-DWITH_BTK)
524528 CopyDependencyDLLsForWin(BTK ${BTK_INSTALL_PREFIX} )
529+ # TODO this should be handled separately between macOS and Linux.
525530 set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH} ;${BTK_LIBRARY_DIRS} " )
526531endif ()
527532
@@ -606,6 +611,7 @@ include_directories("${Simbody_INCLUDE_DIR}")
606611# Copy files over from the Simbody installation.
607612# ----------------------------------------------
608613if (${OPENSIM_COPY_SIMBODY} )
614+ # TODO copy BTK as well.
609615
610616 # Install Simbody headers into OpenSim installation.
611617 install (DIRECTORY "${Simbody_INCLUDE_DIR} /"
0 commit comments