Introduction
============

This directory is aimed to decouple project building from packaging since 
maintainer rules are generally independent from the developer ones and 
strongly OS specific.

So the idea is to provide space for deploying CPack template files (postfixed 
with '*.cmake.in'), automatically configured during the usual cmake project 
building.

The results will be available in the corresponding binary directory as 
complete CPack configuration file (postfixed with '*.cmake') usable by cpack 
as usual:

`cpack --config <build root>/cpack.d/<config-name>.cmake`

The templates already present will produce packages with 

 * stripped binaries
 * build number equal to the number of commits on the current branch
 * file names (that try to be) compliant with the target OS rules

How to build a new os specific package
======================================

The initial directory structure in the source project directory is the 
following:

    <source root>
    |
    ├── cpack.d
    |   ├── CMakeLists.txt                (template auto config definition)
    |   ├── commons.cmake.in              (helper file usable through inclusion)
    |   ├── fedora.cmake.in               (os specific template for Fedora)
    |   ├── fedora_post_uninstall.sh      (helper file for fedora)
    |   ├── README                        (this readme)
    |   └── readme-file.txt               (file referred in the 'commons' configs)
    |

Step one: new template definition
------------------------------------

Assuming you want to add a new template for Debian:9, create and fill a new 
member in the cpack.d directory named 'debian.cmake.in' (the only important
part is the postfix `.cmake.in`). There is no mandatory rule to follow, below 
a possible skeleton to be further filled:

    ##############################################################################
    # CPACK Configuration for Linux Debian 9 amd64 architecture

    cmake_policy(SET CMP0012 NEW)

    # this will include a number of predefined helper macros
    include("@CMAKE_CURRENT_BINARY_DIR@/commons.cmake")

    # this macro initializes a number of project specific and os 'agnostic' attributes
    config_package(NAME "lib@PROJECT_NAME@" LOWCASE)

    # this macro define a component package according to Debian specifications for
    # COMPONENT NAME, SECTION and FILE NAME termination (third optional argument)
    macro(component COMPONENT SECTION)
      if (${ARGC} GREATER 2)
        set(CPACK_DEBIAN_${COMPONENT}_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${ARGV2}")
      else()
        set(CPACK_DEBIAN_${COMPONENT}_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
      endif()
      set(CPACK_DEBIAN_${COMPONENT}_FILE_NAME    "${CPACK_DEBIAN_${COMPONENT}_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_@DEB_ARCH@.deb")
      set(CPACK_DEBIAN_${COMPONENT}_PACKAGE_SECTION   ${SECTION})
    endmacro(component)

    set(CPACK_GENERATOR               "DEB")
    set(CPACK_PACKAGE_FILE_NAME     "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.amd64.deb")
    set(CPACK_DEB_COMPONENT_INSTALL   "ON")
    set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${PROJECT_URL}")

    component(RUNTIME libs)
    component(DEVELOPMENT libdevel dev)

Now the directory structure is:

    <source root>
    |
    ├── cpack.d
    |   ├── CMakeLists.txt  
    |   ├── commons.cmake.in 
    |   ├── debian.cmake.in          (new template for Debian)
    |   ├── fedora.cmake.in   
    |   ├── fedora_post_uninstall.sh    
    |   ├── README                      
    |   └── readme-file.txt             
    |

Step two: package creation
--------------------------

After building the project with usual cmake commands, the build directory structure will be:

```
<build root>
|
├── cpack.d
|   ├── commons.cmake        
|   ├── debian.cmake                (new config for Debian)
|   ├── fedora.cmake      
|
```

in order to create the Debian packages just 'cd' into a work directory of your choice
and execute

`cpack --configure /path/to/debian.cmake`
