OpenSUSE 13: Install cmake 3.6

This article will describe installing cmake 3.6 with Fedora 25's src.rpm.

1 Install jsoncpp-devel

cmake 3.6 in Fedora 25 needs jsoncpp-devel. Because jsoncpp is in packman repository, add packman repository.

> sudo zypper ar -f http://packman.inode.at/suse/openSUSE_13.2/ packman
> sudo zypper -n --gpg-auto-import-keys up

2 Install cmake 3.6

Download Fedora 25's src.rpm.

> F=https://dl.fedoraproject.org/pub/fedora/linux/releases/25
> wget -q ${F}/Everything/source/tree/Packages/c/cmake-3.6.2-6.fc25.src.rpm
> rpm -i cmake-3.6.2-6.fc25.src.rpm
> cd ~/rpmbuild

Change BuildRequires package name from Fedora 25 to OpenSUSE 13.

> B="BuildRequires:"
> sed -e "s/^${B}\( *\)qt-devel/${B}\1libqt4-devel/g" \
    -e "s/^${B}\( *\)pkgconfig(Qt5)/${B}\1patterns-openSUSE-devel_qt5/g" \
    -e "s/^${B}\( *\)bzip2-devel/${B}\1libbz2-devel/g" \
    -e "s/^${B}\( *\)expat-devel/${B}\1libexpat-devel/g" \
    -e "s/^${B}\( *\)gcc-gfortran/${B}\1gcc-fortran/g" \
    -e "s/^${B}\( *\)libarchive3-devel/${B}\1libarchive-devel/g" \
    -e "s/^${B}\( *\)python2-devel/${B}\1python-devel/g" \
    -e "s/^${B}\( *\)python%{python3_pkgversion}-devel/${B}\1python3-devel/g" \
    -e "s;^${B}\( *\)/usr/bin/sphinx-build;#${B}\1/usr/bin/sphinx-build;g" \
    -i SPECS/cmake.spec

Make the condition for Fedora's RPM macro to be always true. This is because packing will be error when this condition is false.

> sed -e 's/%if 0%{?fedora} || 0%{?rhel} >= 7/%if 1/g' -i SPECS/cmake.spec

Fedora 25's %_docdir is /usr/share/doc and OpenSUSE 13's /usr/share/doc/package. This will cause packing error. Change %_docdir to /usr/share/doc.

> sed -e 's;%{_docdir};/usr/share/doc;g' -i SPECS/cmake.spec

OpenSUSE 13 does not have /usr/lib/rpm/macros.d/macros.emacs. Change RPM macro in /usr/lib/rpm/macros.d/macros.emacs to command.

> sed -e "s;%{_emacs_bytecompile};/usr/bin/emacs -batch --no-init-file \
--no-site-file --eval '(progn (setq load-path (cons \".\" load-path)))' \
-f batch-byte-compile;g" \
    -e 's;%{_emacs_sitelispdir};/usr/share/emacs/site-lisp;g' \
    -e 's;%{_emacs_sitestartdir};/usr/share/emacs/site-lisp/site-start.d;g' \
    -i SPECS/cmake.spec

Remove emacs-filesystem from Requires package which OpenSUSE 13 does not have.

> sed -e 's/Requires: emacs-filesystem\(.*\)/#Requires: emacs-filesystem\1/g' \
    -i SPECS/cmake.spec

Install BuildRequires packages. jsoncpp-devel will be installed.

> sudo zypper -n in $(grep "^${B}" SPECS/cmake.spec | \
                       sed -e "s/^${B}//g" -e 's/,/ /g')

Fedora and Ubuntu have /usr/include/form.h which is same with /usr/include/ncurses/form.h. But OpenSUSE 13 does not have. Create symbolic link /usr/include/form.h to /usr/include/ncurses/form.h.

> sudo ln -s /usr/include/ncurses/form.h /usr/include/

Because OpenSUSE 13's python-sphinx cannot generate html in cmake 3.6, run rpmbuild with –without sphinx. This will take 30 minutes.

