File adios2.spec of Package adios2

#
# spec file for package adios
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define flavor @BUILD_FLAVOR@%{nil}
%define pname adios2
%define vers 2.7.1

# Name the suffix of the pkg
%if "%flavor" != "%nil"
  %define pkg_suffix -@BUILD_FLAVOR@
%endif

%if "%flavor" == "openmpi3"
%global mpi_flavor openmpi3
%global mpi_family openmpi
%global mpi_ver 3
%endif

%if "%flavor" == "openmpi4"
%global mpi_flavor openmpi4
%global mpi_family openmpi
%global mpi_ver 4
%endif

%if "%flavor" == "gnu-openmpi3-hpc"
%global mpi_flavor openmpi3
%global mpi_family openmpi
%global mpi_ver 3
%bcond_without hpc
%endif

%if "%flavor" == "gnu-openmpi4-hpc"
%global mpi_flavor openmpi4
%global mpi_family openmpi
%global mpi_ver 4
%bcond_without hpc
%endif

%if "%flavor" == "mpich"
%global mpi_flavor mpich
%global mpi_family mpich
%endif

%if "%flavor" == "gnu-mpich-hpc"
%global mpi_flavor mpich
%global mpi_family mpich
%bcond_without hpc
%endif

%if "%flavor" == "mvapich2"
%global mpi_flavor mvapich2
%global mpi_family mvapich2
%endif

%if "%flavor" == "gnu-mvapich2-hpc"
%global mpi_flavor mvapich2
%global mpi_family mvapich2
%bcond_without hpc
%endif

%if "%flavor" == "python"
%global py_flavor python
%endif

%if "%flavor" == "python-openmpi3"
%global py_flavor python
%global mpi_flavor openmpi3
%global mpi_family openmpi
%global mpi_ver 3
%endif

%if "%flavor" == "python-openmpi4"
%global py_flavor python
%global mpi_flavor openmpi4
%global mpi_family openmpi
%global mpi_ver 4
%endif

%if "%flavor" == "python-gnu-openmpi3-hpc"
%global py_flavor python
%global mpi_flavor openmpi3
%global mpi_family openmpi
%global mpi_ver 3
%bcond_without hpc
%endif

%if "%flavor" == "python-gnu-openmpi4-hpc"
%global py_flavor python
%global mpi_flavor openmpi4
%global mpi_family openmpi
%global mpi_ver 4
%bcond_without hpc
%endif

%if "%flavor" == "python-mpich"
%global py_flavor python
%global mpi_flavor mpich
%global mpi_family mpich
%endif

%if "%flavor" == "python-gnu-mpich-hpc"
%global py_flavor python
%global mpi_flavor mpich
%global mpi_family mpich
%bcond_without hpc
%endif

%if "%flavor" == "python-mvapich2"
%global py_flavor python
%global mpi_flavor mvapich2
%global mpi_family mvapich2
%endif

%if "%flavor" == "python-gnu-mvapich2-hpc"
%global py_flavor python
%global mpi_flavor mvapich2
%global mpi_family mvapich2
%bcond_without hpc
%endif

# Python ----------------------------------------------------------------------
%if 0%{?py_flavor:1}
  %global _pyvers_ %py_flavor
%endif


# OpenHPC----------------------------------------------------------------------
%if 0%{?fedora} && %{with hpc}
ExclusiveArch:  do_not_build
%endif

# MPI    ----------------------------------------------------------------------
%if 0%{?mpi_flavor:1}

  # No OMPI4 in 15.3
  %if "%mpi_flavor" == "openmpi4" && 0%{?sle_version} == 150300
ExclusiveArch:  do_not_build
  %endif

  %if "%mpi_flavor" == "openmpi4" && 0%{?fedora}
    %global mpi_flavor openmpi
  %endif

  %if "%mpi_flavor" == "openmpi3" && 0%{?fedora}
ExclusiveArch:  do_not_build
  %endif

  # Fedora does not have mvapich2
  # Exclude builds that does not make sense
  %if "%mpi_flavor" == "mvapich2" && 0%{?fedora}
