Skip to content

Commit

Permalink
Added packaging using CPack and pkg-config.
Browse files Browse the repository at this point in the history
Fixed installation dir of configs - it must be arch-independent for a header-only library.
  • Loading branch information
KOLANICH committed Jul 22, 2021
1 parent 1e52a80 commit 7d45b04
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
48 changes: 42 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.1)

project(argh)
project(argh VERSION 1.3.1)
set(PROJECT_DESCRIPTION "A minimalist argument handler.")
set(PROJECT_HOMEPAGE_URL "https://github.com/adishavit/argh")

set(CMAKE_CXX_STANDARD 11)

Expand Down Expand Up @@ -35,20 +37,54 @@ add_library(argh INTERFACE)
target_include_directories(argh INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}> $<INSTALL_INTERFACE:include>)

if(ARGH_MASTER_PROJECT)
install(TARGETS argh EXPORT arghTargets)
install(TARGETS argh EXPORT argh)

include(GNUInstallDirs)
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
install(FILES "${CMAKE_CURRENT_LIST_DIR}/argh.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES "${CMAKE_CURRENT_LIST_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES "${CMAKE_CURRENT_LIST_DIR}/README.md" DESTINATION ${CMAKE_INSTALL_DOCDIR})
set(PackagingTemplatesDir "${CMAKE_CURRENT_LIST_DIR}/packaging")

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
# this might be a bit too restrictive, since for other (BSD, ...) this might apply also
# but this can be fixed later in extra pull requests from people on the platform
install(FILES argh-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/argh)
install(EXPORT arghTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/argh)
install(FILES "${PackagingTemplatesDir}/argh-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/argh)
install(EXPORT argh DESTINATION ${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/argh)
else()
install(FILES argh-config.cmake DESTINATION CMake)
install(EXPORT arghTargets DESTINATION CMake)
install(FILES "${PackagingTemplatesDir}/argh-config.cmake" DESTINATION CMake)
install(EXPORT argh DESTINATION CMake)
endif()

set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "Argh developers")
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf")

set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel")
set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}")

set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_NSIS_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")

set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
message(STATUS "PROJECT_DESCRIPTION ${PROJECT_DESCRIPTION}")
configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
install(FILES "${PKG_CONFIG_FILE_NAME}"
DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig"
)

include(CPack)
endif()
File renamed without changes.
7 changes: 7 additions & 0 deletions packaging/pkgconfig.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}

0 comments on commit 7d45b04

Please sign in to comment.