在 Leap 15.4 上编译 QGIS 3.22.9

1.RPMBUILD 相关准备
1).按照 RPMBUILD 命令建立缺省目录。

2.编译环境的准备
1) 安装 python3.10
sudo zypper in python310 python310-base python310-devel
2) 安装 openSUSE 相关包
sudo zypper in netcdf-devel hdf5-devel postgresql-devel libQt5Sql5-postgresql qtkeychain-qt5-devel qca-qt5-devel libexpat-devel python3-OWSLib PDAL-devel qwt6-devel gsl-devel protobuf-devel python3-GDAL python3-psycopg2 python3-Jinja2 python3-qscintilla-qt5 python3-qt5-devel python3-sip-devel python3-termcolor PyQt-builder libzip-devel libqca-qt5-devel PDal libQt53DLogic-devel FastCGI-devel libQt53DAnimation-devel libQt53DCore-devel libQt53DExtras-devel libQt53DInput-devel libQt53DQuick-devel libQt53DQuickAnimation-devel libQt53DQuickExtras-devel libQt53DQuickInput-devel libQt53DQuickRender-devel libQt53DQuickScene2D-devel libQt53DRender-devel libQt5Concurrent-devel libQt5Core-devel libQt5DBus-devel libQt5Gui-devel libQt5Network-devel libQt5Positioning-devel libQt5PrintSupport-devel libQt5Script-devel libQt5SerialPort-devel libQt5Sql-devel libQt5Svg-devel libQt5Test-devel libQt5UiTools-devel libQt5Widgets-devel libQt5Xml-devel grass-devel libQt5Sql-private-headers-devel libQt5Sql5-postgresql libexiv2-devel libqscintilla_qt5-devel libspatialindex-devel libzstd-devel ocl-icd-devel opencl-cpp-headers python3-future python3-pygments SQLite-devel update-desktop-files python3-pyqt-builder geos-devel flex proj-devel gdal-devel libspatialite-devel postgresql14-server-devel
3) 安装 python 的相关包
sudo pip3.10 install PyQt5==5.15.2 PyQt3D==5.15.2 qscintilla==2.12.0 owslib PyYAML numpy jinja2 pygments psycopg2
因为了 Leap 的 QT 版本为 5.15.2,所以 pyqt5 的版本必须符合,同理 qscintilla。GDAL 不能通过 pip 直接安装,需要在 pypi 下载 tar 文件,下载到本地,然后执行 sudo python3.10 setup.py install 进行安装。
4) grass 8.2 的 rpm 包生成
Show Application:Geo / grass - openSUSE Build Service 下载 grass.spec 文件,放在 rpmbuild/spec 目录下,进行对应的修改。

    #
    # spec file for package grass
    #
    # Copyright (c) 2021 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/
    #


    # Notice to maintainer : move this package to real lfhs
    %define	shortver 82
    # Post Leap 42 / TW
    %if 0%{?suse_version} > 1325
    BuildRequires:  wxWidgets-devel >= 3.0
    BuildRequires:  python3-wxPython
    %else
    %define _use_internal_dependency_generator 0
    %define __find_requires %wx_requires
    # Don't work for SUSE Linux Enterprise why ?
    # BuildRequires:  python-wxWidgets >= 2.8
    BuildRequires:  wxWidgets-devel >= 2.8
    %endif
    Name:           grass
    Version:        8.2.0
    Release:        0
    Summary:        Geographic Resources Analysis Support System
    License:        GPL-2.0-or-later
    Group:          Productivity/Scientific/Other
    URL:            https://grass.osgeo.org/
    Source:         https://grass.osgeo.org/grass%{shortver}/source/%{name}-%{version}.tar.gz
    Source1:        https://grass.osgeo.org/grass%{shortver}/source/%{name}-%{version}.md5sum
    #BuildRequires:  -post-build-checks
    BuildRequires:  bison
    BuildRequires:  blas-devel
    BuildRequires:  fdupes
    BuildRequires:  fftw3-devel
    BuildRequires:  flex
    BuildRequires:  freetype2-devel
    BuildRequires:  gcc-c++
    BuildRequires:  lapack-devel
    BuildRequires:  libXmu-devel
    BuildRequires:  libbz2-devel
    BuildRequires:  libgdal-devel >= 3
    BuildRequires:  libgeos-devel >= 3
    BuildRequires:  libjpeg-devel
    BuildRequires:  libpng-devel
    BuildRequires:  libtiff-devel
    BuildRequires:  libzstd-devel
    BuildRequires:  man
    BuildRequires:  mysql-devel
    BuildRequires:  ncurses-devel >= 5.5
    BuildRequires:  netcdf-devel
    BuildRequires:  perl
    BuildRequires:  postgresql-devel
    BuildRequires:  proj >= 6
    BuildRequires:  proj-devel >= 6
    BuildRequires:  python3-dateutil
    BuildRequires:  python3-devel
    BuildRequires:  python3-numpy
    BuildRequires:  python3-opengl
    BuildRequires:  python3-six
    BuildRequires:  python3-xml
    BuildRequires:  SQLite-devel
    BuildRequires:  unixODBC-devel
    BuildRequires:  xorg-x11-Mesa-devel
    BuildRequires:  zlib-devel
    Requires:       fftw3
    Requires:       proj >= 6
    Requires:       python3
    Requires:       python3-dateutil
    Requires:       python3-numpy
    Requires:       python3-opengl
    Requires:       python3-xml
    Requires:       SQLite >= 3
    Requires:       unixODBC
    Requires:       xterm
    Recommends:     grass-doc
    Obsoletes:      grass7
    %if 0%{?suse_version} >= 1550
    Requires:       python3-wxPython
    %else
    Requires:       python-wxWidgets >= 2.8
    %endif

    %package doc
    Summary:        Documentation for GRASS GIS 8.2
    Group:          Documentation/Other

    %package devel
    Summary:        Development files for GRASS GIS 8.2
    Group:          Development/Libraries/C and C++
    Requires:       grass = %{version}

    %description
    GRASS (Geographic Resources Analysis Support System), commonly
    referred to as GRASS, is a Geographic Information System
    (GIS) used for geospatial data management and analysis, image
    processing, graphics/maps production, spatial modeling, and
    visualization. GRASS is currently used in academic and commercial
    settings around the world, as well as by many governmental agencies
    and environmental consulting companies.

    %description devel
    This package contains the development files for GRASS GIS

    %description doc
    This package contains the HTML documentation files for GRASS GIS

    %prep
    %setup -q -n grass-%{version}

    %define grasver -@GRASS_VERSION_MAJOR@.@GRASS_VERSION_MINOR@.@GRASS_VERSION_RELEASE@
    %define grasver2 '-${GRASS_VERSION_MAJOR}.${GRASS_VERSION_MINOR}.${GRASS_VERSION_RELEASE}'

    sed -i s/%{grasver}//g include/Make/Platform.make.in
    sed -i s/%{grasver}//g grass.pc.in
    sed -i s/%{grasver2}//g configure
    sed -i s/%{grasver2}//g Makefile

    %define grassprefix %{_libdir}
    %define grassdir %{grassprefix}/%{name}%{shortver}
    %define grasslib %{grassprefix}/%{name}%{shortver}/lib

    # configure with shared libs:
    # Pick for upstream travis, normal optflags are not supported
    export CFLAGS="-O2 -Werror=implicit-function-declaration"

    ./configure \
        --prefix=%{grassprefix} \
        --enable-shared \
        --enable-socket \
        --enable-largefile \
        --with-blas \
        --with-cairo --with-cairo-ldflags=-lfontconfig \
        --with-curses \
        --with-cxx \
        --with-fftw \
        --with-freetype --with-freetype-includes=%{_includedir}/freetype2 \
        --with-gdal=%{_bindir}/gdal-config \
        --with-geos \
        --with-lapack \
        --with-motif \
        --with-mysql --with-mysql-includes=%{_includedir}/mysql \
        --with-netcdf \
        --with-nls \
        --with-odbc \
        --with-openmp \
        --with-postgres --with-postgres-includes=%{_includedir}/pgsql \
        --with-proj-share=%{_datadir}/proj \
        --with-pthread \
        --with-python \
        --with-bzlib \
        --with-x \
        --with-zstd \
        --with-sqlite \
        --with-wxwidgets

    # rpmlint: wrong-script-interpreter /usr/bin/env python3
    find . -type f -exec sed -i -e 's:  #!%{_bindir}/env python3:  #!%{_bindir}/python3:g' {} +

    %build
    make prefix=%{grassprefix} PREFIX=%{grassprefix} %{?_smp_mflags}

    %install
    make prefix=%{buildroot}%{grassprefix} PREFIX=%{buildroot}%{grassprefix} install

    # Program sets LD_LIBRARY_PATH pointing to in-source path
    # resulting in wrong requires, prevent that
    rm -rf dist.*

    # don't create a non-standard-directory for a single file
    mkdir -p %{buildroot}%{_bindir}
    # 后添加的,否则没有 grass82
    mv %{buildroot}%{grassprefix}/bin/grass %{buildroot}%{grassprefix}/bin/grass%{shortver}
    mv %{buildroot}%{grassprefix}/bin/grass%{shortver} %{buildroot}%{_bindir}
    rmdir %{buildroot}%{grassprefix}/bin

    # changing GISBASE in startup script (deleting %%{buildroot} from path)
    sed -i s:%{buildroot}::g %{buildroot}%{_bindir}/grass%{shortver}
    sed -i s:%{buildroot}::g %{buildroot}%{grassdir}/include/Make/Grass.make
    sed -i s:%{buildroot}::g %{buildroot}%{grassdir}/include/Make/Platform.make
    sed -i s:%{buildroot}::g %{buildroot}%{grassdir}%{_sysconfdir}/fontcap
    # Make symlinks in /usr/bin/
    install -d %{buildroot}%{_bindir}/
    pushd %{buildroot}%{_bindir}/
    ln -fsv grass%{shortver} grass
    popd

    # make grass libraries available on the system
    install -d %{buildroot}%{_sysconfdir}/ld.so.conf.d
    echo %{grasslib} >> %{buildroot}%{_sysconfdir}/ld.so.conf.d/grass-%{version}.conf

    mkdir -p %{buildroot}%{_datadir}/applications
    cp  %{buildroot}%{grassdir}/share/applications/grass.desktop %{buildroot}%{_datadir}/applications/grass.desktop
    mkdir -p %{buildroot}%{_datadir}/pixmaps
    ln -s %{grassdir}/share/icons/hicolor/192x192/apps/grass.png %{buildroot}%{_datadir}/pixmaps/grass.png

    rm -rf %{buildroot}%{_libdir}/grass%{shortver}/tools/__pycache__

    echo %{grassdir} >%{buildroot}/%{_sysconfdir}/GRASSDIR

    %fdupes -s %{buildroot}%{grassdir}

    %files devel
    %defattr(-,root,root)
    %{grassdir}/include
    %{grasslib}/*.a
    %{_sysconfdir}/GRASSDIR

    %files doc
    %defattr(-,root,root)
    %{grassdir}/docs

    %files
    %defattr(-,root,root)
    %config %{_sysconfdir}/ld.so.conf.d/grass-%{version}.conf
    %{_bindir}/%{name}
    %{_bindir}/%{name}%{shortver}
    %{grassdir}/bin/*
    %{grassdir}%{_sysconfdir}/*
    %{grassdir}/gui/*
    %{grassdir}/scripts/*
    %{grassdir}/share/applications/grass.desktop
    %{grassdir}/share/icons/hicolor/*
    %{grassdir}/share/metainfo/org.osgeo.grass.appdata.xml
    %{_datadir}/applications/grass.desktop
    %{_datadir}/pixmaps/grass.png
    %lang(ar) %{grassdir}/locale/ar/LC_MESSAGES/*.mo
    %lang(bn) %{grassdir}/locale/bn/LC_MESSAGES/*.mo
    %lang(cs) %{grassdir}/locale/cs/LC_MESSAGES/*.mo
    %lang(de) %{grassdir}/locale/de/LC_MESSAGES/*.mo
    %lang(el) %{grassdir}/locale/el/LC_MESSAGES/*.mo
    %lang(es) %{grassdir}/locale/es/LC_MESSAGES/*.mo
    %lang(fr) %{grassdir}/locale/fr/LC_MESSAGES/*.mo
    %lang(fi) %{grassdir}/locale/fi/LC_MESSAGES/*.mo
    %lang(hu) %{grassdir}/locale/hu/LC_MESSAGES/*.mo
    %lang(id) %{grassdir}/locale/id_ID/LC_MESSAGES/*.mo
    %lang(it) %{grassdir}/locale/it/LC_MESSAGES/*.mo
    %lang(ja) %{grassdir}/locale/ja/LC_MESSAGES/*.mo
    %lang(ko) %{grassdir}/locale/ko/LC_MESSAGES/*.mo
    %lang(lv) %{grassdir}/locale/lv/LC_MESSAGES/*.mo
    %lang(ml) %{grassdir}/locale/ml/LC_MESSAGES/*.mo
    %lang(pl) %{grassdir}/locale/pl/LC_MESSAGES/*.mo
    %lang(pt) %{grassdir}/locale/pt/LC_MESSAGES/*.mo
    %lang(pt_br) %{grassdir}/locale/pt_BR/LC_MESSAGES/*.mo
    %lang(ru) %{grassdir}/locale/ru/LC_MESSAGES/*.mo
    %lang(ro) %{grassdir}/locale/ro/LC_MESSAGES/*.mo
    %lang(sl) %{grassdir}/locale/sl/LC_MESSAGES/*.mo
    %lang(sl) %{grassdir}/locale/si/LC_MESSAGES/*.mo
    %lang(ta) %{grassdir}/locale/ta/LC_MESSAGES/*.mo
    %lang(th) %{grassdir}/locale/th/LC_MESSAGES/*.mo
    %lang(tr) %{grassdir}/locale/tr/LC_MESSAGES/*.mo
    %lang(sl) %{grassdir}/locale/uk/LC_MESSAGES/*.mo
    %lang(vi) %{grassdir}/locale/vi/LC_MESSAGES/*.mo
    %lang(zh) %{grassdir}/locale/zh/LC_MESSAGES/*.mo
    %lang(zh_cn) %{grassdir}/locale/zh_CN/LC_MESSAGES/*.mo
    %{grassdir}/driver/*
    %{grassdir}/fonts/*
    %{grassdir}/utils/*
    %{grasslib}/*.so
    %{grassdir}/AUTHORS
    %{grassdir}/translators.csv
    %{grassdir}/translation_status.json
    %{grassdir}/contributors*
    %{grassdir}/CHANGES
    %{grassdir}/COPYING
    %{grassdir}/GPL.TXT
    %{grassdir}/REQUIREMENTS.html
    %{grassdir}/CITING
    %{grassdir}/INSTALL
    %exclude %{grassdir}/demolocation

    %post -p /sbin/ldconfig

    %postun -p /sbin/ldconfig

    %changelog
  1. 下载文件
    https://grass.osgeo.org/grass82/source/grass-8.2.0.tar.gz
    https://grass.osgeo.org/grass82/source/grass-8.2.0.md5sum
    放到 rpmbuild/source 目录下
  2. 运行 rpmbuild /home/user/rpmbuild/SPECS/grass.spec -bb 生成对应的 rpm 包,rpm 包自动生成在 rpmbuild/RPMS 目录下
  3. 先将 Leap 的 grass 7.8 删除,然后即可进行 grass 8.2 的安装。

3.qgis ltr 的编译
1).从 Show Application:Geo / qgis-ltr - openSUSE Build Service 下载 qgis-ltr.spec 文件,放到 rpmbuild/SPECS/下,进行必要的修改。

    #
    # spec file for package qgis-ltr
    #
    # 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 is_ltr 1

    %bcond_without grass
    %if %is_ltr
    Name:           qgis-ltr
    %else
    Name:           qgis
    %endif
    Version:        3.22.9
    Release:        0
    Summary:        A Geographic Information System (GIS)
    License:        GPL-2.0-only
    Group:          Productivity/Graphics/Visualization/Other
    URL:            https://qgis.org/
    Source:         https://qgis.org/downloads/qgis-%{version}.tar.bz2
    Source1:        https://qgis.org/downloads/qgis-%{version}.tar.bz2.sha256
    Source2:        %{name}.rpmlintrc
    Source3:        qgis_sample_data.zip
    Patch1:         fix-fastcgi-include.patch
    # PATCH-FIX-UPSTREAM - scan for pdal-config instead of pdal in cmake
    Patch2:         qgis-fix-cmake-findpdal.patch
    BuildRequires:  FastCGI-devel
    BuildRequires:  PDAL-devel
    BuildRequires:  bison >= 2.4
    BuildRequires:  cmake >= 3.0.0
    BuildRequires:  fdupes
    BuildRequires:  filesystem
    BuildRequires:  flex >= 2.5.6
    BuildRequires:  geos-devel >= 3.4
    BuildRequires:  libQt5Sql-private-headers-devel
    BuildRequires:  libQt5Sql5-mysql
    BuildRequires:  libQt5Sql5-postgresql
    # Add the 3 main db we should access
    # also have them in requires
    BuildRequires:  libQt5Sql5-sqlite
    BuildRequires:  libexiv2-devel
    BuildRequires:  libqscintilla_qt5-devel
    BuildRequires:  libspatialindex-devel
    BuildRequires:  libzstd-devel
    BuildRequires:  ocl-icd-devel
    BuildRequires:  opencl-cpp-headers
    BuildRequires:  pkgconfig
    BuildRequires:  poppler-tools
    BuildRequires:  protobuf-devel
    BuildRequires:  python3-GDAL
    BuildRequires:  python3-Jinja2
    BuildRequires:  python3-OWSLib
    BuildRequires:  python3-PyYAML
    BuildRequires:  python3-future
    BuildRequires:  python3-psycopg2
    BuildRequires:  python3-pygments
    BuildRequires:  python3-pyqt-builder
    BuildRequires:  python3-qscintilla-qt5
    BuildRequires:  python3-qscintilla-qt5-sip
    BuildRequires:  python3-qt5-devel
    BuildRequires:  python3-sip-devel
    BuildRequires:  python3-six
    BuildRequires:  python3-termcolor
    BuildRequires:  qwt6-devel
    BuildRequires:  sqlite-devel >= 3.12.0
    BuildRequires:  unzip
    BuildRequires:  update-desktop-files
    BuildRequires:  cmake(Qt53DAnimation)
    BuildRequires:  cmake(Qt53DCore)
    BuildRequires:  cmake(Qt53DExtras)
    BuildRequires:  cmake(Qt53DInput)
    BuildRequires:  cmake(Qt53DLogic)
    BuildRequires:  cmake(Qt53DQuick)
    BuildRequires:  cmake(Qt53DQuickAnimation)
    BuildRequires:  cmake(Qt53DQuickExtras)
    BuildRequires:  cmake(Qt53DQuickInput)
    BuildRequires:  cmake(Qt53DQuickRender)
    BuildRequires:  cmake(Qt53DQuickScene2D)
    BuildRequires:  cmake(Qt53DRender)
    BuildRequires:  cmake(Qt5Concurrent)
    BuildRequires:  cmake(Qt5Core)
    BuildRequires:  cmake(Qt5DBus)
    BuildRequires:  cmake(Qt5Gui)
    BuildRequires:  cmake(Qt5Keychain) >= 0.5
    BuildRequires:  cmake(Qt5Network)
    BuildRequires:  cmake(Qt5Positioning)
    BuildRequires:  cmake(Qt5PrintSupport)
    BuildRequires:  cmake(Qt5Script)
    BuildRequires:  cmake(Qt5SerialPort)
    BuildRequires:  cmake(Qt5Sql)
    BuildRequires:  cmake(Qt5Svg)
    BuildRequires:  cmake(Qt5Test)
    BuildRequires:  cmake(Qt5UiTools)
    BuildRequires:  cmake(Qt5Widgets)
    BuildRequires:  cmake(Qt5Xml)
    BuildRequires:  pkgconfig(expat) >= 1.95
    # Requires at least gdal 3.1 for GeoTIFF and Proj >= 6 - https://github.com/qgis/QGIS/issues/36699#issuecomment-633539864
    BuildRequires:  pkgconfig(gdal) >= 3.1
    BuildRequires:  pkgconfig(Qt5Qwt6)
    BuildRequires:  pkgconfig(gsl) >= 1.8
    BuildRequires:  pkgconfig(libpq) > 9.4
    BuildRequires:  pkgconfig(libzip)
    BuildRequires:  pkgconfig(pdal) >= 2.2.0
    BuildRequires:  pkgconfig(proj) >= 6.3.1
    #BuildRequires:  pkgconfig(python3) >= 3.7
    BuildRequires:  pkgconfig(qca2-qt5)
    BuildRequires:  pkgconfig(spatialite) >= 4.2.0
    # Force requires of those 3 main component.
    Requires:       libQt5Sql5-mysql
    Requires:       libQt5Sql5-postgresql
    Requires:       libQt5Sql5-sqlite
    # proj.db is required
    Requires:       proj
    Requires:       pdal
    Requires:       python3-GDAL
    Requires:       python3-Jinja2
    Requires:       python3-OWSLib
    Requires:       python3-PyYAML
    Requires:       python3-Pygments
    Requires:       python3-future
    Requires:       python3-psycopg2
    # Those are not picked by obs
    Requires:       python3-qscintilla-qt5
    Requires:       python3-six
    Requires:       python3-termcolor
    Recommends:     %{name}-sample-data
    Recommends:     apache2-mod_fcgid
    Recommends:     gpsbabel
    Recommends:     mod_spatialite
    # It's in Application:Geo, but not in Factory
    Suggests:       saga-gis
    %if %is_ltr
    Conflicts:      qgis
    %else
    Conflicts:      qgis-ltr
    %endif
    Conflicts:      qgis-master
    Obsoletes:      qgis2 < %{version}

    %if %{with grass}
    BuildRequires:  grass-devel >= 8.2
    %endif

    %ifarch ppc64le
    BuildRequires:  memory-constraints
    %endif

    %package devel
    Summary:        Development Libraries for QGIS
    Group:          Development/Libraries/C and C++
    Requires:       %{name} = %{version}
    Requires:       python3-qt5-devel
    %if %{with grass}
    %package plugin-grass
    Summary:        GRASS Support Libraries for QGIS
    Group:          Productivity/Graphics/Visualization/Other
    Requires:       %{name} = %{version}
    Requires:       grass >= 8.2
    Requires:       grass-doc
    Obsoletes:      %{name}-plugin-grass < %{version}

    %description plugin-grass
    GRASS plugin for QGIS required to interface with GRASS system.
    %endif

    %package sample-data
    %define sampledir sample-data
    Summary:        QGIS sample data
    Group:          Productivity/Graphics/Visualization/Other
    BuildArch:      noarch

    %description
    QGIS is a Geographic Information System (GIS). QGIS supports vector,
    raster, OWS and database formats. QGIS can be used to browse and
    create map data on the computer. It supports many common spatial data
    formats (e.g. ESRI ShapeFile, geotiff). QGIS supports plugins to do
    things like display tracks from a GPS.

    %description devel
    Development packages for QGIS, including the C header files.

    %description sample-data
    QGIS sample data with raster, vector, gps files and a GRASS location from the Alaska area.

    %prep
    %autosetup -p1 -n qgis-%{version}
    # Remove bad env and python version in grass plugin
    sed -i 's,^#!%{_bindir}/env python$,#!%{_bindir}/python3,g' src/plugins/grass/scripts/*.py
    sed -i 's,^#!%{_bindir}/env python3$,#!%{_bindir}/python3,g' src/plugins/grass/scripts/*.py

    %build
    %define _lto_cflags %{nil}

    export CFLAGS="%{optflags}"
    export QTDIR=%{_prefix}
    export PATH=$PATH:$QTDIR/bin

    %cmake \
    -DQGIS_LIB_SUBDIR=%{_lib} \
    -DWITH_3D=TRUE \
    -DWITH_BINDINGS=TRUE \
    -DWITH_GRASS=TRUE \
    -DGRASS_PREFIX8=`cat %{_sysconfdir}/GRASSDIR` \
    -DWITH_QSPATIALITE=TRUE \
    -DWITH_SERVER=TRUE \
    -DWITH_SERVER_PLUGINS=TRUE \
    -DWITH_POSTGRESQL=TRUE \
    -DWITH_PDAL=TRUE \
    -DWITH_QTWEBKIT=FALSE \
    -DFCGI_INCLUDE_DIR=%{_includedir}/fastcgi \
    -DPOSTGRES_LIBRARY=%{_libdir}/libpq.so \
    -DPOSTGRES_INCLUDE_DIR=%{_includedir}/pgsql \
    -DQGIS_PLUGIN_SUBDIR=%{_lib}/qgis \
    -DQGIS_MANUAL_SUBDIR=share/man \
    -DQWT_INCLUDE_DIR=%{_includedir}/qt5/qwt6 \
    -DQCA_INCLUDE_DIR=%{_includedir}/qt5/Qca-qt5/QtCrypto \
    -DCMAKE_SKIP_RPATH=OFF \
    -DOpenCL_INCLUDE_DIR=%{_includedir} \
    -Wno-dev

    export QTDIR=%{_prefix}
    export PATH=$PATH:$QTDIR/bin
    %ifarch ppc64le
    # avoid OOM failure on power8-01 builder
    %limit_build -m 1300
    %endif
    %make_jobs

    %install
    %cmake_install

    mkdir -p %{buildroot}%{_datadir}/pixmaps
    ln -s ../qgis/images/icons/qgis-icon-512x512.png %{buildroot}/%{_datadir}/pixmaps/qgis.png

    # Rename .desktop file
    mv %{buildroot}%{_datadir}/applications/org.qgis.qgis.desktop %{buildroot}%{_datadir}/applications/%{name}.desktop

    # Install sample data
    pushd %{buildroot}%{_datadir}/qgis
    unzip %{SOURCE3}
    mv qgis_sample_data %{sampledir}
    find %{sampledir} -depth \( -name .tmp -o -name .bash\* -o -name \*~ \) -exec rm -r {} +
    popd

    %fdupes -s %{buildroot}

    %post -p /sbin/ldconfig
    %postun -p /sbin/ldconfig

    %post plugin-grass -p /sbin/ldconfig
    %postun plugin-grass -p /sbin/ldconfig

    %files
    %{_bindir}/*
    %{_libdir}/libqgis*so*
    %{_libdir}/qt5/plugins/sqldrivers/libqsqlspatialite.so
    %{_mandir}/man1/*
    %{_datadir}/qgis
    %{_datadir}/applications/%{name}.desktop
    %{_datadir}/pixmaps/qgis.png
    # Own directories for icon size not provided by hicolor-icon-theme
    %dir %{_datadir}/icons/hicolor/42x42
    %dir %{_datadir}/icons/hicolor/42x42/apps
    %dir %{_datadir}/icons/hicolor/42x42/mimetypes
    %dir %{_datadir}/icons/hicolor/80x80
    %dir %{_datadir}/icons/hicolor/80x80/apps
    %dir %{_datadir}/icons/hicolor/80x80/mimetypes
    %dir %{_datadir}/icons/hicolor/8x8
    %dir %{_datadir}/icons/hicolor/8x8/apps
    %dir %{_datadir}/icons/hicolor/8x8/mimetypes
    %{_datadir}/icons/hicolor/*/apps/*.png
    %{_datadir}/icons/hicolor/*/apps/*.svg
    %{_datadir}/icons/hicolor/*/mimetypes/*.png
    %{_datadir}/icons/hicolor/*/mimetypes/*.svg
    %{_datadir}/metainfo/org.qgis.qgis.appdata.xml
    %dir %{_libdir}/qgis/
    %{_libdir}/qgis/*
    %if %{with grass}
    %exclude %{_libdir}/libqgisgrass8.so
    %exclude %{_libdir}/libqgisgrass8.so.*
    %exclude %{_libdir}/qgis/libgrassplugin8.so
    %exclude %{_libdir}/qgis/libprovider_grass8.so
    %exclude %{_libdir}/qgis/libprovider_grassraster8.so
    %exclude %{_libdir}/qgis/grass
    %endif
    %exclude %{_datadir}/qgis/%{sampledir}
    %license COPYING
    %doc BUGS README.md

    %files devel
    %{_includedir}/qgis/

    %if %{with grass}
    %files plugin-grass
    %{_libdir}/qgis/libgrassplugin8.so
    %{_libdir}/qgis/libprovider_grass8.so
    %{_libdir}/qgis/libprovider_grassraster8.so
    %{_libdir}/libqgisgrass8.so
    %{_libdir}/libqgisgrass8.so.*
    %defattr(755,root,root)
    %{_libdir}/qgis/grass
    %endif

    %files sample-data
    %dir %{_datadir}/qgis
    %{_datadir}/qgis/%{sampledir}

    %changelog
  1. 下载文件
    https://download.qgis.org/downloads/qgis-3.22.9.tar.bz2
    https://download.qgis.org/downloads/qgis-3.22.9.tar.bz2.sha256
    File fix-fastcgi-include.patch of Package qgis-ltr - openSUSE Build Service
    File qgis-fix-cmake-findpdal.patch of Package qgis-ltr - openSUSE Build Service
    放到 rpmbuild/source 目录下

  2. 运行 rpmbuild /home/user/rpmbuild/SPECS/qgis.spec -bb 生成对应的 rpm 包,rpm 包自动生成在 rpmbuild/RPMS 目录下

  3. 问题解决。
    (1) Exiv2::unsignedLongLong 找不到错误
    使用 https://download.opensuse.org/repositories/graphics/15.4/作为源,更新 exiv2-0.27.5 版本即可。
    (2) 编译过程中出现’core/core.sip’ could not be found 错误。
    我的 pyqt5 安装后,出现在/usr/local/lib64/python3.10/site-packages/目录下,所以,使用以下命令解决问题

     ln -s  /usr/local/lib64/python3.10/site-packages /usr/lib64/python3.10/site-packages
    

(3) 编译后运行 qgis 出现错误
Couldn’t load SIP module.
Python support will be disabled.

        Traceback (most recent call last):
        File "", line 1, in 
        File "/usr/share/qgis/python/qgis/__init__.py", line 78, in 
            from qgis.PyQt import QtCore
        File "/usr/share/qgis/python/qgis/PyQt/QtCore.py", line 24, in 
            from PyQt5.QtCore import *
        ImportError: /usr/lib64/libQt5Core.so.5: version `Qt_5_PRIVATE_API' not found (required by /usr/local/lib64/python3.10/site-packages/PyQt5/QtCore.abi3.so)
    使用一下命令解决问题
    export LD_LIBRARY_PATH="/usr/local/lib64/python3.10/site-packages/PyQt5/Qt/lib:/usr/local/lib64/python3.10/site-packages/PyQt5/Qt5/lib:/usr/local/lib64/python3.10/site-packages/PyQt5/Qt5/plugins:$LD_LIBRARY_PATH"

4.参考了 anaconda 中的 qgis 脚本。

前边的,我没验证,不过,后边的 ln 命令这块,我编译的时候,是没有系统的包在里边,因为 15.4 缺省的是 3.6。qgis 需要的 python 缺省要大于 3.7。有时间我去验证一下。这个断断续续呀做了 1 个月。这里边,可能还有问题,缺省编译的时候,用的版本,比如 psycopg2,也安装了 2 次。
只是说现在好用了。