From 740b05ba7ab576ea64921d9bb05689e20f44ba5d Mon Sep 17 00:00:00 2001 From: Felix Kimmerle Date: Thu, 4 Dec 2025 18:53:50 +0100 Subject: [PATCH 1/3] added install and package (tgz, deb) targets --- .gitignore | 1 + CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++++----- changelog | 4 ++++ cmake/CPackConfig.cmake | 25 +++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 changelog create mode 100644 cmake/CPackConfig.cmake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 94d6c2c..798ea93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,12 @@ find_package(Boost 1.83 COMPONENTS filesystem REQUIRED) find_package(yaml-cpp 0.6 REQUIRED) add_library(cpackexamplelib filesystem/filesystem.cpp fem/fem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp) + + +set_target_properties(cpackexamplelib PROPERTIES + PUBLIC_HEADER "fem/fem.hpp;filesystem/filesystem.hpp;flatset/flatset.hpp;yamlParser/yamlParser.hpp" +) + add_executable("${PROJECT_NAME}" main.cpp) target_link_libraries("${PROJECT_NAME}" cpackexamplelib) @@ -20,3 +26,37 @@ target_link_libraries(cpackexamplelib Boost::filesystem ${YAML_CPP_LIBRARIES}) DEAL_II_SETUP_TARGET("${PROJECT_NAME}") DEAL_II_SETUP_TARGET(cpackexamplelib) + + +include(GNUInstallDirs) + +set(LICENSE_FILE "${CMAKE_SOURCE_DIR}/LICENSE") +install( + FILES "${LICENSE_FILE}" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + RENAME "copyright" + COMPONENT doc +) + +set(DEBIAN_CHANGELOG "${CMAKE_SOURCE_DIR}/changelog") +install(FILES "${DEBIAN_CHANGELOG}" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + RENAME "changelog") + + +install(CODE " + set(f \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/doc/${PROJECT_NAME}/changelog.Debian\") + if(EXISTS \"\${f}\") + execute_process(COMMAND sh -c \"gzip -9 -f '\${f}'\") + endif() + ") + +install(TARGETS cpackexample cpackexamplelib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpackexamplelib + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpackexamplelib + ) + +include(cmake/CPackConfig.cmake) diff --git a/Dockerfile b/Dockerfile index bd5207d..670e865 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,14 @@ RUN apt-get -qq update && \ vim \ tree \ lintian \ - unzip + unzip \ + libyaml-cpp-dev # Get, unpack, build, and install yaml-cpp -RUN mkdir software && cd software && \ - wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.zip && unzip yaml-cpp-0.6.3.zip && \ - cd yaml-cpp-yaml-cpp-0.6.3 && mkdir build && cd build && \ - cmake -DYAML_BUILD_SHARED_LIBS=ON .. && make -j4 && make install +# RUN mkdir software && cd software && \ +# wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.zip && unzip yaml-cpp-0.6.3.zip && \ +# cd yaml-cpp-yaml-cpp-0.6.3 && mkdir build && cd build && \ +# cmake -DYAML_BUILD_SHARED_LIBS=ON .. && make -j4 && make install # This is some strange Docker feature. Normally, you don't need to add /usr/local to these ENV LIBRARY_PATH $LIBRARY_PATH:/usr/local/lib/ diff --git a/changelog b/changelog new file mode 100644 index 0000000..eff8d0b --- /dev/null +++ b/changelog @@ -0,0 +1,4 @@ +Example changelog + +- v0.1.0 +Project was born diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake new file mode 100644 index 0000000..ab175fb --- /dev/null +++ b/cmake/CPackConfig.cmake @@ -0,0 +1,25 @@ +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) + + +set(CPACK_DEBIAN_PACKAGE_DESCRIPTION +"SSE artificial cpack example + This package demonstrates packaging with CMake/CPack to TGZ and DEB. + It installs a small binary and a library and ships docs under + /usr/share/doc/${CPACK_PACKAGE_NAME}/." +) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "" + CACHE STRING "Very extensive description of the cpack example module") + +set(CPACK_PACKAGE_VENDOR "Felix Kimmerle") +set(CPACK_PACKAGE_CONTACT "FelixKimmerle@hotmail.com") +set(CPACK_PACKAGE_MAINTAINER "FelixKimmerle <${CPACK_PACKAGE_CONTACT}>") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/FelixKimmerle/cpack-exercise-wt2526") + +set(CPACK_STRIP_FILES "TRUE") +set(CPACK_GENERATOR "TGZ;DEB") +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES) +# set(CPACK_DEBIAN_PACKAGE_VERSION 1) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Felix Kimmerle <${CPACK_PACKAGE_CONTACT}>") + +include(CPack) From a4615aac37edceb38938663ac098ed0947a0d75a Mon Sep 17 00:00:00 2001 From: Felix Kimmerle Date: Thu, 4 Dec 2025 19:45:16 +0100 Subject: [PATCH 2/3] added dummy changelog and manpage and added compression such that the debian package follows the guidelines and lintian does not complain anymore --- CMakeLists.txt | 46 +++++++++++++++++++++++++++++++---------- changelog | 7 ++++--- cmake/CPackConfig.cmake | 6 +++--- man/cpackexample.1 | 7 +++++++ 4 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 man/cpackexample.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 798ea93..67f9c11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ DEAL_II_INITIALIZE_CACHED_VARIABLES() # Uses the FindBoost module of CMake find_package(Boost 1.83 COMPONENTS filesystem REQUIRED) -find_package(yaml-cpp 0.6 REQUIRED) +find_package(yaml-cpp 0.8 REQUIRED) add_library(cpackexamplelib filesystem/filesystem.cpp fem/fem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp) @@ -38,18 +38,42 @@ install( COMPONENT doc ) -set(DEBIAN_CHANGELOG "${CMAKE_SOURCE_DIR}/changelog") -install(FILES "${DEBIAN_CHANGELOG}" - DESTINATION "${CMAKE_INSTALL_DOCDIR}" - RENAME "changelog") +set(DEB_CHANGELOG_SRC "${CMAKE_SOURCE_DIR}/changelog") +set(DEB_CHANGELOG_GZ "${CMAKE_BINARY_DIR}/changelog.gz") + +add_custom_command( + OUTPUT "${DEB_CHANGELOG_GZ}" + COMMAND ${CMAKE_COMMAND} -E env SOURCE_DATE_EPOCH=0 GZIP=-9 sh -c + "gzip -n -c '${DEB_CHANGELOG_SRC}' > '${DEB_CHANGELOG_GZ}'" + DEPENDS "${DEB_CHANGELOG_SRC}" + VERBATIM + ) + add_custom_target(gen_deb_changelog ALL DEPENDS "${DEB_CHANGELOG_GZ}") + + install( + FILES "${DEB_CHANGELOG_GZ}" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + RENAME "changelog.gz" + ) + +set(DEB_MANPAGE_SRC "${CMAKE_SOURCE_DIR}/man/cpackexample.1") +set(DEB_MANPAGE_GZ "${CMAKE_BINARY_DIR}/cpackexample.1.gz") + +add_custom_command( + OUTPUT "${DEB_MANPAGE_GZ}" + COMMAND ${CMAKE_COMMAND} -E env SOURCE_DATE_EPOCH=0 GZIP=-9 sh -c + "gzip -n -c '${DEB_MANPAGE_SRC}' > '${DEB_MANPAGE_GZ}'" + DEPENDS "${DEB_MANPAGE_SRC}" + VERBATIM + ) + add_custom_target(gen_deb_manpage ALL DEPENDS "${DEB_MANPAGE_GZ}") + + install( + FILES "${DEB_MANPAGE_GZ}" + DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" + ) -install(CODE " - set(f \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/doc/${PROJECT_NAME}/changelog.Debian\") - if(EXISTS \"\${f}\") - execute_process(COMMAND sh -c \"gzip -9 -f '\${f}'\") - endif() - ") install(TARGETS cpackexample cpackexamplelib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/changelog b/changelog index eff8d0b..b29985e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ -Example changelog +cpackexample (0.1.0) unstable; urgency=medium -- v0.1.0 -Project was born + * Initial release. + + -- Felix Kimmerle Thu, 04 Dec 2025 12:00:00 +0100 diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake index ab175fb..0520fd0 100644 --- a/cmake/CPackConfig.cmake +++ b/cmake/CPackConfig.cmake @@ -3,9 +3,9 @@ set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "SSE artificial cpack example - This package demonstrates packaging with CMake/CPack to TGZ and DEB. - It installs a small binary and a library and ships docs under - /usr/share/doc/${CPACK_PACKAGE_NAME}/." +This package demonstrates packaging with CMake/CPack to TGZ and DEB. +It installs a small binary and a library and ships docs under +/usr/share/doc/${CPACK_PACKAGE_NAME}/." ) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "" CACHE STRING "Very extensive description of the cpack example module") diff --git a/man/cpackexample.1 b/man/cpackexample.1 new file mode 100644 index 0000000..33f66f7 --- /dev/null +++ b/man/cpackexample.1 @@ -0,0 +1,7 @@ +.TH cpackexample 1 "Dec 2025" "cpackexample 0.1.0" "User Commands" +.SH NAME +cpackexample \- demo binary +.SH SYNOPSIS +.B cpackexample +.SH DESCRIPTION +Demo program for CMake/CPack packaging. From a43c9891f63964874aea6bc26baffe056e63e6aa Mon Sep 17 00:00:00 2001 From: Felix Kimmerle Date: Thu, 4 Dec 2025 20:09:49 +0100 Subject: [PATCH 3/3] Dockerfile now able to produce the packages (tgz, deb) on its own without cluttering the host --- .gitignore | 1 + Dockerfile | 12 ++++++------ docker-entrypoint.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 docker-entrypoint.sh diff --git a/.gitignore b/.gitignore index 84c048a..e2cae22 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /build/ +/dist/ diff --git a/Dockerfile b/Dockerfile index 670e865..60875c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,15 +15,15 @@ RUN apt-get -qq update && \ unzip \ libyaml-cpp-dev -# Get, unpack, build, and install yaml-cpp -# RUN mkdir software && cd software && \ -# wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.zip && unzip yaml-cpp-0.6.3.zip && \ -# cd yaml-cpp-yaml-cpp-0.6.3 && mkdir build && cd build && \ -# cmake -DYAML_BUILD_SHARED_LIBS=ON .. && make -j4 && make install # This is some strange Docker feature. Normally, you don't need to add /usr/local to these ENV LIBRARY_PATH $LIBRARY_PATH:/usr/local/lib/ ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib/ ENV PATH $PATH:/usr/local/bin/ -CMD ["/bin/bash"] +RUN mkdir -p /src /out +COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] + +# CMD ["/bin/bash"] + diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..6d2de59 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail +shopt -s nullglob + +SRC_DIR="/src" +OUT_DIR="/out" +BUILD_DIR="/tmp/build" + +mkdir -p "$BUILD_DIR" +mkdir -p "$OUT_DIR" + + +cmake -S "$SRC_DIR" -B "$BUILD_DIR" \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=ON \ + -DCPACK_PACKAGE_DIRECTORY="$BUILD_DIR" + +make -C "$BUILD_DIR" -j"$(nproc)" package + +artifacts=( + "$BUILD_DIR"/*.tar.gz + "$BUILD_DIR"/*.deb +) + +for f in "${artifacts[@]}"; do + cp -f "$f" "$OUT_DIR/" +done + +ls -l "$OUT_DIR"