From ad401e185ab7448b9cbbd0eecedecdeb0c3f20b4 Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 15:32:20 +0100 Subject: [PATCH 1/7] changes in the main file --- CMakeLists.txt | 31 ++++++++++++++++++++++++++++++ main.cpp | 52 +++++++++++++++++++++++++------------------------- 2 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e1ad237 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION "3.12") + +project("cmake-exercise") + +# C++ Standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Find deal.II +find_package(deal.II 9.0 REQUIRED CONFIG + HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR} +) +# Find boost +find_package(Boost REQUIRED COMPONENTS container filesystem) + +# Find yaml-cpp +find_package(yaml-cpp REQUIRED) + + +add_executable(main main.cpp fem/fem.cpp flatset/flatset.cpp filesystem/filesystem.cpp yamlParser/yamlParser.cpp) + +# Link deal.II +target_link_libraries(main PRIVATE ${DEAL_II_LIBRARIES}) +target_include_directories(main PRIVATE ${DEAL_II_INCLUDE_DIRS}) +target_compile_definitions(main PRIVATE ${DEAL_II_DEFINITIONS}) + +# Link boost +target_link_libraries(main PRIVATE Boost::container Boost::filesystem) + +# Link yaml-cpp +target_link_libraries(main PRIVATE yaml-cpp) 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; } From 3af78c3136cf6b9acc0d959260e2fabb71fbb49c Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 17:26:22 +0100 Subject: [PATCH 2/7] Small change --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1ad237..81ee4b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION "3.12") +cmake_minimum_required(VERSION 3.12) -project("cmake-exercise") +project(main) # C++ Standard set(CMAKE_CXX_STANDARD 17) From 97bb5a04abec0bbbc1fbcd036b12f1ba6133a999 Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 22:25:41 +0100 Subject: [PATCH 3/7] final modification hopefully -yml 0.6.3 -CMakeLists added -Dockerfile configured --- CMakeLists.txt | 41 +++++++++++++++++++++++------------------ Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 Dockerfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ee4b0..3dd260c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,36 @@ cmake_minimum_required(VERSION 3.12) -project(main) - # C++ Standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# Find deal.II -find_package(deal.II 9.0 REQUIRED CONFIG - HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR} +# 1. Deal.II suchen +find_package(deal.II 9.0 REQUIRED + HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} ) -# Find boost -find_package(Boost REQUIRED COMPONENTS container filesystem) -# Find yaml-cpp -find_package(yaml-cpp REQUIRED) +# 2. Variablen initialisieren (Wichtig!) +deal_ii_initialize_cached_variables() +project(main) -add_executable(main main.cpp fem/fem.cpp flatset/flatset.cpp filesystem/filesystem.cpp yamlParser/yamlParser.cpp) +# 3. Deine ZUSÄTZLICHEN Abhängigkeiten finden (die nicht zu deal.II gehören) +find_package(Boost REQUIRED COMPONENTS container filesystem) +find_package(yaml-cpp REQUIRED) -# Link deal.II -target_link_libraries(main PRIVATE ${DEAL_II_LIBRARIES}) -target_include_directories(main PRIVATE ${DEAL_II_INCLUDE_DIRS}) -target_compile_definitions(main PRIVATE ${DEAL_II_DEFINITIONS}) +# 4. Dein Executable mit allen Source-Files +add_executable(main + main.cpp + fem/fem.cpp + flatset/flatset.cpp + filesystem/filesystem.cpp + yamlParser/yamlParser.cpp +) -# Link boost -target_link_libraries(main PRIVATE Boost::container Boost::filesystem) +# 5. DER MAGISCHE BEFEHL +# Das verlinkt automatisch MPI, Kokkos, Trilinos, OpenMP, etc. +deal_ii_setup_target(main) -# Link yaml-cpp -target_link_libraries(main PRIVATE yaml-cpp) +# 6. Nur noch deine eigenen Zusatz-Libs linken +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..5600d08 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# Dockerfile +FROM ubuntu:24.04 + + +ENV DEBIAN_FRONTEND=noninteractive + +# Update + install in EINEM Schritt +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 + +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..c830b8b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,42 @@ # 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) + +## 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 build -t cmake-exercise . +``` + +## 2. Run the Docker Container + +To run the Docker container use the following command: + +```bash +docker run --rm -it /bin/bash +``` + +You will find yourself in a bash shell inside the container in the directory `/mnt/hst`, where the project has been cloned. + +**Alternatively** + +If you want to mount a local directory into the container, you can use the `-v` option. For example: + +```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. From 76af3d3f3647ca33ee2d446c17a3d2cc2c711053 Mon Sep 17 00:00:00 2001 From: David Enoghama <61471574+the-mr-dave@users.noreply.github.com> Date: Sun, 23 Nov 2025 22:39:37 +0100 Subject: [PATCH 4/7] Update README I had some flaws in my README and needed to correct them --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c830b8b..a13523a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Repository with the solution can be found here: [enoghadd solution](https:// To build the Docker image for this project, run the following command in your terminal from the directory containing the Dockerfile: ```bash -docker build -t cmake-exercise . +docker buildx build --no-cache -t . ``` ## 2. Run the Docker Container @@ -17,7 +17,7 @@ docker build -t cmake-exercise . To run the Docker container use the following command: ```bash -docker run --rm -it /bin/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. From da24d3f207e006a419233b84ec1169fb33154c7d Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 22:42:51 +0100 Subject: [PATCH 5/7] added my setup --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c830b8b..2893419 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Repository for the [CMake exercise](https://github.com/Simulation-Software-Engin 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: From 0bacf243f38601b0ae6a902a18bdd814b45a042c Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 22:52:03 +0100 Subject: [PATCH 6/7] Next final one --- CMakeLists.txt | 13 ++++++------- Dockerfile | 3 ++- README.md | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd260c..e7c397d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,21 +4,21 @@ cmake_minimum_required(VERSION 3.12) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# 1. Deal.II suchen +# Deal.II suchen find_package(deal.II 9.0 REQUIRED HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} ) -# 2. Variablen initialisieren (Wichtig!) + deal_ii_initialize_cached_variables() project(main) -# 3. Deine ZUSÄTZLICHEN Abhängigkeiten finden (die nicht zu deal.II gehören) + find_package(Boost REQUIRED COMPONENTS container filesystem) find_package(yaml-cpp REQUIRED) -# 4. Dein Executable mit allen Source-Files + add_executable(main main.cpp fem/fem.cpp @@ -27,10 +27,9 @@ add_executable(main yamlParser/yamlParser.cpp ) -# 5. DER MAGISCHE BEFEHL -# Das verlinkt automatisch MPI, Kokkos, Trilinos, OpenMP, etc. + deal_ii_setup_target(main) -# 6. Nur noch deine eigenen Zusatz-Libs linken + target_link_libraries(main Boost::container Boost::filesystem) target_link_libraries(main yaml-cpp) diff --git a/Dockerfile b/Dockerfile index 5600d08..621ed5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive -# Update + install in EINEM Schritt +# Update and install in one step RUN apt-get update && apt-get install -y \ build-essential \ cmake \ @@ -25,6 +25,7 @@ RUN apt-get update && apt-get install -y \ 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 && \ diff --git a/README.md b/README.md index d508819..e91ed9d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ To build the Docker image for this project, run the following command in your te docker buildx build --no-cache -t . ``` -## 2. Run the Docker Container +## 2.A Run the Docker Container To run the Docker container use the following command: @@ -26,7 +26,7 @@ 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. -**Alternatively** +## 2.B Alternatively If you want to mount a local directory into the container, you can use the `-v` option. For example: From 5ca640c66ef4ec3c93ce7619f089a55a4ebbc022 Mon Sep 17 00:00:00 2001 From: David Enoghama Date: Sun, 23 Nov 2025 22:52:35 +0100 Subject: [PATCH 7/7] Final README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e91ed9d..f4cbd6e 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ 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 Alternatively +## 2.B Run the Docker Container with mounted directory -If you want to mount a local directory into the container, you can use the `-v` option. For example: +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