Add packaging

This commit is contained in:
Matthias Saft 2023-11-09 23:01:54 +01:00 committed by Thomas Jensen
parent 652d518b32
commit 0a6a5cd1e9
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
3 changed files with 117 additions and 4 deletions

3
.gitignore vendored
View File

@ -67,3 +67,6 @@ CMakeUserPresets.json
# Misc
/vs
# CMake / Conan
dist/

View File

@ -1,8 +1,15 @@
cmake_minimum_required(VERSION 3.27)
# Build options options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DISABLE_TESTING "Disable test compilation" OFF)
option(ENABLE_COVERAGE "Enable coverage measurement" OFF)
# Project and generated target name.
project(boxes LANGUAGES C)
# =============================================================================
# Boxes version, fallback in case not in a boxes Git repository.
set(BVERSION "2.2.2-dev")
set(GLOBALCONF "/usr/share/boxes")
@ -29,6 +36,7 @@ add_custom_command(
COMMAND sed -e "s|--BVERSION--|${BVERSION}|; s|--GLOBALCONF--|${GLOBALCONF}|"
${CMAKE_CURRENT_SOURCE_DIR}/src/boxes.in.h > ${CMAKE_CURRENT_BINARY_DIR}/boxes.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/boxes.in.h
COMMENT "Generating boxes.h"
VERBATIM
)
@ -55,6 +63,7 @@ flex_target(boxes_scanner
)
add_flex_bison_dependency(boxes_scanner boxes_parser)
# =============================================================================
# The executable target name is the project name.
# Note that a static library with the project name and suffix "_lib" is
@ -105,6 +114,7 @@ set(SOURCES_EXE
src/boxes.c
)
# -----------------------------------------------------------------------------
# Build static library.
add_library(${TARGET}_lib STATIC
@ -131,7 +141,53 @@ target_link_libraries(${TARGET}
${LIBRARIES}
)
# -----------------------------------------------------------------------------
# Enable and include unit tests.
enable_testing()
add_subdirectory(utest)
# Check and include unit tests.
if (NOT DISABLE_TESTING)
enable_testing()
add_subdirectory(utest)
endif ()
# =============================================================================
# Create man page
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/boxes.1
COMMAND sed -e "s|--BVERSION--|${BVERSION}|; s|--GLOBALCONF--|${GLOBALCONF}|"
${CMAKE_SOURCE_DIR}/doc/boxes.1.in > ${CMAKE_BINARY_DIR}/boxes.1
DEPENDS ${CMAKE_SOURCE_DIR}/doc/boxes.1.in
COMMENT "Generating man page"
VERBATIM
)
add_custom_target(
boxes_man_page ALL
DEPENDS ${CMAKE_BINARY_DIR}/boxes.1
)
# -----------------------------------------------------------------------------
# Installing
install(
TARGETS ${TARGET}
)
install(
FILES ${CMAKE_BINARY_DIR}/boxes.1
DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1
)
# Packaging
set(CPACK_PACKAGE_NAME "boxes")
set(CPACK_PACKAGE_VERSION ${BVERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line ASCII boxes")
set(CPACK_PACKAGE_DESCRIPTION "Boxes is a command line program which draws, removes, and repairs ASCII art boxes.")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://boxes.thomasjensen.com")
set(CPACK_PACKAGE_VENDOR "Thomas Jensen and the boxes contributors")
set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
set(CPACK_RESOURCE_FILE_INSTALL ${CMAKE_BINARY_DIR}/boxes.1)
set(CPACK_SET_DESTDIR true)
set(CPACK_GENERATOR "ZIP" "TGZ") # "DEB"
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Thomas Jensen and the boxes contributors")
include(CPack)

View File

@ -7,7 +7,7 @@ Building boxes requires two tools to be installed:
- [Conan](https://conan.io), a package manager for C/C++, is used to resolve required library and tool dependencies
- libunistring
- pcre2
- ncurses (official Conan 2 version should be available soon)
- ncurses (official Conan 2 version should be available soon, see [below](#ncurses))
- flex (library and tool)
- bison (tool)
- cmocka (for testing)
@ -75,3 +75,57 @@ cmake --build ./build/${BUILD_TYPE} \
ctest --test-dir ./build/${BUILD_TYPE} --verbose
```
## Installing boxes
First start with providing the Conan packages like described in the [building boxes](#building-boxes) section. Then you
can do the following to install the `boxes`:
```sh
...
export INSTALL_DIR="./dist"
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} --preset ${BUILD_PRESET}
cmake --build --preset ${BUILD_PRESET} --target install
${INSTALL_DIR}/bin/boxes --help
```
## Packaging boxes
The installation process is used for packaging. So the same prerequisites as for [installing boxes](#installing-boxes)
have to be fulfilled. To create boxes packages, do the following:
```sh
...
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} --preset ${BUILD_PRESET}
cmake --build --preset ${BUILD_PRESET} --target package
```
## Notes
### ncurses
The Conan `ncurses` is in the last steps of being migrated from version 1 to version 2 (you can
[track](https://github.com/conan-io/conan-center-index/pull/20355) the status). Unfortunately this means, that it cannot
be used right out-of-the-box, and needs to be created into the local Conan cache manually first. Fortunately, it is
rather easy to do this by following these steps:
```sh
# Create a directory where the recipes files are stored
mkdir -p ncurses
pushd ncurses
# Download the required files
curl -LO https://raw.githubusercontent.com/valgur/conan-center-index/migrate/ncurses/recipes/ncurses/all/conandata.yml
curl -LO https://raw.githubusercontent.com/valgur/conan-center-index/migrate/ncurses/recipes/ncurses/all/conanfile.py
mkdir -p cmake
pushd cmake
curl -LO https://raw.githubusercontent.com/valgur/conan-center-index/migrate/ncurses/recipes/ncurses/all/cmake/conan-official-ncurses-targets.cmake
popd
# Build the package
conan create . --version 6.4 --settings build_type=Debug --build missing
#conan create . --version 6.4 --settings build_type=Release --build missing
popd
```