Skip to content

Commit

Permalink
try not using real path
Browse files Browse the repository at this point in the history
  • Loading branch information
lilike-adsk committed Feb 23, 2024
1 parent 814ed82 commit 62cb482
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 97 deletions.
93 changes: 4 additions & 89 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,19 @@ 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()

# 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_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)
Expand Down Expand Up @@ -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 <sub-directory name>]
Expand Down
16 changes: 8 additions & 8 deletions lib/mayaHydra/mayaPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 62cb482

Please sign in to comment.