Files
cmake-examples/06-installer/deb/README.adoc
2017-07-02 21:39:06 +01:00

158 lines
4.5 KiB
Plaintext

= Creating deb files
:toc:
:toc-placement!:
toc::[]
# Introduction
This example shows how to generate a Linux installers using the link:https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html[deb]
format.
The files in this tutorial are below:
```
$ tree
.
├── cmake-examples.conf
├── CMakeLists.txt
├── include
│   └── Hello.h
└── src
├── Hello.cpp
└── main.cpp
```
* link:CMakeLists.txt[] - Contains the CMake commands you wish to run
* link:cmake-examples.conf[] - An example configuration file
* link:include/Hello.h[] - The header file to include
* link:src/Hello.cpp[] - A source file to compile
* link:src/main.cpp[] - The source file with main
# Concepts
## CPack Generator
A CPack Generator can be used by a `make package` target to create an installer.
In the case of Debian packages you can tell CMake to create a generator using the following:
[source,cmake]
----
set(CPACK_GENERATOR "DEB")
----
After setting various settings to describe the package you must then tell CMake to
include the CPack generator using
[source,cmake]
----
include(CPack)
----
Once included all files that would typically be installed using a `make install` target
can now be packaged into a Debian package.
## Debian Package Settings
Various settings for the package are exposed by CPack. In this example we set the
following:
[source,cmake]
----
# Set a Package Maintainer.
# This is required
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Thom Troy")
# Set a Package Version
set(CPACK_PACKAGE_VERSION ${deb_example_VERSION})
----
Which sets the maintainer and version. More debian specific settings are specified below
or at link:https://cmake.org/Wiki/CMake:CPackPackageGenerators#Debian_Generator_specific_settings[the CPack Wiki]
[cols=",",options="header",]
|=======================================================================
|Variable |Info
|CPACK_DEBIAN_PACKAGE_MAINTAINER |Maintainer information
|CPACK_PACKAGE_DESCRIPTION_SUMMARY |Package short description
|CPACK_PACKAGE_DESCRIPTION |Package description
|CPACK_DEBIAN_PACKAGE_DEPENDS |For advanced users to add custom scripts.
|CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA |The build directory you are currently in.
|CPACK_DEBIAN_PACKAGE_SECTION |Package section (see link:http://packages.debian.org/stable/[here])
|CPACK_DEBIAN_PACKAGE_VERSION |Package version
|=======================================================================
# Building the Example
[source,bash]
----
$ mkdir build
$ cd build/
$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/matrim/workspace/cmake-examples/06-installer/deb/build
$ make help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... cmake_examples_deb
... cmake_examples_deb_bin
... edit_cache
... install
... install/local
... install/strip
... list_install_components
... package
... package_source
... rebuild_cache
... src/Hello.o
... src/Hello.i
... src/Hello.s
... src/main.o
... src/main.i
... src/main.s
$ make package
Scanning dependencies of target cmake_examples_deb
[ 50%] Building CXX object CMakeFiles/cmake_examples_deb.dir/src/Hello.cpp.o
Linking CXX shared library libcmake_examples_deb.so
[ 50%] Built target cmake_examples_deb
Scanning dependencies of target cmake_examples_deb_bin
[100%] Building CXX object CMakeFiles/cmake_examples_deb_bin.dir/src/main.cpp.o
Linking CXX executable cmake_examples_deb_bin
[100%] Built target cmake_examples_deb_bin
Run CPack packaging tool...
CPack: Create package using DEB
CPack: Install projects
CPack: - Run preinstall target for: cmake_examples_deb
CPack: - Install project: cmake_examples_deb
CPack: Create package
CPack: - package: /home/matrim/workspace/cmake-examples/06-installer/deb/build/cmake_examples_deb-0.2.2-Linux.deb generated.
$ ls
CMakeCache.txt cmake_examples_deb-0.2.2-Linux.deb cmake_examples_deb_bin CMakeFiles cmake_install.cmake CPackConfig.cmake _CPack_Packages CPackSourceConfig.cmake install_manifest.txt libcmake_examples_deb.so Makefile
----