4

I am building a debian package with CMAKE and CPACK. Everything is smooth with the build except that I can't find how to add a changelog file in the deb package. Is there any way to do it?

Caduchon
  • 4,574
  • 4
  • 26
  • 67
Jibrilat
  • 347
  • 1
  • 3
  • 14
  • What is the format of your changelog ? How is it generated ? – Caduchon Sep 29 '17 at 14:13
  • Until now I was using dh to generate the changelog file and before every release I was adding the changes manually and then I was building the package with dpkg-buildpackage – Jibrilat Sep 29 '17 at 14:30
  • I don't understand the difference with adding a simple text file. – Caduchon Sep 29 '17 at 14:33
  • The changelog will be used by Debian archive. Check more info here: https://www.debian.org/doc/debian-policy/ch-controlfields.html#debian-changes-files-changes So I need a to add explicitily this information somewhere in CPACK but I cant find where. – Jibrilat Sep 29 '17 at 14:43
  • Have you tried the approach shown here: [CPack_Debian](https://code.cor-lab.org/svn/cca/trunk/cca/cpack/CPackDebianConfig.cmake) and here all others files [CMake_Debian](https://code.cor-lab.org/svn/cca/trunk/cca/cpack/) ? – fedepad Sep 30 '17 at 21:42

1 Answers1

3

Since at least CMake 3, the Debian CPack generator provides the variable CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, which is a list of arbitrary files to add to the control section of the package.

You can write/generate your changelog file, and add it to this variable:

set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/debian/changelog")

See the CMake docs for more.

===== EDIT =====

Lintian (quite rightly) doesn't like the above solution. The changelog should be compressed and installed in /usr/share/doc/package-name/changelog.gz. The following code works on Linux:

include(GNUInstallDirs)

add_custom_command(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"
    COMMAND gzip -cn9 "${CMAKE_CURRENT_SOURCE_DIR}/changelog" > "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/changelog"
    COMMENT "Compressing changelog"
)

add_custom_target(changelog ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"
    DESTINATION "${CMAKE_INSTALL_DOCDIR}"
)

add_custom_command adds a hook to re-generate changelog.gz when its dependencies (changelog) change. add_custom_target adds a target to generate changelog.gz at build time. install installs the compressed changelog to the correct location.

The code should go in a CMakeLists.txt file in the same directory as the changelog. Unfortunately, CMake doesn't seem to have a cross-platform way to compress single files yet.

truf
  • 2,843
  • 26
  • 39
jezza
  • 331
  • 2
  • 13
  • It works for me. What's going wrong? Are you getting error messages? – jezza Jul 21 '20 at 18:44
  • `lintian` doesn't accept this solution, moreover according to Debian guidelines changelog should be compressed using `gzip -9` – pktiuk Aug 15 '20 at 19:52
  • [This](https://www.debian.org/doc/debian-policy/ch-docs.html#s-changelogs) only says they should be **installed** compressed, so I question your conclusion here. As for `lintian` not accepting the solution, what's the error? This solution is transparent enough that it should be clear why it fails. – jezza Sep 28 '20 at 20:43
  • 1
    @pktiuk I've updated my answer. Hope this helps - I don't get any warnings or errors from lintian now. – jezza Dec 04 '20 at 13:32
  • The command that works for me is: `gzip -ck9 "${CMAKE_CURRENT_SOURCE_DIR}/changelog" > "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"` – Andrei Dec 07 '21 at 04:15
  • @Andrei Thanks for pointing out my typos. Fixed now. I can't see a -k option in the gzip docs (https://linux.die.net/man/1/gzip) so I haven't changed that bit. – jezza Dec 07 '21 at 10:30
  • 1
    Hm... I suppose that man is outdated. Probably in 2012 they added more options. http://manpages.ubuntu.com/manpages/bionic/man1/gzip.1.html If I don't specify `-k`, the original `changelog` is deleted from source directory. – Andrei Dec 08 '21 at 07:36
  • 1
    Interesting. -c should imply -k (I have verified this on Debian 10). – jezza Dec 09 '21 at 14:43
  • 1
    Thank you for your workaround. I filed an issue at https://gitlab.kitware.com/cmake/cmake/-/issues/24929 giving a slightly improved variant of it. – dvo May 19 '23 at 07:37