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
48 changes: 46 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,63 @@ project("cpackexample" VERSION 0.1.0)

FIND_PACKAGE(deal.II 9.5 REQUIRED
HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
)
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)

add_library(cpackexamplelib filesystem/filesystem.cpp fem/fem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp)
# 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)
add_library(cpackexamplelib SHARED
filesystem/filesystem.cpp
fem/fem.cpp
flatset/flatset.cpp
yamlParser/yamlParser.cpp
)
else()
add_library(cpackexamplelib STATIC
filesystem/filesystem.cpp
fem/fem.cpp
flatset/flatset.cpp
yamlParser/yamlParser.cpp
)
endif()

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)

# Install the executable into <prefix>/bin
install(
TARGETS cpackexample
RUNTIME DESTINATION bin
)

# Install the library into <prefix>/lib
install(
TARGETS cpackexamplelib
ARCHIVE DESTINATION lib # static libraries (.a)
LIBRARY DESTINATION lib # shared libraries (.so)
INCLUDES DESTINATION include/cpackexamplelib
)

# Install public headers into <prefix>/include/cpackexamplelib
install(
FILES
fem/fem.hpp
filesystem/filesystem.hpp
flatset/flatset.hpp
yamlParser/yamlParser.hpp
DESTINATION include/cpackexamplelib
)

include(cmake/CPackConfig.cmake)
97 changes: 72 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,75 @@
From ubuntu:24.04
FROM ubuntu:24.04

# Install a few dependencies
# Install dependencies (incl. dpkg-dev for shlibdeps)
RUN apt-get -qq update && \
apt-get -qq -y install \
build-essential \
cmake \
git \
libboost-all-dev \
wget \
libdeal.ii-dev \
vim \
tree \
lintian \
unzip

# 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"]
build-essential \
cmake \
git \
libboost-all-dev \
wget \
libdeal.ii-dev \
vim \
tree \
lintian \
unzip \
dpkg-dev && \
rm -rf /var/lib/apt/lists/*

# Get, unpack, build, and install yaml-cpp (shared)
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

# Make sure /usr/local is visible
ENV LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib/
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
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'
#!/bin/bash
set -euo pipefail

SRC_DIR=/mnt/cpack-exercise
BUILD_DIR=$(mktemp -d /tmp/cpack-build-XXXXXX)
INSTALL_PREFIX=/tmp/cpack-install
OUT_DIR=${CPACK_OUTPUT_DIR:-$SRC_DIR/packages}

echo "Using source directory: $SRC_DIR"
echo "Using build directory: $BUILD_DIR"
echo "Using install prefix: $INSTALL_PREFIX"
echo "Using output directory: $OUT_DIR"

mkdir -p "$OUT_DIR"

# Configure: shared library + install prefix
cmake -S "$SRC_DIR" -B "$BUILD_DIR" \
-DCPACKEXAMPLE_BUILD_SHARED=ON \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX"

# Build
cmake --build "$BUILD_DIR" -- -j"$(nproc)"

# Create packages (TGZ + DEB)
cmake --build "$BUILD_DIR" --target package

# Copy only the final packages to the mounted output directory
cp "$BUILD_DIR"/cpackexample-*.tar.gz "$OUT_DIR"/
cp "$BUILD_DIR"/cpackexample_*.deb "$OUT_DIR"/

# Clean up temporary build and install dirs (container only)
rm -rf "$BUILD_DIR" "$INSTALL_PREFIX"

echo "Packages copied to: $OUT_DIR"
EOF

RUN chmod +x /usr/local/bin/build-and-package.sh

# Default: run the automated build-and-package script
CMD ["/usr/local/bin/build-and-package.sh"]
50 changes: 50 additions & 0 deletions cmake/CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Basic package information
set(CPACK_PACKAGE_NAME "cpackexample")
set(CPACK_PACKAGE_VENDOR "Nikhil / University Of Stuttgart")
set(CPACK_PACKAGE_CONTACT "n.k.2449837@gmail.com")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"Finite Element / Boost / YAML example packaged with CPack"
)

# Debian wants an extended description (not empty)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION
"Finite element demo application

This package contains a small FEM-based example using deal.II, Boost
and yaml-cpp, packaged with CMake and CPack for the SSE exercise."
)

# Version
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}"
)

# Homepage / project URL (your fork)
set(CPACK_PACKAGE_HOMEPAGE_URL
"https://github.com/Nikhil-4595/cpack-exercise-wt2526"
)

# Only create TGZ and DEB binaries
set(CPACK_GENERATOR "TGZ;DEB")

# Install into /usr so binary ends up in /usr/bin, etc.
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")

# Debian-specific fields
# Lintian wants a 'phrase' (Name <email>) as maintainer
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nikhil <${CPACK_PACKAGE_CONTACT}>")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

# Strip binaries in packages -> fixes 'unstripped-binary-or-object'
set(CPACK_STRIP_FILES YES)

# Let Debian tools detect shared-library dependencies
# -> fixes 'undeclared-elf-prerequisites' and adds proper Depends:
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES)

# Enable CPack
include(CPack)