Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@ 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)
add_library(cpackexamplelib SHARED filesystem/filesystem.cpp fem/fem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp)
add_executable("${PROJECT_NAME}" main.cpp)

target_link_libraries("${PROJECT_NAME}" cpackexamplelib)
target_link_libraries(cpackexamplelib Boost::filesystem ${YAML_CPP_LIBRARIES})

DEAL_II_SETUP_TARGET("${PROJECT_NAME}")
DEAL_II_SETUP_TARGET(cpackexamplelib)

# --- Installation Targets ---

# Install the executable to bin/
install(TARGETS cpackexample DESTINATION bin)

# Install the library to lib/
install(TARGETS cpackexamplelib DESTINATION lib)

# Install header files to include/cpackexamplelib
install(FILES
fem/fem.hpp
filesystem/filesystem.hpp
flatset/flatset.hpp
yamlParser/yamlParser.hpp
DESTINATION include/cpackexamplelib
)

# Include CPack configuration
include(cmake/CPackConfig.cmake)
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib/
ENV PATH $PATH:/usr/local/bin/

CMD ["/bin/bash"]

# Copy the entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Set the script to run automatically
ENTRYPOINT ["/entrypoint.sh"]
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# Packaging with CPack

Repository for the [CPack exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/03_building_and_packaging/cpack_exercise.md). The code is a slightly modified version of the [code used in the CMake exercise](https://github.com/Simulation-Software-Engineering/cmake-exercise).
This repository contains the solution for the CPack exercise. It demonstrates how to package a C++ project (split into a library `cpackexamplelib` and an executable `cpackexample`) into `.tar.gz` and Debian `.deb` packages using CMake and CPack.

## Features

* **CMake Installation Targets:** Configured `make install` to place binaries, libraries, and headers in standard locations (`bin/`, `lib/`, `include/`).
* **CPack Configuration:** Generates `TGZ` and `DEB` packages with proper metadata (maintainer, dependencies, description).
* **Debian Compliance:** Packages follow the `package_version_arch.deb` naming convention and auto-detect dependencies.
* **Automated Build:** Includes a Docker-based workflow to build packages automatically without polluting the host system.

## How to Build and Package

### Option 1: Automated Docker Build (Bonus Task)

This is the easiest method. It builds the shared library and packages inside a container and copies the results to your current directory.

1. Build the Docker image:
```bash
docker build -t cpack-exercise .
```

2. Run the automation script:
```bash
docker run --rm --mount type=bind,source="$(pwd)",target=/mnt/cpack-exercise cpack-exercise
```
*(Note: On Windows PowerShell, use `${PWD}` instead of `$(pwd)`)*

### Option 2: Manual Build

If you prefer to build manually inside the container:

1. Enter the container:
```bash
docker run --rm -it --mount type=bind,source="$(pwd)",target=/mnt/cpack-exercise cpack-exercise /bin/bash
```

2. Build and package:
```bash
mkdir build && cd build
cmake ..
make package
```

## Lintian Checks

The Debian package has been verified using `lintian`. Debug symbols are stripped to ensure the binary size is optimized and compliant.
27 changes: 27 additions & 0 deletions cmake/CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --- CPack Configuration ---

# Package Information
set(CPACK_PACKAGE_VENDOR "Simulation Software Engineering")
set(CPACK_PACKAGE_CONTACT "AbdulRehman<GitLab username: @rehmanal>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A simple CPack exercise project")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/AbdulRehman-Fayyaz/cpack-exercise-wt2526")

# Generate both .tar.gz (TGZ) and Debian (.deb) packages
set(CPACK_GENERATOR "TGZ;DEB")

# Debian specific setting (Required for .deb creation)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "AbdulRehman(@rehmanal)")

# --- Debian Specific Configuration ---

# 1. Enable dependency auto-detection (shlibdeps)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

# 2. Use the default Debian naming scheme (package_version_arch.deb)
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")

# Strip debug symbols to reduce package size and fix Lintian error
set(CPACK_STRIP_FILES TRUE)

# This must be the last command in this file
include(CPack)
20 changes: 20 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

# 1. Create an internal build directory (hidden from host)
mkdir -p /tmp/build
cd /tmp/build

# 2. Run CMake pointing to the mounted source code
echo "Configuring project..."
cmake /mnt/cpack-exercise

# 3. Build the packages
echo "Building packages..."
make package

# 4. Copy the generated packages back to the host
echo "Copying packages to host..."
cp *.deb *.tar.gz /mnt/cpack-exercise/

echo "Done! Packages are in your host directory."