File hipcub.spec of Package hipcub

%global upstreamname hipCUB

%global rocm_release 6.2
%global rocm_patch 0
%global rocm_version %{rocm_release}.%{rocm_patch}

# hipCUB version
%define hipcub_version 3.2.0

# Compiler is hipcc, which is clang based:
%global toolchain clang
# hipcc does not support some clang flags
%global build_cxxflags %(echo %{optflags} | sed -e 's/-fstack-protector-strong/-Xarch_host -fstack-protector-strong/' -e 's/-fcf-protection/-Xarch_host -fcf-protection/')
# there is no debug package
%global debug_package %{nil}

%global build_type RelWithDebInfo

# Option to build the test suite
%bcond_without test
# Option to run the test suite for testing on real HW:
%bcond_with check

Name:           hipcub
Version:        %{rocm_version}
Release:        0
Summary:        ROCm port of CUDA CUB library

Url:            https://github.com/ROCm/%{upstreamname}
License:        MIT and BSD-3-Clause
Source0:        %{url}/archive/refs/tags/rocm-%{version}.tar.gz#/%{upstreamname}-rocm-%{version}.tar.gz
Patch0:         hipcub-fix-c++17-build.patch
BuildRequires:  cmake
BuildRequires:  ninja
BuildRequires:  rocm-cmake
BuildRequires:  rocm-comgr-devel
BuildRequires:  rocm-hip-devel
BuildRequires:  rocm-release(rocprim-headers) = %{rocm_release}
BuildRequires:  rocm-runtime-devel
BuildRequires:  rocm-rpm-macros

%if 0%{?sle_version} == 150600
BuildRequires:  gcc12-c++
BuildRequires:  libstdc++6-devel-gcc12
%else
BuildRequires:  libstdc++-devel
%endif

%if %{with check} || %{with test}
BuildRequires:  googletest-devel
%endif

# Only headers, cmake infra but noarch confuses the libdir
# BuildArch: noarch
# Only x86_64 works right now:
ExclusiveArch:  x86_64

%description
hipCUB is a thin wrapper library on top of rocPRIM or CUB. It enables developers
to port a project using the CUB library to the HIP layer to run on AMD hardware.
In the ROCm environment, hipCUB uses the rocPRIM library as the backend.

%package        devel
Summary:        The %{upstreamname} development package
Provides:       %{name}-headers = %{hipcub_version}
Provides:       rocm-release(%{name}-headers) = %{rocm_release}
Requires:       rocm-release(rocprim-headers) = %{rocm_release}

%description devel
hipCUB is a thin wrapper library on top of rocPRIM or CUB. It enables developers
to port a project using the CUB library to the HIP layer to run on AMD hardware.
In the ROCm environment, hipCUB uses the rocPRIM library as the backend.

%if %{with test}
%package     test
Summary:     Tests for %{name}

%description test
This package contains the test files to be run on real hardware.
%endif

%prep
%autosetup -p1 -n %{upstreamname}-rocm-%{version}

sed -i -e '/INSTALL_RPATH/d' -e 's/set(CMAKE_CXX_STANDARD.*/set(CMAKE_CXX_STANDARD 17)/' CMakeLists.txt

#
# The ROCMExportTargetsHeaderOnly.cmake file
# generates a files that reference the install location of other files
# Make this change so they match
sed -i -e 's/ROCM_INSTALL_LIBDIR lib/ROCM_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/' cmake/ROCMExportTargetsHeaderOnly.cmake

%build
%define __builder ninja
%cmake \
    -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF \
%if %{with check} || %{with test}
    -DBUILD_TEST=ON \
%endif
    -DCMAKE_BUILD_TYPE=%build_type \
    -DCMAKE_CXX_COMPILER=%rocm_cxx \
    -DCMAKE_CXX_FLAGS="%build_cxxflags $CXXFLAGS" \
    -DCMAKE_PREFIX_PATH="%rocm_path" \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_INSTALL_LIBDIR=%{_lib} \
    -DROCM_SYMLINK_LIBS=OFF \
    -DAMDGPU_TARGETS="%{list_sep rocm_gpu_list ;}"
%cmake_build

%install
%cmake_install

# we don't need the docs
rm -rf %{buildroot}%{_docdir}/%{name}

%if %{with test}
# move tests to libexec
mkdir -p %{buildroot}%{_libexecdir}/%{name}-test
mv %{buildroot}%{_bindir}/* %{buildroot}%{_libexecdir}/%{name}-test/
%endif

%check
%if %{with check}
%ctest
%endif

%files devel
%doc README.md
%license LICENSE.txt
%{_includedir}/%{name}
%{_libdir}/cmake/%{name}

%if %{with test}
%files test
%{_libexecdir}/%{name}-test
%endif

%changelog
openSUSE Build Service is sponsored by