|
| 1 | +# Building KchmViewer |
| 2 | + |
| 3 | +- [Dependencies and Tools](#dependencies-and-tools) |
| 4 | +- [Getting sources](#getting-sources) |
| 5 | +- [Usage CMake](#usage-cmake) |
| 6 | +- [Building in Debian](#building-in-debian) |
| 7 | +- [Qmake options](#qmake-options) |
| 8 | + |
| 9 | + |
| 10 | +## Dependencies and Tools |
| 11 | + |
| 12 | + |
| 13 | +### Mandatory requirements |
| 14 | + |
| 15 | +- C++11 compiler which is supported by the [Qt SDK][1]. |
| 16 | +- Qt tools such as `moc` and the resource packer. |
| 17 | +- `CMake` or `Qmake` to generate the build scripts. For builds I recommend CMake, and Qmake is mainly used as a Qt Creator project. |
| 18 | +- SDK for `Qt 4`, `Qt 5` or `KDE 4`. |
| 19 | +- The [CHMLib][2] library for handling chm files. You can choose dynamic or static linking. In the first case, you need a library and headers for development. In the second case you need to download the repository submodule and specify `USE_STATIC_CHMLIB` flag when generating the build script. |
| 20 | +- The [libzip][3] library and headers for software development. When building this library from source you will need the [zlib][4] library. |
| 21 | + |
| 22 | + |
| 23 | +### Optional requirements |
| 24 | + |
| 25 | +- I recommend using [Git][5] to retrieve the source code. Although you can download and unpack the archive with the sources, this option is not covered here. Also, Git is more convenient if you want to use a submodule with CHMLib. |
| 26 | +- [GNU Gettext][6] is required to translate the user interface. |
| 27 | + |
| 28 | + |
| 29 | +## Getting sources |
| 30 | + |
| 31 | +Use the `git clone` command to retrieve the sources. The `-b release` option allows you to switch to the `release` branch immediately after downloading; this branch points to the latest release. If you need static linking to CHMLib, use `--recursive` options to download the CHMLib submodule. |
| 32 | + |
| 33 | +```sh |
| 34 | +# Getting the repository together with the submodule |
| 35 | +# and switching to the release branch |
| 36 | +git clone -b release --recursive https://github.com/u-235/kchmviewer |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | +## Usage CMake |
| 41 | + |
| 42 | +A modern [cmake][7] generates an build system script and also can be used as a build and installation driver. |
| 43 | + |
| 44 | +```sh |
| 45 | +# Generate build system |
| 46 | +cmake [<options>] ../ |
| 47 | +# Bbilding mode |
| 48 | +cmake --build . [<options>] |
| 49 | +# Installation mode |
| 50 | +cmake --install . [<options>] |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +### Options of build system generation |
| 55 | + |
| 56 | +* `-G` - specifies a build system generator. This option is not necessary when using the default toolkit. |
| 57 | +* `--install-prefix <prefix>` - specifies a root folder for install application. By defaults to `/usr/local` on UNIX and `c:/Program Files/kchmviewer` on Windows. Note, that the installation prefix can be overridden when CMake is run in installation mode (`cmake --install`) with the `--prefix` option. Cpack ignores the installation prefix. |
| 58 | +* `-D <var>=<value>` - specifies the initial value of the CMake script variable. |
| 59 | + |
| 60 | + **Project-specific variables** |
| 61 | + |
| 62 | + - `FRAMEWORK=<Qt4 | Qt5 | KDE4>` - choosing the framework with which to build the application, default is `Qt5`. |
| 63 | + - `USE_STATIC_CHMLIB=<ON | OFF>` - choosing static linking with CHMLib, default is `OFF`. For static linking, the library is compiled from source in the `lib/CHMLib` folder. This folder can be obtained along with the sources of the application using the command `git clone --recursive`. |
| 64 | + - `USE_WEBENGINE=<ON | OFF>` - choosing WebEngine instead of WebKit, default is `OFF`. WebEngine requires Qt version 5.9 or higher. |
| 65 | + - `USE_GETTEXT=<ON | OFF>` - enabling translation of the application, default is `ON`. If Gettext is not available, this option will be ignored. |
| 66 | + - `USE_DEPLOY_RUNTIME=<ON | OFF>` - copying runtime dependencies for deployment, default is `OFF`. |
| 67 | + - `chmlib_ROOT=<path/to/chmlib>`- specifies an additional folder to look up the library and headers for CHMLib. The `chm_lib.h` file is expected either in the root folder or the `include` folder. The `chm` library must be either in the root folder or in the `lib` folder. |
| 68 | + - `libzip_ROOT=<path/to/libzip>`- specifies an additional folder to look up the library and headers for libzip. The `zip.h` file is expected either in the root folder or the `include` folder. The `zip` library must be either in the root folder or in the `lib` folder. |
| 69 | + |
| 70 | + **CMake-specific variables** |
| 71 | + |
| 72 | + - `CMAKE_PREFIX_PATH=<path/to/qt>` is the path to the Qt development package if it is simply unpacked or builds without installation. In my case, Qt version 5.5 is in /home/user/Qt and I use `-DCMAKE_PREFIX_PATH=~/Qt/5.5/gcc`. |
| 73 | + - `CMAKE_BUILD_TYPE=<Debug | Release | RelWithDebInfo | MinSizeRel>` |
| 74 | + |
| 75 | + For example, configure cmake to build which Qt 5.15 and WebEngine |
| 76 | + |
| 77 | + ```sh |
| 78 | + cmake -DCMAKE_PREFIX_PATH=~/Qt/5.15/gcc -DUSE_WEBENGINE=ON ../ |
| 79 | + ``` |
| 80 | + |
| 81 | + |
| 82 | +### Cpack |
| 83 | + |
| 84 | +CMake comes with a `cpack` utility for generating installers. The build scripts have basic `cpack` support, but in some cases [additional options][8] and [variables][9] may need to be specified. The [generator][10] must be specified in any case. |
| 85 | + |
| 86 | + |
| 87 | +## Building in Debian |
| 88 | + |
| 89 | +In GNU/Linux with package manager DEB-based for any build configurations you need the following packages and their dependencies: |
| 90 | + |
| 91 | +- `build-essential` `cmake` `git` `libzip-dev` |
| 92 | +- `libchm-dev` |
| 93 | +- `gettext` |
| 94 | + |
| 95 | +The table lists the required additional packages and CMake options for varios build configuration. |
| 96 | + |
| 97 | +| Configuration | Packages | CMake Options | |
| 98 | +|------------------|-------------------------------------------------|----------------------| |
| 99 | +| Qt 5 + WebKit | `qt5-default` `libqt5webkit5-dev` | | |
| 100 | +| Qt 5 + WebEngine | `qt5-default` `qtwebengine5-dev-dev` | `-DUSE_WEBENGINE=ON` | |
| 101 | +| Qt 4 | `qt4-default` `libqtwebkit-dev` | `-DFRAMEWORK=QT4` | |
| 102 | +| KDE 4 | `qt4-default` `libqtwebkit-dev` `kdelibs5-dev` | `-DFRAMEWORK=KDE4` | |
| 103 | + |
| 104 | + |
| 105 | +### Build with WebKit |
| 106 | + |
| 107 | +```sh |
| 108 | +apt install build-essential cmake git libzip-dev libchm-dev\ |
| 109 | + gettext qt5-default libqt5webkit5-dev |
| 110 | +git clone -b release --recursive https://github.com/u-235/kchmviewer |
| 111 | +mkdir kchmviewer/build |
| 112 | +cd kchmviewer/build |
| 113 | +cmake -DCMAKE_BUILD_TYPE=Release ../ |
| 114 | +cmake --build . --config Release |
| 115 | +# Optional generate package |
| 116 | +cpack -G DEB -DCPACK_DEBIAN_PACKAGE_SHLIBDEPS=ON |
| 117 | +``` |
| 118 | + |
| 119 | + |
| 120 | +### Build with WebEngine |
| 121 | + |
| 122 | +```sh |
| 123 | +apt install build-essential cmake git libzip-dev libchm-dev\ |
| 124 | + gettext qt5-default qtwebengine5-dev |
| 125 | +git clone -b release --recursive https://github.com/u-235/kchmviewer |
| 126 | +mkdir kchmviewer/build |
| 127 | +cd kchmviewer/build |
| 128 | +cmake -DCMAKE_BUILD_TYPE=Release -DUSE_WEBENGINE=ON ../ |
| 129 | +cmake --build . --config Release |
| 130 | +# Optional generate package |
| 131 | +cpack -G DEB -DCPACK_DEBIAN_PACKAGE_SHLIBDEPS=ON |
| 132 | +``` |
| 133 | + |
| 134 | + |
| 135 | +### Build with KDE4 |
| 136 | + |
| 137 | +```sh |
| 138 | +apt install build-essential cmake git libzip-dev libchm-dev\ |
| 139 | + gettext qt4-default libqtwebkit-dev kdelibs5-dev |
| 140 | +git clone -b release --recursive https://github.com/u-235/kchmviewer |
| 141 | +mkdir kchmviewer/build |
| 142 | +cd kchmviewer/build |
| 143 | +cmake -DCMAKE_BUILD_TYPE=Release -DFRAMEWORK=KDE4 ../ |
| 144 | +cmake --build . --config Release |
| 145 | +# Optional generate package |
| 146 | +cpack -G DEB -DCPACK_DEBIAN_PACKAGE_SHLIBDEPS=ON |
| 147 | +``` |
| 148 | + |
| 149 | + |
| 150 | +## Qmake options |
| 151 | + |
| 152 | +The project options for qmake are the similar to those for cmake. |
| 153 | + |
| 154 | +- `USE_STATIC_CHMLIB=1` if defined, use static CHMLib from git submodule. |
| 155 | +- `USE_WEBENGINE=1` if defined, use QtWebEngine. |
| 156 | +- `CHMLIB_ROOT=<path/to/chmlib>` folder to look up the library and headers for CHMLib. |
| 157 | +- `LIBZIP_ROOT=<path/to/libzip>`folder to look up the library and headers for libzip. |
| 158 | + |
| 159 | + |
| 160 | +[1]: https://doc.qt.io/qt-5/supported-platforms.html "Qt doc: supported platforms" |
| 161 | +[2]: https://github.com/jedwing/CHMLib "CHMLib repositoriy" |
| 162 | +[3]: https://github.com/nih-at/libzip "libzip repositoriy" |
| 163 | +[4]: https://github.com/madler/zlib "zlib repositoriy" |
| 164 | +[5]: https://git-scm.com/ "Git home page" |
| 165 | +[6]: https://www.gnu.org/software/gettext "GNU Gettext home page" |
| 166 | +[7]: https://cmake.org/cmake/help/latest/manual/cmake.1.html "Launch cmake" |
| 167 | +[8]: https://cmake.org/cmake/help/latest/manual/cpack.1.html "Launch cpack" |
| 168 | +[9]: https://cmake.org/cmake/help/latest/module/CPack.html "Cpack module" |
| 169 | +[10]: https://cmake.org/cmake/help/latest/manual/cpack-generators.7.html "cpack generators" |
0 commit comments