ExclusiveArch:  do_not_build
  %endif

  # There is not mpi4py with mvapich2
  %if "%mpi_flavor" == "mvapich2" && 0%{?py_flavor:1}
ExclusiveArch:  do_not_build
  %endif
%endif

%if %{with hpc}
%global hpc_mpi_flavor gnu-%{mpi_flavor}-hpc
%endif

%if 0%{?fedora}
  # :FIXME: this macro is defined at python-rpm-macros package
  # but somehow it does not expands when building in fedora
  %define python3_version 3.9
%endif

# Paths  ----------------------------------------------------------------------
%{?_pyvers_:%{bcond_without python}}%{!?_pyvers_:%{bcond_with python}}
%{?mpi_flavor:%{bcond_without mpi}}%{!?mpi_flavor:%{bcond_with mpi}}
%{?with_hpc:%{!?compiler_family:%global compiler_family gnu}}
%{?with_mpi:%{!?mpi_flavor:%global mpi_flavor openmpi}}
%{?with_mpi:%global pkg_suffix -%{mpi_flavor}}

%if %{with hpc}
 %{hpc_init -c %{compiler_family} %{?with_mpi:-m %mpi_family} %{?c_f_ver:-v %{c_f_ver}} %{?mpi_ver:-V %{mpi_ver}} %{?ext:-e %{ext}}}
 %global hpc_module_pname %{pname}
 %define pkg_prefix %hpc_prefix
 %define pkg_bindir %hpc_bindir
 %define pkg_libdir %hpc_libdir
 %define pkg_incdir %hpc_includedir
 %define pkg_datadir %hpc_datadir
 %define pkg_sysconfdir %{hpc_prefix}/etc
 %define package_name   %{hpc_package_name %{vers}}
 %define libname(l:s:)   lib%{pname}%{-l*}%{hpc_package_name_tail %{?vers}}
%else
 %{?with_mpi:%define pkg_prefix %{_libdir}/mpi/gcc/%{mpi_flavor}}
 %{!?with_mpi:%define pkg_prefix %{_prefix}}
 %define pkg_bindir %{pkg_prefix}/bin
 %define pkg_libdir %{pkg_prefix}/%{_lib}/
 %define pkg_incdir %{pkg_prefix}/include/
 %define pkg_datadir %{pkg_prefix}/share/
 %define pkg_sysconfdir %{pkg_prefix}/etc/
 %define package_name   %pname%{?pkg_suffix}
 %define libname(l:s:)   lib%{pname}%{!-l:%{-s:-}}%{-l*}%{-s*}%{?pkg_suffix}
%endif

%define py_libdir      %{pkg_libdir}/python%{python3_version}

# Header ----------------------------------------------------------------------
Name:    %{package_name}
Version: %{vers}
Release: 0
Summary: The Adaptable IO System (ADIOS2)
License: Apache-2.0
Group:   Productivity/Scientific/Other
URL:     https://adios2.readthedocs.io/en/release/
Source0: https://github.com/ornladios/ADIOS2/archive/v%{version}.tar.gz
Source1: adios2-rpmlintrc
Patch0:  python-shebang.patch
Patch1:  evpath-set-soname.patch

# In tumbleweed math lib fails to automatically get linked
%if 0%{?suse_version} > 1500
Patch2:  evpath-link-m.patch
%endif

%if %{with hpc}
BuildRequires: suse-hpc > 0.3
BuildRequires: lua-lmod
BuildRequires: gnu-compilers-hpc-macros-devel
%{?mpi_flavor:BuildRequires: %{mpi_flavor}-gnu-hpc-macros-devel}
%{hpc_requires}
%endif

BuildRequires: cmake
BuildRequires: fdupes
BuildRequires: gcc-c++
BuildRequires: gcc-fortran
BuildRequires: python3
BuildRequires: python3-numpy
BuildRequires: zlib-devel

