From e60281acb706e71b16e9105d25bf45b41b81126a Mon Sep 17 00:00:00 2001 From: Marcel Graf Date: Fri, 21 Nov 2025 21:01:43 +0100 Subject: [PATCH] Created Dockerfile that sets up a container on which the requested tasks can be run. Created yaml.sh for setting up the desired yaml-cpp installation while the container is built. Created a CMakeLists.txt. Adapted build_and_run.sh. --- CMakeLists.txt | 34 +++++++++++++++++++++++++++++++ Dockerfile | 7 +++++++ build_and_run.sh | 4 ++-- main.cpp | 53 ++++++++++++++++++++++++------------------------ yaml.sh | 28 +++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 Dockerfile create mode 100755 yaml.sh diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5b618f1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +# General +cmake_minimum_required(VERSION 3.16.2) +project(sse_cmake_exercise) + +# Packages +find_package(Boost REQUIRED COMPONENTS filesystem) +find_package(deal.II REQUIRED) +find_package(yaml-cpp REQUIRED) + +# Source files +set(SOURCE_FILES + fem/fem.cpp + flatset/flatset.cpp + filesystem/filesystem.cpp + yamlParser/yamlParser.cpp +) + +# Header files +set(HEADER_FILES + fem/fem.hpp + flatset/flatset.hpp + filesystem/filesystem.hpp + yamlParser/yamlParser.hpp +) + +# Executable +add_executable(${PROJECT_NAME} main.cpp ${SOURCE_FILES} ${HEADER_FILES}) + +# deal.II +deal_ii_initialize_cached_variables() +deal_ii_setup_target(${PROJECT_NAME}) + +# Linking +target_link_libraries(${PROJECT_NAME} ${Boost_FILESYSTEM_LIBRARY} yaml-cpp) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f7054f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:24.04 + +RUN mkdir yaml +COPY yaml.sh /yaml/yaml.sh + +RUN apt-get update && apt-get install -y build-essential cmake libdeal.ii-dev libboost-all-dev wget +RUN ./yaml/yaml.sh \ No newline at end of file diff --git a/build_and_run.sh b/build_and_run.sh index 60c4293..447280e 100755 --- a/build_and_run.sh +++ b/build_and_run.sh @@ -3,5 +3,5 @@ mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Debug .. -make -./main ../yamlParser/config.yml +make -j +./sse_cmake_exercise ../yamlParser/config.yml diff --git a/main.cpp b/main.cpp index 7588360..d74040b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,39 +1,38 @@ -//#include "fem/fem.hpp" -//#include "flatset/flatset.hpp" -//#include "filesystem/filesystem.hpp" -//#include "yamlParser/yamlParser.hpp" +#include "fem/fem.hpp" +#include "flatset/flatset.hpp" +#include "filesystem/filesystem.hpp" +#include "yamlParser/yamlParser.hpp" #include int main(int argc, char *argv[]) { std::cout << "Let's fight with CMake, Docker, and some dependencies!" << std::endl << std::endl; - //std::cout << "Solve Poisson problem with FEM using deal.II" << std::endl; - //Fem fem; - //fem.run(); - //std::cout << std::endl; + std::cout << "Solve Poisson problem with FEM using deal.II" << std::endl; + Fem fem; + fem.run(); + std::cout << std::endl; - //std::cout << "Modify a flat set using boost container" << std::endl; - //modifyAndPrintSets(); - //std::cout << std::endl; - - //std::cout << "Inspect the current directory using boost filesystem" << std::endl; - //inspectDirectory(); - //std::cout << std::endl; + std::cout << "Modify a flat set using boost container" << std::endl; + modifyAndPrintSets(); + std::cout << std::endl; + std::cout << "Inspect the current directory using boost filesystem" << std::endl; + inspectDirectory(); + std::cout << std::endl; - //if ( argc == 2 ) - //{ - // const std::string yamlFile( argv[1] ); - // std::cout << "Parse some yaml file with yaml-cpp" << std::endl; - // std::cout << " " << yamlFile << std::endl; - // parseConfig( yamlFile ); - //} - //else - //{ - // std::cout << "To parse a yaml file please specify file on command line" << std::endl; - // std::cout << " ./main YAMLFILE" << std::endl; - //} + if ( argc == 2 ) + { + const std::string yamlFile( argv[1] ); + std::cout << "Parse some yaml file with yaml-cpp" << std::endl; + std::cout << " " << yamlFile << std::endl; + parseConfig( yamlFile ); + } + else + { + std::cout << "To parse a yaml file please specify file on command line" << std::endl; + std::cout << " ./main YAMLFILE" << std::endl; + } return 0; } diff --git a/yaml.sh b/yaml.sh new file mode 100755 index 0000000..04382f6 --- /dev/null +++ b/yaml.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +mkdir yaml && cd yaml + +# config yamlcpp + +YAMLCPP_VERSION="0.6.3" +YAMLCPP_TAR_GZ="yaml-cpp-${YAMLCPP_VERSION}.tar.gz" +YAMLCPP_URL="https://github.com/jbeder/yaml-cpp/archive/refs/tags/${YAMLCPP_TAR_GZ}" +PREFIX_DIR="$(pwd)/yaml-cpp-${YAMLCPP_VERSION}" + +# download yamlcpp +mkdir -p build +wget -O "build/${YAMLCPP_TAR_GZ}" "${YAMLCPP_URL}" +tar -xzf "build/${YAMLCPP_TAR_GZ}" -C build + +# build yamlcpp +mkdir -p "build/yaml-cpp-build-${YAMLCPP_VERSION}" "${PREFIX_DIR}" + +cmake -S "build/yaml-cpp-yaml-cpp-${YAMLCPP_VERSION}" -B "build/yaml-cpp-build-${YAMLCPP_VERSION}" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}" \ + -DYAML_BUILD_SHARED_LIBS=ON \ + -DYAML_BUILD_TESTS=OFF \ + -DYAML_BUILD_TOOLS=OFF +cmake --build "build/yaml-cpp-build-${YAMLCPP_VERSION}" --target install -j + +echo "Installed yaml-cpp at ${PREFIX_DIR}" \ No newline at end of file