Skip to content

Add installation and packaging targets#19

Closed
Nikhil-4595 wants to merge 2 commits intoSimulation-Software-Engineering:mainfrom
Nikhil-4595:main
Closed

Add installation and packaging targets#19
Nikhil-4595 wants to merge 2 commits intoSimulation-Software-Engineering:mainfrom
Nikhil-4595:main

Conversation

@Nikhil-4595
Copy link

@Nikhil-4595 Nikhil-4595 commented Dec 8, 2025

Gitlab Username : nikhilnl

This commit completes the mandatory CPack assignment and optional bonus tasks.

Mandatory features:

  • Added full installation targets in CMake:
    • cpackexample → /bin/
    • cpackexamplelib (static or shared via standard BUILD_SHARED_LIBS) → /lib/
    • public headers → /include/cpackexamplelib/
  • Added cmake/CPackConfig.cmake defining:
    • package metadata (name, maintainer, vendor, homepage, description)
    • TGZ and DEB generators only
    • /usr install prefix for Debian packaging
    • automatic dependency detection (CPACK_DEBIAN_PACKAGE_SHLIBDEPS=YES)
    • stripping of binaries (CPACK_STRIP_FILES=YES)
  • Verified:
    • make install installs correctly
    • make package produces *.tar.gz and *.deb packages
    • Debian package installs via apt install ./pkg.deb
    • Installed binary runs correctly from /usr/bin

Lintian:

  • Resolved major issues: missing maintainer phrase, missing description, unstripped binaries, undeclared ELF dependencies.
  • Remaining warnings (expected for this exercise): no changelog, no copyright, no manpage.
  • Initial and final lintian reports included in this PR.

How to build and test:

  1. Build the Docker image:
docker build -t cpack-exercise .
  1. Automated build and packaging (bonus workflow):

Run the container:

docker run --rm \
  --mount type=bind,source="$(pwd)",target=/mnt/cpack-exercise \
  cpack-exercise

Behavior:

  • The project is configured, built, and packaged inside the container
  • The build happens in a temporary directory under /tmp
  • Only the final artifacts are copied back to the host

After the container exits on the host:

ls packages

Expected output:

  • cpackexample_0.1.0_arm64.deb
  • cpackexample-0.1.0-Linux.tar.gz

This commit completes all required tasks and implements the full optional automation workflow.

Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to run your code. Parts of your solution seem generated, are they?

CMakeLists.txt Outdated
# Option for bonus task: allow building the library as shared
option(CPACKEXAMPLE_BUILD_SHARED "Build cpackexamplelib as a shared library" OFF)

if (CPACKEXAMPLE_BUILD_SHARED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the variable different to BUILD_SHARED_LIBS?

Comment on lines 18 to 23
set(CPACK_PACKAGE_VERSION_MAJOR 0)
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}"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better take the versions from the project, don't hard-code here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, Sure. Will take care of it next time.

Dockerfile Outdated
ENV PATH=$PATH:/usr/local/bin/

# Script to configure, build (shared), and create packages automatically
RUN cat > /usr/local/bin/build-and-package.sh << 'EOF'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN cat > /usr/local/bin/build-and-package.sh << 'EOF'
RUN <<'EOF'
cat > /usr/local/bin/build-and-package.sh

Did your code work for you?

Copy link
Author

@Nikhil-4595 Nikhil-4595 Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did, as per my knowledge. What is the issue @uekerman ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker build -t cpack-exercise .
[+] Building 0.1s (2/2) FINISHED                                                                                   docker:default
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 2.15kB                                                                                       0.0s
Dockerfile:37
--------------------
  35 |     RUN cat > /usr/local/bin/build-and-package.sh << 'EOF'
  36 |     #!/bin/bash
  37 | >>> set -euo pipefail
  38 |     
  39 |     SRC_DIR=/mnt/cpack-exercise
--------------------
ERROR: failed to solve: dockerfile parse error on line 37: unknown instruction: set (did you mean user?)

I am using:

docker --version
Docker version 24.0.6, build ed223bc

Copy link
Author

@Nikhil-4595 Nikhil-4595 Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @uekerman,
I tried to reproduce the Docker build error (unknown instruction: set) on my side but was not able to get it.

image

On my machine, I am using Docker Desktop 28.5.1. I tested the Dockerfile both with BuildKit enabled and disabled (using DOCKER_BUILDKIT=0), and in both cases it builds successfully, including the RUN cat > … << 'EOF' block with indented content.

image

I believe the build failure you're experiencing is due to a Docker version difference. You mentioned using Docker 24.0.6, which appears to have stricter parsing rules for heredoc syntax in Dockerfiles. In older Docker versions, the heredoc content (the lines between << 'EOF' and EOF) must start at the beginning of the line with no leading whitespace. When indentation is present, the legacy parser interprets those indented lines as Dockerfile instructions rather than heredoc content, which causes the error: unknown instruction: set.

Newer Docker versions (25.0+) introduced support for indented heredoc content, making the syntax more flexible and readable. Docker Desktop 28.5.1 supports this feature regardless of whether BuildKit is explicitly enabled or disabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting the same problem with Docker version 28.1.1 :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fails on Ubuntu 24.04

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's strange. What shall I do now? Shall I make the changes in the docker file as others?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @uekerman, I updated the CMake setup to avoid hard-coding the package version in CPackConfig.cmake. I also switched to the standard BUILD_SHARED_LIBS mechanism instead of a custom variable, so the shared/static behavior follows common CMake practice.

Additionally, I simplified the Docker automation to follow the expected workflow: the project is built and packaged in a temporary directory inside the container, and only the final .deb and .tar.gz artifacts are copied back to the host. With this setup, the heredoc-related build issue should no longer occur.

Please, have a look and then let me know :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works now, thanks for following up 👍

@uekerman uekerman closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants