I am developing a C/C++ package, built using CMake, and I want to package it for Debian. So I thought I'd use CPack to build a Debian package. I managed to do so, but my project should also contain configuration files, that should not be overwritten by package upgrades. IIUC, that's what Debian conffiles are for, but I can't figure out how to use CMake to insert them. Right now, it installs the files under /etc/myproject
, but they get overwritten even if the info I found online seems to suggest that everything under /etc
should be treated as a conffile. I also found that CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
may help me, but I can't figure out how should I use it. So, how can I instruct CMake/CPack to install conffiles?
My current relevant CMakeLists.txt is
###########
# Install #
###########
set(CMAKE_INSTALL_PREFIX "/opt/test/usr")
set(CPACK_PACKAGE_NAME test-package)
set(CPACK_PACKAGE_VENDOR "Test company")
set(CPACK_PACKAGE_CONTACT "test@company.com")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 1)
set(CPACK_PACKAGE_VERSION_PATCH 2)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test package for CPack")
set(CPACK_GENERATOR DEB)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_PRIORITY extra)
install(TARGETS ${PROJECT_NAME}
DESTINATION bin)
install(TARGETS sub-proc-test # two programs built from my MWE
DESTINATION bin)
install(FILES # these SHOULD be conffiles
${CMAKE_SOURCE_DIR}/proc-test.env
${CMAKE_SOURCE_DIR}/sub-proc-test-1.env
${CMAKE_SOURCE_DIR}/sub-proc-test-2.env
${CMAKE_SOURCE_DIR}/proc-test-add.env
DESTINATION /etc/test) # installed here
include(CPack)
I may have found a solution (sorry for the alliterations ahead). Apparently, CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
is a variable, for which you can set a list of semicolon separated files, that will be included in the DEBIAN
folder of the package. Since .deb
packages will read the file DEBIAN/conffiles
to know which files are conffiles, I created a conffiles
file, wrote in it the newline separated list of files that are confiles, and added in my CMakeLists.txt
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/conffiles")
Then when I built the package everything went good, and installation works as expected.