From a111aea13d677e5544d3a2e8f3ce076788119e8f Mon Sep 17 00:00:00 2001 From: Martin Olivier Date: Fri, 13 Oct 2023 15:31:40 +0200 Subject: [PATCH] feat: packaging via cpack (#73) Signed-off-by: Martin Olivier --- .github/workflows/CI.yml | 4 ++ CMakeLists.txt | 78 ++++++++++++++++++++++++++++++++++ README.md | 3 +- _config.yml | 2 - packaging/CMakeConfig.cmake.in | 7 +++ packaging/pkgconfig.pc.in | 9 ++++ 6 files changed, 99 insertions(+), 4 deletions(-) delete mode 100644 _config.yml create mode 100644 packaging/CMakeConfig.cmake.in create mode 100644 packaging/pkgconfig.pc.in diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ec36e4d..dd98411 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,6 +38,10 @@ jobs: generator: MinGW Makefiles - os: ubuntu-latest generator: Visual Studio 17 + - generator: MinGW Makefiles + cxx-std: 17 + - generator: MinGW Makefiles + cxx-std: 20 name: ${{ matrix.os }} (C++${{ matrix.cxx-std }} - ${{ matrix.generator }}) runs-on: ${{ matrix.os }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fa2602..66bccc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,3 +67,81 @@ if(DYLIB_BUILD_TESTS) include(GoogleTest) gtest_discover_tests(unit_tests PROPERTIES DISCOVERY_TIMEOUT 600 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) endif() + +set(CPACK_PACKAGE_NAME "dylib") +set(CPACK_PACKAGE_VENDOR "Martin Olivier") +set(CPACK_PACKAGE_VERSION_MAJOR "2") +set(CPACK_PACKAGE_VERSION_MINOR "1") +set(CPACK_PACKAGE_VERSION_PATCH "0") +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_PACKAGE_DESCRIPTION "C++ cross-platform wrapper around dynamic loading of shared libraries") +set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") +set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") + +include(CPackComponent) +include(CMakePackageConfigHelpers) + +set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging") + +set(LIB_NAME "dylib") +string(TOUPPER "${LIB_NAME}" LIB_NAME_UPPER) +set(CMAKE_EXPORT_NAME "${LIB_NAME}") +set(PKG_CONFIG_NAME "${LIB_NAME}") + +cpack_add_component(dev + DISPLAY_NAME "${LIB_NAME} header" + DESCRIPTION "The header needed for using ${LIB_NAME} in own software" +) + +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.hpp" + TYPE INCLUDE + COMPONENT "dev" +) + +set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PKG_CONFIG_NAME}.pc") +configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) +install(FILES "${PKG_CONFIG_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + COMPONENT "dev" +) + +set(CMAKE_CONFIG_FILE_BASENAME "${CMAKE_EXPORT_NAME}Config.cmake") +set(CMAKE_CONFIG_VERSION_FILE_BASENAME "${CMAKE_EXPORT_NAME}ConfigVersion.cmake") +set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CONFIG_FILE_BASENAME}") +configure_package_config_file("${PackagingTemplatesDir}/CMakeConfig.cmake.in" "${CMAKE_CONFIG_FILE_NAME}" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake" +) + +set(CMAKE_CONFIG_VERSION_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CONFIG_VERSION_FILE_BASENAME}") +write_basic_package_version_file( + "${CMAKE_CONFIG_VERSION_FILE_NAME}" + VERSION "100500.100500.100500" # any version of same bitness suits. CMake cannot compare to infinity + COMPATIBILITY AnyNewerVersion +) + +install(FILES "${CMAKE_CONFIG_FILE_NAME}" "${CMAKE_CONFIG_VERSION_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_EXPORT_NAME}" + COMPONENT "dev" +) + +set("CPACK_DEBIAN_DEV_PACKAGE_NAME" "lib${LIB_NAME}-dev") +set("CPACK_DEBIAN_DEV_PACKAGE_DEPENDS" "libc6-dev") +set("CPACK_DEBIAN_DEV_PACKAGE_SUGGESTS" "cmake, pkg-config, pkg-conf") + +set("CPACK_RPM_DEV_PACKAGE_NAME" "lib${LIB_NAME}-devel") +set("CPACK_RPM_DEV_PACKAGE_SUGGESTS" "${CPACK_DEBIAN_DEV_PACKAGE_SUGGESTS}") + +set(CPACK_COMPONENTS_ALL "dev") + +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/martin-olivier/dylib") +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_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_RPM_COMPONENT_INSTALL ON) +set(CPACK_NSIS_COMPONENT_INSTALL ON) +set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") + +include(CPack) \ No newline at end of file diff --git a/README.md b/README.md index 3f28349..d643443 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@

- Dylib -

+dylib

version diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 4f9c932..0000000 --- a/_config.yml +++ /dev/null @@ -1,2 +0,0 @@ -theme: jekyll-theme-minimal -show_downloads: true diff --git a/packaging/CMakeConfig.cmake.in b/packaging/CMakeConfig.cmake.in new file mode 100644 index 0000000..5b41736 --- /dev/null +++ b/packaging/CMakeConfig.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + + +message(STATUS "@CMAKE_EXPORT_NAME@Config.cmake") +find_package(PkgConfig REQUIRED) +pkg_check_modules("@CMAKE_EXPORT_NAME@" "@PKG_CONFIG_NAME@") +check_required_components("@CMAKE_EXPORT_NAME@") \ No newline at end of file diff --git a/packaging/pkgconfig.pc.in b/packaging/pkgconfig.pc.in new file mode 100644 index 0000000..ac5bd2c --- /dev/null +++ b/packaging/pkgconfig.pc.in @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PKG_CONFIG_NAME@ +Description: @CPACK_PACKAGE_DESCRIPTION@ +Version: @CPACK_PACKAGE_VERSION@ +Libs: -L${libdir} -l@LIB_FILE_NAME@ +Cflags: -I${includedir} \ No newline at end of file