SWDEV-335902 - Fix HIP when Git info unavailable

Prior to this change, when Git_FOUND was false, HIP_VERSION_BUILD_ID
would be undefined in the CMake code. The value of HIP_VERSION_BUILD_ID
in <hip/hip_version.h> is taken from the CMake variable, so it was being
defined as nothing in those cases. That would cause compilation failures,
as src/hip_global.cpp contains the function:

    size_t amd_dbgapi_get_build_id() {
      return HIP_VERSION_BUILD_ID;
    }

which would become

    size_t amd_dbgapi_get_build_id() {
      return ;
    }

after preprocessing. To prevent this, we can define the version
information to a default value when Git is not found.

A related problem was reported by Harmen Stoppels in
https://github.com/ROCm-Developer-Tools/HIP/pull/2218. When Git
is not available (or if the library is being built from a tarball),
the HIP_VERSION_GITHASH is not defined. This causes trouble because
HIP_LIB_VERSION_STRING is defined as "X.Y.Z-${HIP_VERSION_GITHASH}"
and therefore becomes "X.Y.Z-".

The incomplete version string becomes a problem when it is appended
to the shared library file name. File names that end with '-' confuse
the linker. They cause strange errors when attempting to link to the
HIP library. This problem can be prevented by dropping the trailing
dash and using "X.Y.Z" as the version string when HIP_VERSION_GITHASH
is not defined.

Change-Id: I6e290c1f1b603ba30c9ded885e125d9ca9a2e688
Signed-off-by: Cordell Bloor <Cordell.Bloor@amd.com>
Este commit está contenido en:
Cordell Bloor
2022-05-06 14:19:47 -06:00
padre 4e86d538e5
commit 9c450d6f66
+5 -1
Ver fichero
@@ -139,6 +139,8 @@ if(GIT_FOUND)
set(HIP_PACKAGING_VERSION_PATCH ${HIP_VERSION_PATCH}-${HIP_VERSION_GITHASH})
endif()
else()
set(HIP_VERSION_BUILD_ID 0)
set(HIP_VERSION_BUILD_NAME "")
# FIXME: Some parts depend on this being set.
set(HIP_PACKAGING_VERSION_PATCH "0")
endif()
@@ -182,8 +184,10 @@ set (HIP_LIB_VERSION_MAJOR ${HIP_VERSION_MAJOR})
set (HIP_LIB_VERSION_MINOR ${HIP_VERSION_MINOR})
if (${ROCM_PATCH_VERSION} )
set (HIP_LIB_VERSION_PATCH ${ROCM_PATCH_VERSION})
else ()
elseif (DEFINED HIP_VERSION_GITHASH)
set (HIP_LIB_VERSION_PATCH ${HIP_VERSION_PATCH}-${HIP_VERSION_GITHASH})
else ()
set (HIP_LIB_VERSION_PATCH ${HIP_VERSION_PATCH})
endif ()
set (HIP_LIB_VERSION_STRING "${HIP_LIB_VERSION_MAJOR}.${HIP_LIB_VERSION_MINOR}.${HIP_LIB_VERSION_PATCH}")
if (DEFINED ENV{ROCM_RPATH})