cmake Packaging and Distributing Projects

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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)


Got any cmake Question?