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
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <image-name> .
```

## 2.A Run the Docker Container

To run the Docker container use the following command:

```bash
docker run --rm -it <image-name>
```

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 <image-name>
```

## 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.
52 changes: 26 additions & 26 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

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;
}