CMake: Add CPack for .deb and .rpm package generation. (#987)

Compile as normal, run `cpack -G DEB` or `cpack -G RPM` in build
directory.

Tested on:
  - Debian 11 (bullseye)
  - OpenSUSE Leap 15
  - Ubuntu 18.04 (bionic)

Bug: https://github.com/drogonframework/drogon/issues/983
This commit is contained in:
tastytea 2021-08-18 16:31:32 +02:00 committed by GitHub
parent d60f962aa3
commit 0783d6aa3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -748,3 +748,4 @@ if(DOXYGEN_FOUND)
endif(BUILD_DOC)
endif(DOXYGEN_FOUND)
include(cmake/Packages.cmake)

37
cmake/Packages.cmake Normal file
View File

@ -0,0 +1,37 @@
include(GNUInstallDirs)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_CONTACT "https://github.com/drogonframework/drogon")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${DROGON_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C++14/17 based HTTP web application framework running on Linux/macOS/Unix/Windows")
# DEB
# Figure out dependencies automatically.
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
# Should be set automatically, but it is not.
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
# The default does not produce valid Debian package names.
set(CPACK_DEBIAN_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
# RPM
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
# Figure out dependencies automatically.
set(CPACK_RPM_PACKAGE_AUTOREQ ON)
# Should be set automatically, but it is not.
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
include(CPack)