diff --git a/CMakeLists.txt b/CMakeLists.txt index 94d6c2c..0289e40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ 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) @@ -20,3 +20,23 @@ 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) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bd5207d..5248253 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 8e950e4..bc5fab7 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake new file mode 100644 index 0000000..6c78d22 --- /dev/null +++ b/cmake/CPackConfig.cmake @@ -0,0 +1,27 @@ +# --- CPack Configuration --- + +# Package Information +set(CPACK_PACKAGE_VENDOR "Simulation Software Engineering") +set(CPACK_PACKAGE_CONTACT "AbdulRehman") +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) \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f9283d3 --- /dev/null +++ b/entrypoint.sh @@ -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." \ No newline at end of file