Skip to content

Commit

Permalink
Compute rpaths instead of using hard-coded paths
Browse files Browse the repository at this point in the history
The build system should now compute appropriate
rpaths for libraries and plugins rather than using
hard-coded rpaths that assumed a certain directory
structure. This fixes rpath issues with the example
plugins and also makes the build system more
flexible.

(Internal change: 1685517)
  • Loading branch information
sunyab authored and pixar-oss committed Dec 2, 2016
1 parent 29a3ce6 commit 899d4f3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
9 changes: 9 additions & 0 deletions cmake/macros/Private.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,12 @@ macro(_get_share_install_dir RESULT)
_get_install_dir(share/usd ${RESULT})
endmacro() # _get_share_install_dir

function(_append_to_rpath orig_rpath new_rpath output)
# Strip trailing '/' path separators, then append to orig_rpath
# if new_rpath doesn't already exist.
string(REGEX REPLACE "/+$" "" new_rpath ${new_rpath})
string(FIND ${orig_rpath} ${new_rpath} rpath_exists)
if (rpath_exists EQUAL -1)
set(${output} "${orig_rpath}:${new_rpath}" PARENT_SCOPE)
endif()
endfunction() # _add_to_rpath
54 changes: 38 additions & 16 deletions cmake/macros/Public.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ endfunction()

function(pxr_shared_library LIBRARY_NAME)
set(options PYTHON_LIBRARY)
set(oneValueArgs
PYTHON_WRAPPED_LIB_PREFIX
)
set(multiValueArgs
PUBLIC_CLASSES
PUBLIC_HEADERS
Expand All @@ -114,7 +117,7 @@ function(pxr_shared_library LIBRARY_NAME)

cmake_parse_arguments(sl
"${options}"
""
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
Expand Down Expand Up @@ -165,13 +168,16 @@ function(pxr_shared_library LIBRARY_NAME)
APPEND PROPERTY PXR_PYTHON_MODULES ${pyModuleName}
)

# Python modules for third_party libs are installed into the root
# pxr/lib/python but need to be able to access their corresponding
# library which lives in third_party/${pkg}/lib
set(rpath ${CMAKE_INSTALL_RPATH})
if (PXR_INSTALL_SUBDIR)
set(rpath "$ORIGIN/../../../../${PXR_INSTALL_SUBDIR}/lib:${rpath}")
endif()

# Python modules need to be able to access their corresponding
# wrapped library, so compute a relative path and append that to
# the module's rpath.
file(RELATIVE_PATH
PYTHON_RPATH
"${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_PREFIX}"
"${CMAKE_INSTALL_PREFIX}/${sl_PYTHON_WRAPPED_LIB_PREFIX}")
_append_to_rpath(${rpath} "$ORIGIN/${PYTHON_RPATH}" rpath)

This comment has been minimized.

Copy link
@meshula

meshula Dec 7, 2016

Member

Hi there, this breaks the Mac run time. For whatever reason, the previous version worked, but the current one doesn't. In any case, $ORIGIN is a Linux specific thing, that should be guarded on non Linux platforms.


# Python modules must be suffixed with .pyd on Windows and .so on
# other platforms.
Expand Down Expand Up @@ -311,6 +317,7 @@ function(pxr_shared_library LIBRARY_NAME)
pxr_shared_library(
"_${LIBRARY_NAME}"
PYTHON_LIBRARY
PYTHON_WRAPPED_LIB_PREFIX ${LIB_INSTALL_PREFIX}
CPPFILES ${sl_PYMODULE_CPPFILES}
LIBRARIES ${LIBRARY_NAME}
)
Expand Down Expand Up @@ -540,17 +547,31 @@ function(pxr_plugin PLUGIN_NAME)
INSTALL_RPATH ${rpath}
)
else()
# Ensure this plugin can find the libs for its matching component, e.g.
# maya/plugin/px_usdIO.so can find maya/lib/*.so
# Ensure this plugin can find the libs for its matching component.
# Compute the relative path from where the plugin is installed
# to the corresponding lib directories and append that to the
# plugin's rpath.
set(rpath ${CMAKE_INSTALL_RPATH})

# If an install subdirectory is specified (e.g., for third party
# packages), add an rpath pointing to lib/ within it.
if (PXR_INSTALL_SUBDIR)
set_target_properties(${PLUGIN_NAME}
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN/../lib"
)
else()
set_target_properties(${PLUGIN_NAME}
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN/../../lib"
)
file(RELATIVE_PATH
PLUGIN_RPATH
"${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_PREFIX}"
"${CMAKE_INSTALL_PREFIX}/${PXR_INSTALL_SUBDIR}/lib")
_append_to_rpath(${rpath} "$ORIGIN/${PLUGIN_RPATH}" rpath)

This comment has been minimized.

Copy link
@meshula

meshula Dec 7, 2016

Member

see notes about non-portability of $ORIGIN

endif()

# Add an rpath pointing to the top-level lib/ directory.
file(RELATIVE_PATH
PLUGIN_RPATH
"${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_PREFIX}"
"${CMAKE_INSTALL_PREFIX}/lib")
_append_to_rpath(${rpath} "$ORIGIN/${PLUGIN_RPATH}" rpath)

This comment has been minimized.

Copy link
@meshula

meshula Dec 7, 2016

Member

see notes about non-portability of $ORIGIN


set_target_properties(${PLUGIN_NAME}
PROPERTIES INSTALL_RPATH "${rpath}")
endif()

set_target_properties(${PLUGIN_NAME}
Expand Down Expand Up @@ -661,6 +682,7 @@ function(pxr_plugin PLUGIN_NAME)
pxr_shared_library(
"_${PLUGIN_NAME}"
PYTHON_LIBRARY
PYTHON_WRAPPED_LIB_PREFIX ${PLUGIN_INSTALL_PREFIX}
CPPFILES ${sl_PYMODULE_CPPFILES}
LIBRARIES ${PLUGIN_NAME}
)
Expand Down

0 comments on commit 899d4f3

Please sign in to comment.