
%global qt_module qtquick3dphysics

%global examples 1

%define short_version 6.5

Name:           qt6-%{qt_module}
Version:        6.5.2
Release:        2
Summary:        Qt 6 Quick3D Physics Extensions
License:        GPL-3.0-only
URL:            https://www.qt.io


Source0: https://download.qt.io/official_releases/qt/%{short_version}/%{version}/submodules/%{qt_module}-everywhere-src-%{version}.tar.xz

#fix physx on riscv64
# https://github.com/felixonmars/archriscv-packages/pull/1821 
Patch0: physx-rv64.patch
Patch1: physx-loongarch64.patch

BuildRequires: cmake
BuildRequires: gcc-c++
BuildRequires: ninja-build
BuildRequires: qt6-rpm-macros >= %{version}
BuildRequires: qt6-qtbase-static >= %{version}
BuildRequires: qt6-qtbase-private-devel
%{?_qt6:Requires: %{_qt6}%{?_isa} = %{_qt6_version}}
BuildRequires: qt6-qtquick3d-devel
BuildRequires: qt6-qtshadertools-devel

%description
This module adds physical simulation capabilities on top of Qt Quick 3D.
In particular, it enables rigid body simulation using simple primitives as well
as convex- and triangle meshes and heightmaps. Physical properties such as mass,
density, gravity and friction are customizable. This makes it possible to create
physically correct behavior in 3D scenes without having to handcraft animations.

%package devel
Summary:        Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: qt6-qtbase-devel%{?_isa}
%description devel
%{summary}.

%if 0%{?examples}
%package examples
Summary: Programming examples for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
%description examples
%{summary}.
%endif

%prep
%autosetup -p1 -n %{qt_module}-everywhere-src-%{version} -p1

%build
%define _lto_cflags %{nil}

%cmake_qt6  -DQT_BUILD_EXAMPLES:BOOL=%{?examples:ON}%{!?examples:OFF}
cmake --build . %{?_smp_mflags} --verbose

%install
DESTDIR="%{buildroot}" cmake --install .

## .prl/.la file love
# nuke .prl reference(s) to %%buildroot, excessive (.la-like) libs
pushd %{buildroot}%{_qt6_libdir}
for prl_file in libQt6*.prl ; do
  sed -i -e "/^QMAKE_PRL_BUILD_DIR/d" ${prl_file}
  if [ -f "$(basename ${prl_file} .prl).so" ]; then
    rm -fv "$(basename ${prl_file} .prl).la"
    sed -i -e "/^QMAKE_PRL_LIBS/d" ${prl_file}
  fi
done
popd

%files
%license LICENSES/*
%{_qt6_libdir}/libQt6Quick3DPhysicsHelpers.so.6*
%{_qt6_libdir}/libQt6Quick3DPhysics.so.6*
%dir %{_qt6_qmldir}/QtQuick3D
%{_qt6_qmldir}/QtQuick3D/Physics/

%files devel
%{_qt6_bindir}/cooker
%{_qt6_libdir}/libQt6Quick3DPhysics.prl
%{_qt6_libdir}/libQt6Quick3DPhysics.so
%{_qt6_libdir}/libQt6Quick3DPhysicsHelpers.prl
%{_qt6_libdir}/libQt6Quick3DPhysicsHelpers.so
%{_qt6_libdir}/cmake/Qt6BundledPhysX/
%{_qt6_libdir}/cmake/Qt6Quick3DPhysics/
%{_qt6_libdir}/cmake/Qt6Qml/QmlPlugins/*.cmake
%{_qt6_libdir}/cmake/Qt6Quick3DPhysicsHelpers/
%{_qt6_libdir}/cmake/Qt6/FindWrapBundledPhysXConfigExtra.cmake
%{_qt6_libdir}/cmake/Qt6BuildInternals/StandaloneTests/QtQuick3DPhysicsTestsConfig.cmake
%{_qt6_archdatadir}/metatypes/qt6quick3dphysics_*_metatypes.json
%{_qt6_archdatadir}/metatypes/qt6quick3dphysicshelpers_*_metatypes.json
%{_qt6_archdatadir}/modules/Quick3DPhysics.json
%{_qt6_archdatadir}/modules/Quick3DPhysicsHelpers.json
%{_qt6_includedir}/QtQuick3DPhysics/
%{_qt6_includedir}/QtQuick3DPhysicsHelpers/
%{_qt6_mkspecsdir}/modules/qt_lib_quick3dphysics.pri
%{_qt6_mkspecsdir}/modules/qt_lib_quick3dphysics_private.pri
%{_qt6_mkspecsdir}/modules/qt_lib_quick3dphysicshelpers.pri
%{_qt6_mkspecsdir}/modules/qt_lib_quick3dphysicshelpers_private.pri
%{_qt6_libdir}/libQt6BundledPhysX.a
%{_qt6_libdir}/pkgconfig/*.pc


%if 0%{?examples}
%files examples
%{_qt6_examplesdir}/
%endif

%changelog
* Thu June 27 2024 shaojiansong <shaojiansong@kylinos.cn> - 6.5.2-2
- Add support for loongarch64.
- Fix lack of patch files in src.rpm package which build from any platform.

* Thu Nov 30 2023 peijiankang <peijiankang@kylinos.cn> - 6.5.2-1
- Update to 6.5.2

* Fri Aug 11 2023 zhangchenglin <zhangchenglin@kylinos.cn> - 6.5.1-1
- Update to 6.5.1

* Tue May 9 2023 EastDong <xudong23@iscas.ac.cn> - 6.5.0-1
- init package
