Créer un paquet debian (.deb) d'un projet utilisant CMake
A la source du projet en question, ouvrez le fichier CMakeLists.txt et ajoutez y à la fin :
SET(MAJOR_VERSION 1)
SET(MINOR_VERSION 0)
SET(PATCH_VERSION 0)
IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_SET_DESTDIR "on")
SET(CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
SET(CPACK_GENERATOR "DEB")
SET(CPACK_PACKAGE_DESCRIPTION "short description")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "long description ...")
SET(CPACK_PACKAGE_VENDOR "Vendor")
SET(CPACK_PACKAGE_CONTACT "developer ")
SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_PACKAGE_SECTION "kde")
SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "kdebase-runtime (>= 4:4.2.1), kdelibs5 (>= 4:4.2.1), libc6 (>= 2.1.3), libgcc1 (>= 1:4.1.1), libplasma3, libqt4-dbus (>= 4.5.0), libqtcore4 (>= 4.5.0), libqtgui4 (>= 4.5.0), libstdc++6 (>= 4.2.1)")
SET(CPACK_DEBIAN_PACKAGE_RECOMMENDS "")
SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}_${CPACK_DEBIAN_ARCHITECTURE}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_COMPONENTS_ALL Libraries ApplicationData)
INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
Vous pouvez éditer les variables :
- MAJOR_VERSION, MINOR_VERSION et PATCH_VERSION afin de générer un fichier contenant les bons numéros de version (projet_MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION.deb
- CPACK_DEBIAN_PACKAGE_DEPENDS afin de matcher les dépendances du projet d'origine. Vous pouvez éventuellement retrouver les dépendances dans un paquet .deb du projet avec
dpkg --info - CPACK_DEBIAN_PACKAGE_SECTION afin de définir la section du paquet.
- CPACK_PACKAGE_DESCRIPTION et CPACK_PACKAGE_DESCRIPTION_SUMMARY
- CPACK_PACKAGE_VENDOR et CPACK_PACKAGE_CONTACT
Pour construire le paquet :
mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr .. cpack ..
Vous pouvez vérifier les fichiers présents dans l'archive .deb et les informations du paquet :
dpkg -c package.deb dpkg --info package.deb