CMake:Packaging With CPack

From KitwarePublic
Revision as of 15:37, 27 July 2006 by Andy (talk | contribs)
Jump to navigationJump to search

Introduction

CPack is a software packaging tool distributed with [http://www.cmake.org CMake]. It uses the generators concept from CMake, to abstract package generation on specific platforms. It can be used with or without CMake, but it may depend on some software being installed on the system. For example, on Mac OSX, it relies on Xcode to be installed and on Windows it requires NSIS.

Using CPack with CMake

CMake comes with CPack module, which will generate appropriate CPack input file. To use this module, some CMake variables need to be set. These variables will be copied to the CPack input file.

A simple CMake section to use CPack from CMake is this:

INCLUDE(Cpack)

This will generate new target in Makefile (or Visual Studio, or Xcode) called "package". By running this target, CPack will be invoked, which will generate all the packages. Example output of the "package" target of Makefile is:

Run CPack packaging tool...
CPack: Create package using STGZ
CPack: Install projects
CPack: - Run preinstall target for: CMake
CPack: - Install project: CMake
CPack: - Strip files
CPack: Compress package
CPack: Finalize package
CPack: Package /home/andy/CMake-bin/cmake-2.5.0-Linux-i686.sh generated.
CPack: Create package using TGZ
CPack: Install projects
CPack: - Run preinstall target for: CMake
CPack: - Install project: CMake
CPack: - Strip files
CPack: Compress package
CPack: Finalize package
CPack: Package /home/andy/CMake-bin/cmake-2.5.0-Linux-i686.tar.gz generated.
CPack: Create package using TZ
CPack: Install projects
CPack: - Run preinstall target for: CMake
CPack: - Install project: CMake
CPack: - Strip files
CPack: Compress package
CPack: Finalize package
CPack: Package /home/andy/CMake-bin/cmake-2.5.0-Linux-i686.tar.Z generated.

When adding line:

INCLUDE(CPack)

CMake module CPack.cmake will generate CPack configuration file called CPackConfig.cmake.

A more typical CMake list section for CPack configuration would be:

INCLUDE(InstallRequiredSystemLibraries)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "My funky project")
SET(CPACK_PACKAGE_VENDOR "Me, myself, and I")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "3")
SET(CPACK_PACKAGE_VERSION_PATCH "2")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
IF(WIN32 AND NOT UNIX)
  # There is a bug in NSI that does not handle full unix paths properly. Make
  # sure there is at least one set of four (4) backlasshes.
  SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\MyExecutable.exe")
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} My Famous Project")
  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.my-project-home-page.org")
  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.my-personal-home-page.com")
  SET(CPACK_NSIS_CONTACT "me@my-personal-home-page.com")
  SET(CPACK_NSIS_MODIFY_PATH ON)
ELSE(WIN32 AND NOT UNIX)
  SET(CPACK_STRIP_FILES "bin/MyExecutable")
  SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF(WIN32 AND NOT UNIX)
SET(CPACK_PACKAGE_EXECUTABLES "MyExecutable" "My Executable")
INCLUDE(CPack)

Using CPack without CMake

CPack can be used directly by specifying CPackConfig.cmake file. This file uses CMake syntax and has to contain several variables. Here is example CPackConfig.cmake files from CMake build directory on Linux system:

SET(CPACK_CMAKE_GENERATOR "Unix Makefiles")
SET(CPACK_GENERATOR "STGZ;TGZ;TZ")
SET(CPACK_INSTALL_CMAKE_PROJECTS "/home/andy/vtk/CMake-bin;CMake;ALL;/")
SET(CPACK_NSIS_DISPLAY_NAME "CMake 2.5")
SET(CPACK_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackConfig.cmake")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "/home/andy/vtk/CMake/Copyright.txt")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool")
SET(CPACK_PACKAGE_EXECUTABLES "ccmake;CMake")
SET(CPACK_PACKAGE_FILE_NAME "cmake-2.5.0-Linux-i686")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake 2.5")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "CMake 2.5.0")
SET(CPACK_PACKAGE_NAME "CMake")
SET(CPACK_PACKAGE_VENDOR "Kitware")
SET(CPACK_PACKAGE_VERSION "2.5.0")
SET(CPACK_PACKAGE_VERSION_MAJOR "2")
SET(CPACK_PACKAGE_VERSION_MINOR "5")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_RESOURCE_FILE_LICENSE "/home/andy/vtk/CMake/Copyright.txt")
SET(CPACK_RESOURCE_FILE_README "/home/andy/vtk/CMake/Templates/CPack.GenericDescription.txt")
SET(CPACK_RESOURCE_FILE_WELCOME "/home/andy/vtk/CMake/Templates/CPack.GenericWelcome.txt")
SET(CPACK_SOURCE_GENERATOR "TGZ;TZ")
SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackSourceConfig.cmake")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "cmake-2.5.0")
SET(CPACK_SOURCE_STRIP_FILES "")
SET(CPACK_STRIP_FILES "bin/ccmake;bin/cmake;bin/cpack;bin/ctest")
SET(CPACK_SYSTEM_NAME "Linux-i686")
SET(CPACK_TOPLEVEL_TAG "Linux-i686")

These variables can be overwritten on the command line using the option "-D":

cpack -D CPACK_PACKAGE_VENDOR=Me -D CPACK_SYSTEM_NAME=super-duper-linux ...

Conclusion

CPack is a powerful, easy to use, cross-platform packaging tool. Using a simple configuration file or using a CMake module, the author of a project can package complex project into a simple installer.



CMake: [Welcome | Site Map]