Rand Stats

Distribution::Builder::Auto

zef:grizzlysmit

Distribution::Builder::Auto

Table of Contents

NAME

Gzz::Readline

AUTHOR

Francis Grizzly Smit (grizzly@smit.id.au)

VERSION

1.0.24

TITLE

Gzz::Readline

SUBTITLE

A Raku module for building CMake projects to make .so files and installing them in into a chosen install directory.

COPYRIGHT

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0 LICENSE

Top of Document

Introduction

A Raku module for building CMake projects to make .so files and installing them in into a chosen install directory. Based on Distribution::Builder::Cmake by Rawley Fowler I have kept to the same licensing

Basically this module will run

$ cd src-dir

$ rm -rv build

$ mkdir -v build

mkdir: created directory 'build'

$ cd build

$ cmake ..

messages con firming that the project has been generated 

$ make 

messages confirming that the library has been generated

Then the library generated by cmake and make will be installed into install or install-local depending on access. If you ran sudo zef install <your-lib-package> then User will be root and install will be used if you used zef install <>your-lib-package then you probably will not have access to install so install-local will be used. In addition man pages, a html page and a markup page can be installed.

Installation

zef install Distribution::Builder::Cmake

Usage

Assuming your Raku project keeps its CMake project in a folder called my-cmake-project, and your exported lib is gzz_readline. Note, the final .so file will be lib{$my-lib}.so. In your META6.json you'll add the following:

{ 
    ....
    "provides": {
        "Gzz::Readline":            "lib/Gzz/Readline.rakumod"
    },
    "resources": [
        "CMakeLists.txt",
        "contrib/postinst.in",
        "debian/final_deb_stuff.sh.in",
        "images/grizzly.png",
        "source/gzz_readline.c",
        "source/gzz_readline.h",
        "source/gzz_readline.pc.in",
        "source/gzz_rlprivate.c",
        "source/gzz_rlprivate.h",
        "docs/Gzz/Readline.3",
        "docs/Gzz/Readline.html",
        "docs/Gzz/Readline.rakudoc",
        "docs/README.md",
        "docs/Gzz/Readline.html"
    ], 
    "bin": {
        "Gzz::Readline.rakudoc": "doc/Gzz/Readline.rakudoc"
    },
    "depends": [
        "Distribution::Builder::Auto",
        "P5readlink",
        "Pod::To::HTML", 
        "Pod::To::Man",
        "Pod::Load", 
        "Test::Output", 
        "Template::Mustache"
    ],
    .....
    ......
    "builder": "Distribution::Builder::Auto",
    "build": {
        "lib"    : "gzz_readline",
        "install": "/usr/local/lib",
        "install-local": "$*HOME/lib",
        "src-dir": "resources",
        "master-lib-version": "1.0.0",
        "lib-versions": {
            "1": "1.0.0",
            "": "1"
        },
        "pod6-files": [
            "lib/Gzz/Readline.rakumod"
        ],
        "man-number" : "3",
        "man"    : "resources/docs/Gzz/Readline.$man-number",
        "man-install" : "/usr/local/man/man$man-number/Gzz::Readline.$man-number",
        "man-install-local" : "$*HOME/man/man$man-number/Gzz::Readline.$man-number",
        "html" : "resources/docs/Gzz/Readline.html",
        "html-install" : "/usr/local/share/html/Gzz::Readline.html",
        "html-install-local" : "$HOME/html/Gzz::Readline.html",
        "markdown-path" : "resources/docs/README.md",
        "markdown-path-install" : "/usr/local/share/Gzz::Readline/README.md",
        "markdown-path-install-local" : "$HOME/docs/Gzz::Readline/README.md",
        "source": "source",
        "log":    "/dev/tty",
        "debug":  true
    }
}

Where

Note: You may also provide a install field to specify the directory to install the library. This defaults to: resources/libraries/libgzz_readline.so

The typical CMake project will look like (assuming your lib is gzz_readline):

# Specify the minimum version.
cmake_minimum_required(VERSION 3.11)

# Specify the project info.
project(gzz_readline
        VERSION 1.0.0
        DESCRIPTION "Extension to Gnu Readline to get a prompt with a default value"
        LANGUAGES "C")


# Declare the library target.
add_library(${PROJECT_NAME} SHARED
    source/gzz_rlprivate.c
    source/gzz_readline.c
)

#add_dependencies(gzz_readline libreadline.so.0)

target_link_libraries(gzz_readline libreadline.so.1)

# Configure the directories to search for header files.
target_include_directories(${PROJECT_NAME} PRIVATE source)

# Set the version property.
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})

# Set the shared object version property to the project's major version.
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})

# Set the public header property to the one with the actual API.
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER source/gzz_readline.h)

# Set the private header property to the one with the actual API.
#set_target_properties(${PROJECT_NAME} PROPERTIES PRIVATE_HEADER source/gzz_rlprivate.h)

# For access to standard installation directory variables (CMAKE_INSTALL_xDIR).
include(GNUInstallDirs)

# Set library shared object and API header file to install.
install(TARGETS ${PROJECT_NAME}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# Create the pkg-config file from the template.
configure_file(source/${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)

# Set pkg-config file to install.
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

# generate postinst file in ${CMAKE_BINARY_DIR} from template                        #
CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/contrib/postinst.in" "postinst" @ONLY IMMEDIATE)


    # generate a DEB when cpack is run
    SET(CPACK_GENERATOR "DEB")
    SET(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
    SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/images/grizzly.png")
    SET(CPACK_SET_DESTDIR TRUE)
    SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "grizzlysmit@smit.id.au")
    SET(CPACK_PACKAGE_VERSION_MAJOR "1")
    SET(CPACK_PACKAGE_VERSION_MINOR "0")
    SET(CPACK_PACKAGE_VERSION_PATCH "0")
    #include(GNUInstallDirs)
    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"

        COMMAND gzip -cn9 "${CMAKE_CURRENT_SOURCE_DIR}/changelog" ">" "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/changelog"
        COMMENT "Compressing changelog"
    )

    add_custom_target(changelog ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz")

    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz"
        DESTINATION "${CMAKE_INSTALL_DOCDIR}"
    )
    set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/changelog.gz")

    SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/docs/CPack.Description.txt")
    SET(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/docs/Gzz/README.md")
    SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/docs/LICENCE")
    SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libreadline8, libreadline-dev")
    SET(CPACK_PACKAGE_VENDOR "Grizzly")
    # make postinst run after install                                                #
    SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst;")


    include(CPack)

You can see an example of this in action in this repo

(Obviously, you'll need Make and CMake installed and what ever compiler your project uses in this case g++)