From 3f161e866ff1c77593b76574c0e00b62cd8b9454 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 16:18:47 +0100 Subject: [PATCH] Add packages.cmake, to create DEB and RPM packages. --- CMakeLists.txt | 2 +- README.adoc | 4 ++-- cmake/packages.cmake | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 cmake/packages.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f634f80..20ffaf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,4 +48,4 @@ if(WITH_EXAMPLES) add_subdirectory(examples) endif() -# include(cmake/packages.cmake) +include(cmake/packages.cmake) diff --git a/README.adoc b/README.adoc index 921ec56..cadfe1a 100644 --- a/README.adoc +++ b/README.adoc @@ -88,8 +88,8 @@ link:{uri-reference}/examples.html[More examples] are included in the reference. * Optional ** Documentation: link:{uri-doxygen}[Doxygen] (tested: 1.8) ** Tests: link:{uri-catch}[Catch] (tested: 2.5 / 1.2) -// ** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.18) -// ** RPM package: link:{uri-rpm-build}[rpm-build] (tested: 4.11) + ** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.18) + ** RPM package: link:{uri-rpm-build}[rpm-build] (tested: 4.11) ==== Get sourcecode diff --git a/cmake/packages.cmake b/cmake/packages.cmake new file mode 100644 index 0000000..464b04b --- /dev/null +++ b/cmake/packages.cmake @@ -0,0 +1,55 @@ +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION ${${PROJECT_NAME}_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}") +set(CPACK_PACKAGE_CONTACT "tastytea ") +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.adoc") + +execute_process(COMMAND uname -m + OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) +set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}") +set(CPACK_GENERATOR "TGZ") + +if(WITH_DEB) + set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}") + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE + "https://schlomp.space/tastytea/${PROJECT_NAME}") + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + + execute_process(COMMAND dpkg --print-architecture + OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND lsb_release --codename --short + OUTPUT_VARIABLE DEBIAN_CODENAME + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}_${DEBIAN_CODENAME}") +endif() + +if(WITH_RPM) + set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}") + set(CPACK_GENERATOR "RPM") + set(CPACK_RPM_PACKAGE_LICENSE "AGPL-3") + set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") + set(CPACK_RPM_PACKAGE_REQUIRES "libcurl >= 7.32") + + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}") + execute_process(COMMAND lsb_release --id --short + OUTPUT_VARIABLE OS + OUTPUT_STRIP_TRAILING_WHITESPACE) + if("${OS}" STREQUAL "CentOS") + execute_process(COMMAND rpm -E %{rhel} + OUTPUT_VARIABLE OS_RELEASE + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_PACKAGE_FILE_NAME}.centos${OS_RELEASE}") + endif() +endif() + +include(CPack)