From d60787bdb268e2bb1e3c21422457b2d1888f39f0 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Thu, 4 Aug 2022 00:41:37 -0700 Subject: [PATCH] SWDEV-349826 - Use get_filename_component rather than using file command to get realpath The cmake file command with REAL_PATH option is supported from cmake version 3.19 onwards Issue reported in cmake version 3.17. get_filename_component is supported since 3.4 onwards The command gives REALPATH with symlinks resolved - /opt/rocm-ver/lib/cmake/hip/hip-config.cmake So need to move four level up to get ROCM PATH Verfied by printing the variables Change made so that default initializaton of ROCM PATH is executed if there is no ROCM_PATH set in ENV Change-Id: Ibfff584eeb154bd73a568a842f28143d5ed72458 --- hipamd/hip-config.cmake.in | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hipamd/hip-config.cmake.in b/hipamd/hip-config.cmake.in index eb7c0c4b94..89d1224ea4 100755 --- a/hipamd/hip-config.cmake.in +++ b/hipamd/hip-config.cmake.in @@ -112,21 +112,25 @@ if(WIN32) set(HIP_PATH ${PACKAGE_PREFIX_DIR}) endif() else() - # Linux - set a default path for ROCM_PATH + # Linux + # If HIP is not installed under ROCm, need this to find HSA assuming HSA is under ROCm + if(DEFINED ENV{ROCM_PATH}) + set(ROCM_PATH "$ENV{ROCM_PATH}") + endif() + + # set a default path for ROCM_PATH if(NOT DEFINED ROCM_PATH) # TODO:once file reorg backward compatibility is turned off, # ROCM_PATH can be set to PACKAGE_PREFIX_DIR. # Time being find the ROCM_PATH based on hip-config file - # Following will provide the path with filename with symlinks resolved. - # Move four level up to get rocm path - file(REAL_PATH ${CMAKE_CURRENT_LIST_FILE} CONFIG_PATH) + # Get the ROCM PATH in 2 steps as get_filename_component appears to process /../ textually + # first find the real path to hip-config file which doesn't have symbolic links + # Real Path : /opt/rocm-ver/lib/cmake/hip/hip-config.cmake + # then go up 4 levels get to /opt/rocm-ver + get_filename_component(CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" REALPATH) get_filename_component(ROCM_PATH "${CONFIG_PATH}/../../../../" ABSOLUTE) endif() - #If HIP is not installed under ROCm, need this to find HSA assuming HSA is under ROCm - if(DEFINED ENV{ROCM_PATH}) - set(ROCM_PATH "$ENV{ROCM_PATH}") - endif() endif() if(HIP_COMPILER STREQUAL "clang")