# mpi4py pkg (Not MPI-4)
%if %{with mpi}
BuildRequires: %{mpi_flavor}-devel
  %if %{with python}
    %if 0%{?fedora}
BuildRequires: python3-mpi4py-%{mpi_flavor}
    %else
      %if 0%{?suse_version} > 1500
BuildRequires: python38-mpi4py-devel
      %endif
      %if 0%{?sle_version} == 150300
BuildRequires: python3-mpi4py-devel
      %endif
    %endif
  %endif
%endif

%if %{with python}
BuildRequires: python3-devel
  %if 0%{?suse_version} > 1500
BuildRequires: python38-numpy-devel
  %endif
  %if 0%{?sle_version} == 150300
BuildRequires: python3-numpy-devel
  %endif
%endif

%if 0%{?suse_version}
BuildRequires: libbz2-devel
BuildRequires: liblz4-devel
%endif

%if 0%{?fedora}
Requires: environment-modules
BuildRequires: bzip2-devel
BuildRequires: environment-modules
BuildRequires: lz4-devel
BuildRequires: python-rpm-macros
%endif

%description
ADIOS2: The Adaptable Input Output (I/O) System version 2  is an open-source
framework that addresses scientific data management challenges, e.g. scalable
parallel I/O, as we approach the exascale era in high-performance computing
(HPC). ADIOS 2 bindings are available in C++, C, Fortran, Python and can be
used on supercomputers, personal computers, and cloud systems running on Linux,
macOS and Windows. ADIOS 2 has out-of-the-box support for MPI and serial
environments.

This package contains all files needed to run projects that depends on the
%{?mpi_flavor}%{!?mpi_flavor:serial} version of ADIOS2.

%{?with_hpc:%hpc_master_package -L}

%package devel
Summary:  Development files for %{name}
Group:    Development/Libraries/Parallel

Requires: %{name} = %{version}

%if 0%{?with_hdf5}
%if %{with hpc}
Requires: hdf5%{?hpc_mpi_flavor:-%{hpc_mpi_flavor}}-devel
BuildRequires: hdf5%{?hpc_mpi_flavor:-%{hpc_mpi_flavor}}-devel
%else
Requires: hdf5%{?mpi_flavor:-%{mpi_flavor}}-devel
BuildRequires: hdf5%{?mpi_flavor:-%{mpi_flavor}}-devel
%endif
%endif

%if %{with hpc}
%hpc_requires_devel
%endif

%description devel
ADIOS2: The Adaptable Input Output (I/O) System version 2  is an open-source
framework that addresses scientific data management challenges, e.g. scalable
parallel I/O, as we approach the exascale era in high-performance computing
(HPC). ADIOS 2 bindings are available in C++, C, Fortran, Python and can be
used on supercomputers, personal computers, and cloud systems running on Linux,
macOS and Windows. ADIOS 2 has out-of-the-box support for MPI and serial
environments.

This package contains all files needed to create projects that use the
%{?mpi_flavor}%{!?mpi_flavor:serial} version of ADIOS2.

%{?with_hpc:%{hpc_master_package -L devel}}

%prep
%setup -q -n ADIOS2-%{version}
%patch0 -p1
%patch1 -p1

# In Tumbleweed math lib fails to automatically get linked
%if 0%{?suse_version} > 1500
%patch2 -p1
%endif

%build
%{?with_hpc:%hpc_setup}

export CC=gcc
export CXX=g++
export F77=gfortran
export F9X=gfortran
export FC=gfortran
export CFLAGS="%{optflags}"

%if 0%{?with_mpi}

# Fedora must load the openmpi module first
%if 0%{?fedora}
source /etc/profile.d/modules.sh
module load mpi
%endif

export MPICC=mpicc
export MPICXX=mpicxx
export MPIFC=mpif90
export MPICC="%{pkg_bindir}/mpicc"
export MPIFC="%{pkg_bindir}/mpif90"
export PATH=${PATH}:%{pkg_bindir}
export LDFLAGS="${LDFLAGS} -L%{pkg_libdir}"
export LD_LIBRARY_PATH="%{pkg_libdir}"
%endif

