From 7ae7155f25c484d9c328115a60cd992887b99ab6 Mon Sep 17 00:00:00 2001 From: Konstantin Lampalzer Date: Sun, 22 Sep 2024 18:29:51 +0200 Subject: [PATCH] ci: add Packing cmake and dockerfile to run packing --- .dockerignore | 2 ++ CMakeLists.txt | 9 +++++++- ci/Dockerfile | 17 +++++++++++++++ cmake/Packing.cmake | 50 +++++++++++++++++++++++++++++++++++++++++++++ package.sh | 0 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 ci/Dockerfile create mode 100644 cmake/Packing.cmake create mode 100755 package.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7846b39 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.github +ci \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ce7beb2..2d37b18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # target_link_libraries(... ${libcreate_LIBRARIES}) # -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.28) project(libcreate) add_compile_options(-Wall -Wextra -Wpedantic) @@ -203,3 +203,10 @@ if(LIBCREATE_BUILD_TESTS AND ${GTEST_FOUND}) else() message("No GTest installation found. Skipping tests.") endif() + +############# +# Packaging # +############# + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(Packing) \ No newline at end of file diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..c303ca9 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:24.04 + +RUN apt update && \ + apt install -y \ + build-essential cmake file \ + libboost-system-dev libboost-thread-dev \ + libgtest-dev googletest && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /libcreate +COPY . . + +WORKDIR /libcreate/build +RUN cmake -B /libcreate/build -S /libcreate -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" && \ + cmake --build /libcreate/build --config Release && \ + ctest -C Release --output-on-failure && \ + cpack --build /libcreate/build -G DEB diff --git a/cmake/Packing.cmake b/cmake/Packing.cmake new file mode 100644 index 0000000..93b1feb --- /dev/null +++ b/cmake/Packing.cmake @@ -0,0 +1,50 @@ +# these are cache variables, so they could be overwritten with -D, +set(CPACK_PACKAGE_NAME ${PROJECT_NAME} + CACHE STRING "The resulting package name" +) +# which is useful in case of packing only selected components instead of the whole thing +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ library for interfacing with iRobot's Create 1 and 2" + CACHE STRING "Package description for the package metadata" +) +set(CPACK_PACKAGE_VENDOR "Verein zur Förderung von Jugendlichen durch Robotikwettbewerbe") + +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +SET(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/_packages") + +# https://unix.stackexchange.com/a/11552/254512 +set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/some")#/${CMAKE_PROJECT_VERSION}") + +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) + +set(CPACK_PACKAGE_CONTACT "kontakt@comp-air.at") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "comp-air dev team") + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + +# Discover and set dependencies correcly +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES) + +# The installation path directory should have 0755 permissions +set( + CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE +) + +# package name for deb. If set, then instead of some-application-0.9.2-Linux.deb +# you'll get some-application_0.9.2_amd64.deb (note the underscores too) +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +# that is if you want every group to have its own package, +# although the same will happen if this is not set (so it defaults to ONE_PER_GROUP) +# and CPACK_DEB_COMPONENT_INSTALL is set to YES +set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)#ONE_PER_GROUP) +# without this you won't be able to pack only specified component +set(CPACK_DEB_COMPONENT_INSTALL YES) + +include(CPack) \ No newline at end of file diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..e69de29