cmakePackaging and Distributing Projects


Syntax

  • # Package a build directory
    pack [PATH]
  • # Use a specific generator
    cpack -G [GENERATOR] [PATH]
  • # Provide optional overrides
  • cpack -G [GENERATOR] -C [CONFIGURATION] -P [PACKAGE NAME] -R [PACKAGE VERSION] -B [PACKAGE DIRECTORY] --vendor [PACKAGE VENDOR]

Remarks

CPack is an external tool allowing the fast packaging of built CMake projects by gathering all the required data straight from the CMakeLists.txt files and the utilized installation commands like install_targets().

For CPack to properly work, the CMakeLists.txt must include files or targets to be installed using the install build target.

A minimal script could look like this:

# Required headers
cmake(3.0)

# Basic project setup
project(my-tool)

# Define a buildable target
add_executable(tool main.cpp)

# Provide installation instructions
install_targets(tool DESTINATION bin)