diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 93d130a0b5..f37d7dba72 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -95,9 +95,9 @@ function(mayaUsd_init_rpath rpathRef origin) set(origin "${CMAKE_INSTALL_PREFIX}/${origin}") endif() endif() - # mayaUsd_add_rpath uses REALPATH, so we must make sure we always + # mayaUsd_add_rpath uses DIRECTORY, so we must make sure we always # do so here too, to get the right relative path - get_filename_component(origin "${origin}" REALPATH) + get_filename_component(origin "${origin}" DIRECTORY) set(${rpathRef} "${origin}" PARENT_SCOPE) endfunction() @@ -105,10 +105,9 @@ endfunction() # and add a relative path from the origin to the target. function(mayaUsd_add_rpath rpathRef target) if(IS_ABSOLUTE "${target}") - # init_rpath calls get_filename_component([...] REALPATH), which does - # symlink resolution, so we must do the same, otherwise relative path + # init_rpath calls get_filename_component([...] DIRECTORY), so we must do the same, otherwise relative path # determination below will fail. - get_filename_component(target "${target}" REALPATH) + get_filename_component(target "${target}" DIRECTORY) # Make target relative to $ORIGIN (which is the first element in # rpath when initialized with mayaUsd_init_rpath()). list(GET ${rpathRef} 0 origin) @@ -160,90 +159,6 @@ function(mayaUsd_install_rpath rpathRef NAME) ) endfunction() -# Initialize a variable to accumulate an rpath. The origin is the -# RUNTIME DESTINATION of the target. If not absolute it's appended -# to CMAKE_INSTALL_PREFIX. -function(mayaUsd_init_rpath2 rpathRef origin) - message(STATUS "mayaUsd_init_rpath2: path 1 : ${origin}") - if(NOT IS_ABSOLUTE ${origin}) - if(DEFINED INSTALL_DIR_SUFFIX) - set(origin "${CMAKE_INSTALL_PREFIX}/${INSTALL_DIR_SUFFIX}/${origin}") - message(STATUS "mayaUsd_init_rpath2: path 2-1 : ${origin}") - else() - set(origin "${CMAKE_INSTALL_PREFIX}/${origin}") - message(STATUS "mayaUsd_init_rpath2: path 2-2 : ${origin}") - endif() - endif() - # mayaUsd_add_rpath uses REALPATH, so we must make sure we always - # do so here too, to get the right relative path - get_filename_component(origin "${origin}" REALPATH) - message(STATUS "mayaUsd_init_rpath2: path 3 : ${origin}") - set(${rpathRef} "${origin}" PARENT_SCOPE) -endfunction() - -# Add a relative target path to the rpath. If target is absolute compute -# and add a relative path from the origin to the target. -function(mayaUsd_add_rpath2 rpathRef target) - if(IS_ABSOLUTE "${target}") - # init_rpath calls get_filename_component([...] REALPATH), which does - # symlink resolution, so we must do the same, otherwise relative path - # determination below will fail. - message(STATUS "mayaUsd_add_rpath2: path 1 : ${target}") - get_filename_component(target "${target}" REALPATH) - message(STATUS "mayaUsd_add_rpath2: path 2 : ${target}") - # Make target relative to $ORIGIN (which is the first element in - # rpath when initialized with mayaUsd_init_rpath()). - list(GET ${rpathRef} 0 origin) - message(STATUS "mayaUsd_add_rpath2: path 3 : ${origin}") - file(RELATIVE_PATH - target - "${origin}" - "${target}" - ) - message(STATUS "mayaUsd_add_rpath2: path 4: ${target}") - if("x${target}" STREQUAL "x") - set(target ".") - endif() - endif() - file(TO_CMAKE_PATH "${target}" target) - message(STATUS "mayaUsd_add_rpath2: path 5: ${target}") - set(NEW_RPATH "${${rpathRef}}") - list(APPEND NEW_RPATH "$ORIGIN/${target}") - message(STATUS "mayaUsd_add_rpath2: path 6: $ORIGIN/${target}") - set(${rpathRef} "${NEW_RPATH}" PARENT_SCOPE) -endfunction() - -function(mayaUsd_install_rpath2 rpathRef NAME) - # Get and remove the origin. - list(GET ${rpathRef} 0 origin) - set(RPATH ${${rpathRef}}) - list(REMOVE_AT RPATH 0) - # Canonicalize and uniquify paths. - set(FINAL "") - foreach(path ${RPATH}) - # Replace $ORIGIN with @loader_path - if(IS_MACOSX) - if("${path}/" MATCHES "^[$]ORIGIN/") - # Replace with origin path. - message(STATUS "mayaUsd_install_rpath2: before replace: ${path}") - string(REPLACE "$ORIGIN/" "@loader_path/" path "${path}/") - message(STATUS "mayaUsd_install_rpath2: after replace: ${path}") - endif() - endif() - # Strip trailing slashes. - string(REGEX REPLACE "/+$" "" path "${path}") - # Ignore paths we already have. - if (NOT ";${FINAL};" MATCHES ";${path};") - list(APPEND FINAL "${path}") - endif() - endforeach() - set_target_properties(${NAME} - PROPERTIES - INSTALL_RPATH_USE_LINK_PATH TRUE - INSTALL_RPATH "${FINAL}" - ) -endfunction() - # # mayaUsd_promoteHeaderList( # [SUBDIR ] diff --git a/lib/mayaHydra/mayaPlugin/CMakeLists.txt b/lib/mayaHydra/mayaPlugin/CMakeLists.txt index 6914298f9b..67a83d0bdd 100644 --- a/lib/mayaHydra/mayaPlugin/CMakeLists.txt +++ b/lib/mayaHydra/mayaPlugin/CMakeLists.txt @@ -84,13 +84,7 @@ maya_set_plugin_properties(${TARGET_NAME}) # run-time search paths # ----------------------------------------------------------------------------- if(IS_MACOSX OR IS_LINUX) - mayaUsd_init_rpath2(rpath "lib/maya") - if(MayaUsd_FOUND) - #When MayaUsd_FOUND is true, MAYAUSDAPI_LIBRARY exists as it is required. - #MAYAUSDAPI_LIBRARY is the full path name of the maya USD API shared library, so get only its directory into MAYAUSDAPI_LIBRARY_PATH - get_filename_component(MAYAUSDAPI_LIBRARY_PATH "${MAYAUSDAPI_LIBRARY}" DIRECTORY) - mayaUsd_add_rpath2(rpath "${MAYAUSDAPI_LIBRARY_PATH}") - endif() + mayaUsd_init_rpath(rpath "lib/maya") if(DEFINED MAYAHYDRA_TO_USD_RELATIVE_PATH) mayaUsd_add_rpath(rpath "../../${MAYAHYDRA_TO_USD_RELATIVE_PATH}/lib") elseif(DEFINED PXR_USD_LOCATION) @@ -102,8 +96,14 @@ if(IS_MACOSX OR IS_LINUX) if(IS_MACOSX AND DEFINED MAYAHYDRA_TO_USD_RELATIVE_PATH) mayaUsd_add_rpath(rpath "../../../../Maya.app/Contents/MacOS") endif() + if(MayaUsd_FOUND) + #When MayaUsd_FOUND is true, MAYAUSDAPI_LIBRARY exists as it is required. + #MAYAUSDAPI_LIBRARY is the full path name of the maya USD API shared library, so get only its directory into MAYAUSDAPI_LIBRARY_PATH + get_filename_component(MAYAUSDAPI_LIBRARY_PATH "${MAYAUSDAPI_LIBRARY}" DIRECTORY) + mayaUsd_add_rpath(rpath "${MAYAUSDAPI_LIBRARY_PATH}") + endif() mayaUsd_add_rpath(rpath "../") - mayaUsd_install_rpath2(rpath ${TARGET_NAME}) + mayaUsd_install_rpath(rpath ${TARGET_NAME}) endif() # -----------------------------------------------------------------------------