使用CMake/CPack制作Debian包:生成正确的包名称
To generate a Debian package that follows the official naming convention (package_name_version_architecture.deb), you need to adjust your CPack configuration to prioritize Debian-specific filename formatting. Here's how to fix your setup:
Updated CMakeLists.txt Snippet
# Core package metadata set(CPACK_PACKAGE_NAME "something") set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MINOR "9") set(CPACK_PACKAGE_VERSION_PATCH "0") set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") # Architecture configuration (generic + Debian-specific) set(CPACK_PACKAGE_ARCHITECTURE "amd64") set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_PACKAGE_ARCHITECTURE}") # Critical: Enable Debian-standard filename structure set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
What's Fixed & Why
The main issue with your original config was missing the CPACK_DEBIAN_FILE_NAME variable. By setting it to "DEB-DEFAULT", you tell CPack to use Debian's required naming schema (using underscores instead of hyphens) instead of the generic CPack format that produces hyphen-separated filenames like something-0.9.0-amd64.deb.
We retained your existing version and architecture settings, but linked the Debian-specific architecture variable to the generic one for consistency – this avoids redundant configuration and reduces the chance of mismatches.
Extra Tips
- If you need a custom filename (instead of strict Debian defaults), you can define
CPACK_DEBIAN_FILE_NAMEexplicitly, e.g.:
But sticking toset(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")DEB-DEFAULTis recommended to ensure compatibility with Debian package tools and repositories. - Debian package names typically use lowercase letters – your current "something" is already compliant here, but keep this in mind for future packages.
内容的提问来源于stack exchange,提问作者Craig S. Anderson