> rpmbuild -ba SPECS/cmake.spec --without sphinx

Install cmake 3.6.

> sudo zypper -n in RPMS/noarch/cmake-*.rpm RPMS/x86_64/cmake-*.rpm

3 Script for installing cmake 3.6

The following script will install cmake 3.6.

#!/bin/sh


# Need jsoncpp in packman.
sudo zypper ar -f http://packman.inode.at/suse/openSUSE_13.2/ packman
sudo zypper -n --gpg-auto-import-keys up

# Download Fedora 25 src.rpm.
F=https://dl.fedoraproject.org/pub/fedora/linux/releases/25
wget -q ${F}/Everything/source/tree/Packages/c/cmake-3.6.2-6.fc25.src.rpm
rpm -i cmake-3.6.2-6.fc25.src.rpm
cd ~/rpmbuild

# Replace package names from Fedora 25 to OpenSUSE 13.
B="BuildRequires:"
sed -e "s/^${B}\( *\)qt-devel/${B}\1libqt4-devel/g" \
    -e "s/^${B}\( *\)pkgconfig(Qt5)/${B}\1patterns-openSUSE-devel_qt5/g" \
    -e "s/^${B}\( *\)bzip2-devel/${B}\1libbz2-devel/g" \
    -e "s/^${B}\( *\)expat-devel/${B}\1libexpat-devel/g" \
    -e "s/^${B}\( *\)gcc-gfortran/${B}\1gcc-fortran/g" \
    -e "s/^${B}\( *\)libarchive3-devel/${B}\1libarchive-devel/g" \
    -e "s/^${B}\( *\)python2-devel/${B}\1python-devel/g" \
    -e "s/^${B}\( *\)python%{python3_pkgversion}-devel/${B}\1python3-devel/g" \
    -e "s;^${B}\( *\)/usr/bin/sphinx-build;#${B}\1/usr/bin/sphinx-build;g" \
    -i SPECS/cmake.spec

# Packing will be error when '%if 0%{?fedora} || 0%{?rhel} >= 7' is false.
# This is Fedora's problem.
sed -e 's/%if 0%{?fedora} || 0%{?rhel} >= 7/%if 1/g' -i SPECS/cmake.spec

# Fedora 25's %_docdir is /usr/share/doc and OpenSUSE 13's is
# /usr/share/doc/package. This causes packing error.
sed -e 's;%{_docdir};/usr/share/doc;g' -i SPECS/cmake.spec

# OpenSUSE 13 does not have /usr/lib/rpm/macros.d/macros.emacs.
sed -e "s;%{_emacs_bytecompile};/usr/bin/emacs -batch --no-init-file \
--no-site-file --eval '(progn (setq load-path (cons \".\" load-path)))' \
-f batch-byte-compile;g" \
    -e 's;%{_emacs_sitelispdir};/usr/share/emacs/site-lisp;g' \
    -e 's;%{_emacs_sitestartdir};/usr/share/emacs/site-lisp/site-start.d;g' \
    -i SPECS/cmake.spec

# Remove emacs-filesystem from cmake-data's dependencies.
sed -e 's/Requires: emacs-filesystem\(.*\)/#Requires: emacs-filesystem\1/g' \
    -i SPECS/cmake.spec

# Install BuildRequires packages.
sudo zypper -n in $(grep "^${B}" SPECS/cmake.spec | \
                       sed -e "s/^${B}//g" -e 's/,/ /g')

# Fedora and Ubuntu have /usr/include/form.h.
# This might be OpenSUSE 13's issue.
sudo ln -s /usr/include/ncurses/form.h /usr/include/

# Build and install rpm. sphinx-build cannot build html.
# Use rpmbuild with "--without sphinx".
rpmbuild -ba SPECS/cmake.spec --without sphinx

# Install cmake.
sudo zypper -n in RPMS/noarch/cmake-*.rpm RPMS/x86_64/cmake-*.rpm