%bcond_with python3
%bcond_with doc

%global srcname Imath
%global sover 29
%global pyver_under %(%{python3} -Esc "import sys; sys.stdout.write('{0.major}_{0.minor}'.format(sys.version_info))")

Name:           imath
Summary:        Library of 2D and 3D vector, matrix, and math operations for computer graphics
Version:        3.1.4
Release:        1%{?_dist_release}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        BSD
URL:            https://github.com/AcademySoftwareFoundation/Imath
Source0:        https://github.com/AcademySoftwareFoundation/%{srcname}/archive/v%{version}/%{srcname}-%{version}.tar.gz

Patch0:         imath-python-test.patch

BuildRequires:  cmake
BuildRequires:  gcc gcc-c++
BuildRequires:  make
BuildRequires:  libboost-devel
%if %{with python3}
BuildRequires:  libboost-python3-devel
BuildRequires:  python3-devel
BuildRequires:  python3-rpm-macros
BuildRequires:  python3-numpy
%endif
%if %{with doc}
# For documentation generation
BuildRequires:  doxygen
BuildRequires:  python3-sphinx
BuildRequires:  python3-breathe
%endif

%description
Imath is a basic, light-weight, and efficient C++ representation of 2D and 3D
vectors and matrices and other simple but useful mathematical objects,
functions, and data types common in computer graphics applications, including
the “half” 16-bit floating-point type.


%if %{with python3}
%package -n python3-%{name}
Summary:        Python module for Imath
Group:          programming
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description -n python3-%{name}
%{summary}.
%endif


%package devel
Summary:        Development files for Imath
Group:          programming
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       libboost-devel
%if %{with python3}
Requires:       libboost-python3-devel
Requires:       python3-%{name}%{?_isa} = %{version}-%{release}
Requires:       python3-devel
%endif

%description devel
%{summary}.


%debug_package


%prep
%autosetup -n %{srcname}-%{version} -p1


%build
%cmake \
    -DCMAKE_INSTALL_PREFIX=%{_usr} \
%if %{with python3}
    -DPYTHON=ON \
%endif
    %{nil}
%cmake_build

%if %{with doc}
# Generate man docs
cd docs
# https://github.com/AcademySoftwareFoundation/Imath/issues/196#issuecomment-896433898
rm classes/half.rst
doxygen
cd ..
PYTHONPATH=${PWD} sphinx-build-3 docs/ html
# Remove the sphinx-build leftovers
rm -rf html/.{doctrees,buildinfo}
%endif


%install
%cmake_install


%check
# https://github.com/AcademySoftwareFoundation/Imath/issues/151
%ifnarch i686
%ctest
%endif


%files
%license LICENSE.md
%doc CHANGES.md CODE_OF_CONDUCT.md CONTRIBUTING.md CONTRIBUTORS.md README.md SECURITY.md
%{_libdir}/libImath-3_1.so.%{sover}*

%if %{with python3}
%files -n python3-%{name}
%{_libdir}/libPyImath_Python%{pyver_under}-3_1.so.%{sover}*
%{python3_sitearch}/imath.so
%{python3_sitearch}/imathnumpy.so
%endif

%files devel
%if %{with doc}
%doc html/
%endif
%{_includedir}/Imath/
%{_libdir}/pkgconfig/Imath.pc
%{_libdir}/cmake/Imath/
%{_libdir}/libImath.so
%{_libdir}/libImath-3_1.so
%if %{with python3}
%{_libdir}/pkgconfig/PyImath.pc
%{_libdir}/libPyImath_Python%{pyver_under}-3_1.so
%endif


%changelog
* Thu Jan 27 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.4-1
- new upstream release.

* Thu Jan 13 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.3-1
- new upstream release.

* Wed Sep 01 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.2-1
- initial build for Vine Linux.

* Wed Aug 11 2021 Josef Ridky <jridky@redhat.com> - 3.1.2-1
- New upstream release 3.1.2

* Fri Aug 06 2021 Jonathan Wakely <jwakely@redhat.com> - 3.0.2-6
- Rebuilt for Boost 1.76

* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.0.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 3.0.2-4
- Rebuilt for Python 3.10

* Thu May 27 2021 Richard Shaw <hobbes1069@gmail.com> - 3.0.2-3
- Add main package as dependency to python package.

* Tue May 25 2021 Richard Shaw <hobbes1069@gmail.com> - 3.0.2-2
- Update spec per reviewer comments.

* Thu May 20 2021 Richard Shaw <hobbes1069@gmail.com> - 3.0.2-1
- Update to 3.0.2.

* Wed Apr 07 2021 Richard Shaw <hobbes1069@gmail.com> - 3.0.1-1
- Initial packaging.
