diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e7c397d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.12) + +# C++ Standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Deal.II suchen +find_package(deal.II 9.0 REQUIRED + HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} +) + + +deal_ii_initialize_cached_variables() + +project(main) + + +find_package(Boost REQUIRED COMPONENTS container filesystem) +find_package(yaml-cpp REQUIRED) + + +add_executable(main + main.cpp + fem/fem.cpp + flatset/flatset.cpp + filesystem/filesystem.cpp + yamlParser/yamlParser.cpp +) + + +deal_ii_setup_target(main) + + +target_link_libraries(main Boost::container Boost::filesystem) +target_link_libraries(main yaml-cpp) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..621ed5c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# Dockerfile +FROM ubuntu:24.04 + + +ENV DEBIAN_FRONTEND=noninteractive + +# Update and install in one step +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + unzip \ + wget \ + vim \ + git \ + g++ \ + libblas-dev \ + liblapack-dev \ + libboost-all-dev \ + libhdf5-dev \ + libmetis-dev \ + libopenmpi-dev \ + openmpi-bin \ + libdeal.ii-dev \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /tmp + +# Used AI to generate this part +RUN wget https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-0.6.3.tar.gz -O yaml-cpp.tar.gz && \ + tar -xzf yaml-cpp.tar.gz && \ + cd yaml-cpp-yaml-cpp-0.6.3 && \ + mkdir build && cd build && \ + # CMake konfigurieren: Release Mode und Shared Libraries sind wichtig + cmake .. -DCMAKE_BUILD_TYPE=Release -DYAML_BUILD_SHARED_LIBS=ON && \ + # Bauen (mit allen Kernen) und Installieren + make -j$(nproc) && \ + make install && \ + # Aufräumen (Source-Dateien löschen, um Image klein zu halten) + cd /tmp && rm -rf yaml-cpp* + +WORKDIR /mnt/hst + +RUN git clone https://github.com/the-mr-dave/cmake-exercise.git . + +# CMD ["./build_and_run.sh"] diff --git a/README.md b/README.md index 9e27f1f..f4cbd6e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,46 @@ # Let's Fight With CMake, Docker, and Some Dependencies Repository for the [CMake exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/03_building_and_packaging/cmake_exercise.md). + +The Repository with the solution can be found here: [enoghadd solution](https://github.com/the-mr-dave/cmake-exercise.git) + +## My Setup + +I used Docker under Windows 11 with WSL2 backend. + +## 1. Build the Docker Image + +To build the Docker image for this project, run the following command in your terminal from the directory containing the Dockerfile: + +```bash +docker buildx build --no-cache -t . +``` + +## 2.A Run the Docker Container + +To run the Docker container use the following command: + +```bash +docker run --rm -it +``` + +You will find yourself in a bash shell inside the container in the directory `/mnt/hst`, where the project has been cloned. + +## 2.B Run the Docker Container with mounted directory + +If you want to mount a local directory into the container, go into you directory and use the following command: + +```bash +docker run --rm -it --mount type=bind,source="$(pwd)",target=/mnt/hst +``` + +## 3. Build and Run the Project + +Run in the container: + +```bash +./build_and_run.sh +``` + +The script will create a build directory, run CMake to configure the project, compile it, and then execute the resulting binary with a sample configuration file. +The dockerfile has impplemented the bonus part, where the container uses [v0.6.3](https://github.com/jbeder/yaml-cpp/releases/tag/yaml-cpp-0.6.3) of yaml-cpp instead of the latest version. diff --git a/main.cpp b/main.cpp index 7588360..08bc4a9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,39 +1,39 @@ -//#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 << "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 << "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; }