Fix: CMake error with old or incomplete HIP install

Pull Request: https://projects.blender.org/blender/blender/pulls/137294
This commit is contained in:
Brecht Van Lommel
2025-04-10 18:56:47 +02:00
committed by Brecht Van Lommel
parent a043a0e74d
commit 3c483e3d40

View File

@@ -46,22 +46,23 @@ if(HIP_HIPCC_EXECUTABLE)
set(HIP_VERSION_MAJOR 0)
set(HIP_VERSION_MINOR 0)
set(HIP_VERSION_PATCH 0)
set(_hipcc_executable ${HIP_HIPCC_EXECUTABLE})
# Get version from the header.
file(STRINGS "${HIP_ROOT_DIR}/include/hip/hip_version.h" _tmp REGEX "^#define HIP_VERSION_MAJOR.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_MAJOR ${_tmp})
file(STRINGS "${HIP_ROOT_DIR}/include/hip/hip_version.h" _tmp REGEX "^#define HIP_VERSION_MINOR.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_MINOR ${_tmp})
file(STRINGS "${HIP_ROOT_DIR}/include/hip/hip_version.h" _tmp REGEX "^#define HIP_VERSION_PATCH.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_PATCH ${_tmp})
unset(_tmp)
set(_hip_version_file "${HIP_ROOT_DIR}/include/hip/hip_version.h")
if(EXISTS ${_hip_version_file})
file(STRINGS ${_hip_version_file} _tmp REGEX "^#define HIP_VERSION_MAJOR.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_MAJOR ${_tmp})
file(STRINGS ${_hip_version_file} _tmp REGEX "^#define HIP_VERSION_MINOR.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_MINOR ${_tmp})
file(STRINGS ${_hip_version_file} _tmp REGEX "^#define HIP_VERSION_PATCH.*$")
string(REGEX MATCHALL "[0-9]+" HIP_VERSION_PATCH ${_tmp})
unset(_tmp)
endif()
unset(_hip_version_file)
# Construct full semantic version.
set(HIP_VERSION "${HIP_VERSION_MAJOR}.${HIP_VERSION_MINOR}.${HIP_VERSION_PATCH}")
set(HIP_VERSION_SHORT "${HIP_VERSION_MAJOR}.${HIP_VERSION_MINOR}")
unset(_hip_version_raw)
unset(_hipcc_executable)
endif()
include(FindPackageHandleStandardArgs)