From 9ba45adfe27ed37d31777a96afd7d3119b4e57fa Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Wed, 21 Jul 2021 11:41:31 +0300 Subject: [PATCH] Added packaging using CPack and generation of pkg-config files. Fixed installation directory - the lib is architecture-independent and so CMake and pkg-config files should go into /lib, not into /lib/ --- CMakeLists.txt | 66 ++++++++++++++++++++++++++++++++++++++- packaging/pkgconfig.pc.in | 7 +++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 packaging/pkgconfig.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b60907a..c766dd31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,21 @@ cmake_minimum_required(VERSION 3.8) + project(argparse VERSION 1.0.0 LANGUAGES CXX) +set("PROJECT_DESCRIPTION" "A single header argument parser for C++17") +set("PROJECT_HOMEPAGE_URL" "https://github.com/p-ranav/argparse") + option(ARGPARSE_BUILD_TESTS OFF) option(ARGPARSE_LONG_VERSION_ARG_ONLY OFF) include(GNUInstallDirs) +include(CMakePackageConfigHelpers) +string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}") + add_library(argparse INTERFACE) add_library(argparse::argparse ALIAS argparse) + if (ARGPARSE_LONG_VERSION_ARG_ONLY) target_compile_definitions(argparse INTERFACE ARGPARSE_LONG_VERSION_ARG_ONLY=true) endif () @@ -17,16 +25,72 @@ target_include_directories(argparse INTERFACE $ $) + if(ARGPARSE_BUILD_TESTS) add_subdirectory(test) endif() +if(${CMAKE_VERSION} VERSION_GREATER "3.14") + set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") +endif() + install(TARGETS argparse EXPORT argparseConfig) install(EXPORT argparseConfig NAMESPACE argparse:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/argparse) + DESTINATION ${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}) install(FILES ${CMAKE_CURRENT_LIST_DIR}/include/argparse/argparse.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/argparse) + +set(CONFIG_FILE_NAME_WITHOUT_EXT "${PROJECT_NAME}Config") +set(CMAKE_CONFIG_FILE_BASENAME "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_NAME_WITHOUT_EXT}") +set(CMAKE_CONFIG_VERSION_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}-version.cmake") +set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}.cmake") + +if(${CMAKE_VERSION} VERSION_GREATER "3.14") + set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") +endif() + +write_basic_package_version_file("${CMAKE_CONFIG_VERSION_FILE_NAME}" + COMPATIBILITY ExactVersion + ${OPTIONAL_ARCH_INDEPENDENT} +) + export(EXPORT argparseConfig NAMESPACE argparse::) + +install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}") + +set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging") + +set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") +set(CPACK_PACKAGE_VENDOR "argparse (C++) 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 "Pranav Srinivas Kumar") +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") +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) diff --git a/packaging/pkgconfig.pc.in b/packaging/pkgconfig.pc.in new file mode 100644 index 00000000..9b6a44c6 --- /dev/null +++ b/packaging/pkgconfig.pc.in @@ -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}