Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
[#55] More flexible package generation
Browse files Browse the repository at this point in the history
Added packaging.cmake, a nice wrapper around creating a proper template
around packaging. By default only TGZ is enabled, to use DEB or RPM,
pass -G <TYPE> to the cpack commandline:

   `cpack -G DEB`
   `cpack -G RPM`
  • Loading branch information
NathanFrench committed Nov 13, 2017
1 parent 471b5da commit 4c5dbe2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 44 deletions.
46 changes: 2 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -440,48 +440,6 @@ else(CMAKE_BUILD_TYPE MATCHES Release)
message(" ${CMAKE_C_FLAGS_RELEASE}")
endif()

set (CPACK_GENERATOR "DEB;RPM")
set (CPACK_PACKAGE_NAME "libevhtp")
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_PATCH_VERSION})

set(PROJECT_VERSION_REVISION 0)
find_program(GIT_PROGRAM git DOC "git program")
if(GIT_PROGRAM)
execute_process(
COMMAND ${GIT_PROGRAM} rev-parse --verify --short HEAD
OUTPUT_VARIABLE PROJECT_VERSION_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif(GIT_PROGRAM)

string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
if(DPKG_PROGRAM)
execute_process(
COMMAND ${DPKG_PROGRAM} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME_LOWERCASE}_${PROJECT_VERSION}-${PROJECT_VERSION_REVISION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")

else(DPKG_PROGRAM)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME_LOWERCASE}_${PROJECT_VERSION}-${PROJECT_VERSION_REVISION}_${CMAKE_SYSTEM_NAME}")
endif(DPKG_PROGRAM)

set (CPACK_DEBIAN_PACKAGE_MAINTAINER "unknown")
find_program(WHOAMI_PROGRAM whoami DOC "whoami program")
if(WHOAMI_PROGRAM)
execute_process(
COMMAND ${WHOAMI_PROGRAM}
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_MAINTAINER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif(WHOAMI_PROGRAM)
INCLUDE(CPack)

message("")

include(packaging)
64 changes: 64 additions & 0 deletions cmake/packaging.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

# ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}

set (CPACK_GENERATOR "TGZ;TZ")
set (CPACK_SET_DESTDIR ON)

set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Embedded Libevent based HTTP API")
set (CPACK_PACKAGE_DESCRIPTION
"Very fast HTTP server API, developed as a very flexible and replacement
for Libevent's evhttp API. Create a multi-threaded, SSL aware, secure,
HTTP server using only a minimal amount of code.")

set (CPACK_PACKAGE_NAME "libevhtp")
set (CPACK_PACKAGE_CONTACT "nate@cl0d.com")
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_PATCH_VERSION})

if(X86)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
set (CPACK_RPM_PACKAGE_ARCHITECTURE "i686")
elseif(X86_64)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set (CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
elseif(ARM)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")
set (CPACK_RPM_PACKAGE_ARCHITECTURE "armhf")
elseif(AARCH64)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
set (CPACK_RPM_PACKAGE_ARCHITECTURE "aarch64")
elseif(PPC64LE)
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "ppc64el")
set (CPACK_RPM_PACKAGE_ARCHITECTURE "ppc64le")
else()
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set (CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
endif()

if(CPACK_GENERATOR STREQUAL "DEB")
set (LIBEVHTP_PACKAGE_ARCH_SUFFIX ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
elseif (CPACK_GENERATOR STREQUAL "RPM")
set (LIBEVHTP_PACKAGE_ARCH_SUFFIX ${CPACK_RPM_PACKAGE_ARCHITECTURE})
else()
set (LIBEVHTP_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR})
endif()

set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}-${LIBEVHTP_PACKAGE_ARCH_SUFFIX}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}-${LIBEVHTP_PACKAGE_ARCH_SUFFIX}")

# RPM STUFF
set(CPACK_RPM_COMPONENT_INSTALL TRUE)
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_RPM_PACKAGE_URL "http://github.com/criticalstack/libevhtp")
set(CPACK_RPM_PACKAGE_LICENSE "BSD")

# DEB STUFF
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "universe/libdevel")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://github.com/criticalstack/libevhtp")

include (CPack)

0 comments on commit 4c5dbe2

Please sign in to comment.