File libkml.spec of Package libkml

#
# spec file for package libkml
#
# Copyright (c) 2022 SUSE LLC
#
# 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         _libsoname libkml_1
%global __requires_exclude_from ^%{_docdir}/.*$
Name:           libkml
Version:        1.3.0
Release:        0
Summary:        Reference implementation of OGC KML 2.2
License:        BSD-3-Clause
URL:            https://github.com/libkml/libkml
Source0:        https://github.com/libkml/libkml/archive/%{version}/libkml-%{version}.tar.gz
## See https://github.com/libkml/libkml/pull/239
Patch0:         0001-Fix-build-failure-due-to-failure-to-convert-pointer-.patch
Patch1:         0002-Fix-mistaken-use-of-std-cerr-instead-of-std-endl.patch
Patch2:         0003-Fix-python-tests.patch
Patch3:         0004-Correctly-build-and-run-java-test.patch
# Fix a fragile test failing on i686
Patch4:         fragile_test.patch
# Don't bytecompile python sources as part of build process, leave it to rpmbuild
Patch5:         libkml_dont-bytecompile.patch
Patch6:         0005-minizip-no-crypt-header.patch
BuildRequires:  boost-devel
BuildRequires:  cmake
BuildRequires:  curl-devel
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  googletest-devel
BuildRequires:  java-devel
BuildRequires:  junit
BuildRequires:  liburiparser-devel
BuildRequires:  minizip-devel
BuildRequires:  pkgconfig
BuildRequires:  python3-devel
BuildRequires:  swig
BuildRequires:  zlib-devel
BuildRequires:  pkgconfig(expat)

%description
Reference implementation of OGC KML 2.2.
It also includes implementations of Google's gx: extensions used by Google

%package -n %{_libsoname}
Summary:        Reference implementation of OGC KML 2.2 shared library
Group:          Development/Libraries/C and C++

%description -n %{_libsoname}
Reference implementation of OGC KML 2.2.
It also includes implementations of Google's gx: extensions used by Google
Earth, as well as several utility libraries for working with other formats.

%package -n python3-%{name}
%{?python_provide:%python_provide python3-%{name}}
Summary:        Python 3 bindings for %{name}
Group:          Development/Libraries/Python
Requires:       %{_libsoname} = %{version}

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

%package -n java-%{name}
Summary:        Java bindings for %{name}
Group:          Development/Libraries/Java
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description -n java-%{name}
The %{name}-java package contains Java bindings for %{name}.

%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries/C and C++
Requires:       %{_libsoname} = %{version}-%{release}
Requires:       boost-devel
Requires:       pkgconfig(expat)

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%prep
%autosetup -p1 -n libkml-%{version}
# Remove exec bit on examples
chmod -x examples/ruby/*.rb examples/perl/*.pl examples/php/*.php examples/python/*.py examples/java/*.sh examples/domviewer/*.py
#Adapt lib to _libdir
sed -i 's,libdir=${exec_prefix}/lib,libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@,g' cmake/libkml.pc.in

%build
%ifarch armv7hl
%define awtlib -DJAVA_AWT_LIBRARY=`find %{_prefix}/lib/jvm/ -name libjawt.so | grep jre/lib/arm \`
%endif
# keep for 15.2 and the stranger 36m
%if (0%{?python3_version_nodots} == 36)
%define _pyinclude %{_includedir}/python%{python3_version}m
%define _pylib %{_libdir}/libpython%{python3_version}m.so
%else
%define _pyinclude %{_includedir}/python%{python3_version}
%define _pylib %{_libdir}/libpython%{python3_version}.so
%endif

%cmake \
  -DBUILD_SHARED_LIBS=ON \
  -DWITH_SWIG=ON \
  -DWITH_PYTHON=ON \
  -DWITH_JAVA=ON \
  -DJNI_INSTALL_DIR=%{_libdir}/%{name} \
  -DCMAKE_INSTALL_DIR=%{_libdir}/cmake/%{name} \
  -DINCLUDE_INSTALL_DIR=%{_includedir}/kml \
  -DPYTHON_LIBRARY=%{_pylib} \
  -DPYTHON_INCLUDE_DIR=%{_pyinclude}/ \
  -DPYTHON_INSTALL_DIR=%{python3_sitearch} \
  -DBUILD_TESTING=ON \
  -DBUILD_EXAMPLES=OFF \
  ../..
%make_build

%install
cd build
%make_install

# Bytecompile and install correctly pyc files
%{_bindir}/python%{python3_version} -m compileall %{buildroot}%{python3_sitearch}/*.py

%check
ctest -V

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

%files -n %{_libsoname}
%license LICENSE
%doc AUTHORS README.md
%{_libdir}/libkml*.so.*

%files -n python3-%{name}
%{python3_sitearch}/*.so
%{python3_sitearch}/*.py
%{python3_sitearch}/__pycache__/*.pyc

%files -n java-%{name}
%{_javadir}/LibKML.jar
%{_libdir}/libkml
%{_libdir}/libkml/libkmlbase_swig_java.so
%{_libdir}/libkml/libkmldom_swig_java.so
%{_libdir}/libkml/libkmlengine_swig_java.so

%files devel
%doc examples
%{_includedir}/kml/
%{_libdir}/libkml*.so
%{_libdir}/pkgconfig/libkml.pc
%{_libdir}/cmake/libkml/

%changelog
openSUSE Build Service is sponsored by