%bcond_without check

Name:           bornagain
Version:        21.1
Release:        %autorelease
Summary:        A software to simulate and fit neutron and x-ray reflectometry and scattering
# The main package is licensed under GPL-3.0-only
# The bundled files in the directory of 3rdparty/Core/tspectrum, which is from
# ROOT, is LGPL-2.1-or-later license
License:        GPL-3.0-only AND LGPL-2.1-or-later
URL:            https://www.bornagainproject.org/
Source0:        https://jugit.fz-juelich.de/mlz/bornagain/-/archive/v%{version}/%{name}-v%{version}.tar.bz2
Source1:        BornAgain.desktop
Patch0:         bornagain-fix-cmake.patch

BuildRequires:  gcc-c++
BuildRequires:  cmake
BuildRequires:  ninja-build
BuildRequires:  cmake(LibHeinz)
BuildRequires:  cmake(formfactor)
BuildRequires:  fftw-devel
BuildRequires:  gsl-devel
BuildRequires:  cmake(cerf)
BuildRequires:  libtiff-devel
BuildRequires:  boost-devel

BuildRequires:  cmake(Qt6Core)
BuildRequires:  cmake(Qt6Gui)
BuildRequires:  cmake(Qt6Widgets)
BuildRequires:  cmake(Qt6PrintSupport)
BuildRequires:  cmake(Qt6Svg)
BuildRequires:  cmake(Qt6OpenGL)
BuildRequires:  cmake(Qt6OpenGLWidgets)
BuildRequires:  gtest-devel
BuildRequires:  qcustomplot-qt6-devel

BuildRequires:  python3-devel
BuildRequires:  %{py3_dist pip}
BuildRequires:  %{py3_dist numpy}
BuildRequires:  %{py3_dist matplotlib}
BuildRequires:  desktop-file-utils
BuildRequires:  chrpath

Provides:       bundled(tspectrum)

%description
BornAgain is a open-source research software to simulate and fit neutron and
x-ray reflectometry and grazing-incidence small-angle scattering.

Its name, BornAgain, alludes to the central role of the distorted-wave Born
approximation in the physical description of the scattering process. The
software provides a generic framework for modeling multilayer samples with
smooth or rough interfaces and with various types of embedded nanoparticles.

%package        libs
Summary:        Runtime libraries of %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    libs
The %{name}-libs package contains runtime libraries of %{name}.

%package        devel
Summary:        Development files for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    devel
The %{name}-devel package contains development files for %{name}.

%package        python3
Summary:        Python bindings for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    python3
The %{name}-python3 package contains Python bindings for %{name}.

%package        examples
Summary:        Example files for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    examples
The %{name}-examples package contains example files for %{name}.

%prep
%autosetup -p1 -n %{name}-v%{version}

rm -r 3rdparty/{common,GUI/qcustomplot}

%build
%cmake \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DBA_CPP_API=ON \
    -DBA_USE_SYSTEM_GTEST=ON \
    -DBA_USE_SYSTEM_QCUSTOMPLOT=ON \

%cmake_build

%install
%cmake_install

install -pDm0644 %{SOURCE1} %{buildroot}%{_datadir}/applications/BornAgain.desktop

chrpath --delete %{buildroot}%{_bindir}/%{name}
chrpath --delete %{buildroot}%{_libdir}/BornAgain_%{version}/_libBornAgain*.so

%check
# https://copr.fedorainfracloud.org/coprs/shattuckite/bornagain/build/6693720/
# many tests failed on aarch64, ppc64le and s390x, disable for now.
%ifarch x86_64
%ctest
%endif

desktop-file-validate %{buildroot}/%{_datadir}/applications/*.desktop

%files
%license COPYING
%doc README.md
%{_bindir}/%{name}
%{_datadir}/icons/hicolor/*/apps/BornAgain.png
%{_datadir}/applications/BornAgain.desktop
%{_mandir}/man1/

%files libs
%{_libdir}/BornAgain_%{version}/_libBornAgain*.so

%files devel
%{_includedir}/BornAgain_%{version}/

%files python3
%{python3_sitearch}/BornAgain/

%files examples
%{_datadir}/BornAgain_%{version}/bornagain_build.log
%{_datadir}/BornAgain_%{version}/Examples/

%changelog
%autochangelog