Create debian package for script and simple project with cmake and cpack
May 16, 2012 Leave a comment
if you have not a launchpad account and you want share with your friend your little project you can use cmake and cpack to create your package , you can do DEBIAN RPM and other package it’s very simple:
We will start with a simple example using one of my projects so download it here kde apps
/home/stuff/kate-folder-service-menu-0.1.0
└── usr
├── bin
│ └── ktexeditor-open-folder
└── share
└── kde4
└── services
└── ServiceMenus
└── kate-folder.desktop
so we have a bash script
ktexeditor-open-folder
and a service menu for dolphin
kate-folder.desktop
ok now create your /home/stuff/kate-folder-service-menu-0.1.0/CMakeLists.txt
##Cmake template for service menus
cmake_minimum_required(VERSION 2.8)
#SET THE NAME FOR YOUR SERVICE MENU
PROJECT("kate-folder-servicemenu")
SET (CMAKE_PROJECT_NAME "kate-folder-servicemenu")
#search for the minimal version of kde 4.0
find_package(KDE4 4.0.0 REQUIRED)
include(KDE4Defaults)
#install the service menu on the correct folder
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/usr/share/kde4/services/ServiceMenus/kate-folder.desktop DESTINATION
${SERVICES_INSTALL_DIR}/ServiceMenus )
#install the script where you should be
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/usr/bin/ktexeditor-open-folder
DESTINATION bin)
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 "kate service menu for folders")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "It's a service menu for dolphin that allow you to open folders skipping no-text files")
SET(CPACK_PACKAGE_VENDOR "nowardev")
SET(CPACK_PACKAGE_CONTACT "nowardev@gmail.com")
SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}")
#demo dependencies
#SET(CPACK_DEBIAN_PACKAGE_DEPENDS " kate , plasma-desktop, libc6 (>= 2.1.3) ")
#dependencies for this service menu
SET(CPACK_DEBIAN_PACKAGE_DEPENDS " kate , dolphin ")
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_PACKAGE_SECTION "kde")
SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
SET(CPACK_COMPONENTS_ALL Libraries ApplicationData)
INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
after that you can always do
mkdir build ; cd build ; cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. ; cpack ..
and you will get your debian package build 🙂