%cmake \
    -DADIOS2_BUILD_EXAMPLES=OFF \
    -DADIOS2_USE_BP5=%{?without_bp5:OFF}%{!?without_bp5:ON} \
    -DADIOS2_USE_BZip2=ON \
    -DADIOS2_USE_Fortran=ON \
    -DADIOS2_USE_HDF5=%{?with_hdf5:ON}%{!?with_hdf5:OFF} \
    -DADIOS2_USE_MGARD=OFF \
    -DADIOS2_USE_MPI=%{?with_mpi:ON}%{!?with_mpi:OFF} \
    -DADIOS2_USE_Profiling=OFF \
    -DADIOS2_USE_Python=%{?with_python:ON}%{!?with_python:OFF} \
    -DBUILD_TESTING=OFF \
    -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \
    -DCMAKE_INSTALL_PREFIX=%{pkg_prefix} \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON

%cmake_build

%install

%if %{with hpc}
%hpc_setup
%endif

%cmake_install
%fdupes %buildroot

%if %{with hpc}
%hpc_write_modules_files
#%%Module1.0#####################################################################

proc ModulesHelp { } {

puts stderr " "
puts stderr "This module loads the %{pname} library built with the %{compiler_family} compiler"
puts stderr "toolchain and the %{mpi_flavor} MPI stack."
puts stderr "\nVersion %{version}\n"

}
module-whatis "Name: %{pname} built with %{compiler_family} compiler and %{mpi_flavor} MPI"
module-whatis "Version: %{version}"
module-whatis "Category: runtime library"
module-whatis "Description: %{summary}"
module-whatis "%{url}"

set     version                     %{version}

depends-on phdf5

prepend-path    PATH                %{hpc_bindir}
prepend-path    LD_LIBRARY_PATH     %{hpc_libdir}

setenv          %{hpc_upcase %pname}_DIR        %{hpc_prefix}
setenv          %{hpc_upcase %pname}_BIN        %{hpc_bindir}
setenv          %{hpc_upcase %pname}_LIB        %{hpc_libdir}

if {[file isdirectory  %{hpc_includedir}]} {
prepend-path    LIBRARY_PATH        %{hpc_libdir}
prepend-path    CPATH               %{hpc_includedir}
prepend-path    C_INCLUDE_PATH      %{hpc_includedir}
prepend-path    CPLUS_INCLUDE_PATH  %{hpc_includedir}
prepend-path    INCLUDE             %{hpc_includedir}

setenv          %{hpc_upcase %pname}_INC        %{hpc_includedir}
}
EOF
%endif

%post -n %{name} -p /sbin/ldconfig
%postun -n %{name} -p /sbin/ldconfig

%files
%if %{with hpc}
%{hpc_dirs}
%{hpc_modules_files}
%dir %{pkg_bindir}
%endif

%license Copyright.txt
%doc Contributing.md ReadMe.md

%{pkg_bindir}/*
%{pkg_libdir}/*.so.*

%if 0%{?with_python:1} || 0%{?without_bp5:1}

%dir %{py_libdir}/site-packages/adios2
%{py_libdir}/site-packages/adios2/*

# When using MPI whe own these dirs
%if 0%{?with_mpi}
  %dir %{py_libdir}
  %dir %{py_libdir}/site-packages
%endif

%endif

%files devel
%if %{with hpc}
%dir %{pkg_incdir}
%dir %{pkg_datadir}
%endif

%dir %{pkg_libdir}/cmake/adios2
%{pkg_incdir}/*
%{pkg_libdir}/*.so
%{pkg_libdir}/cmake/adios2/*

# When using MPI whe own these dirs
%if 0%{?with_mpi}
  %dir %{pkg_libdir}/cmake
  %dir %{pkg_datadir}/iotest-config
  %{pkg_datadir}/iotest-config
%endif

%changelog
openSUSE Build Service is sponsored by