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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.14)

project(cmake-exercise)


# Add dependencies like described in the exercise
find_package(deal.II REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem system)

# Add executables, with source files in subdirs
add_executable(
main
main.cpp
flatset/flatset.cpp
filesystem/filesystem.cpp
fem/fem.cpp
yamlParser/yamlParser.cpp
)

# Link the files. When linking like this no extra path is necessary when including in source code
target_include_directories(
main
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/flatset
${CMAKE_CURRENT_SOURCE_DIR}/filesystem
${CMAKE_CURRENT_SOURCE_DIR}/fem
${CMAKE_CURRENT_SOURCE_DIR}/yamlParser
)

# Link libraries
target_link_libraries(
main
Boost::filesystem
yaml-cpp
)

# Setup Deal.II
DEAL_II_SETUP_TARGET(main)

40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# install necessary packages, this step can take a while
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
unzip \
vim \
libeigen3-dev \
libboost-all-dev \
libgmp-dev \
libmpfr-dev \
python3 \
python3-pip \
libdeal.ii-dev \
&& rm -rf /var/lib/apt/lists/*

# install yaml-cpp from GitHub (v.0.6.3)
WORKDIR /tmp
RUN wget -q https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.zip -O yaml-cpp.zip \
&& unzip yaml-cpp.zip \
&& mkdir -p yaml-cpp-yaml-cpp-0.6.3/build \
&& cd yaml-cpp-yaml-cpp-0.6.3/build \
&& cmake -DYAML_BUILD_SHARED_LIBS=on ../ \
&& make -j"$(nproc)" \
&& make install \
&& cd /tmp \
&& rm -rf yaml-cpp-0.6.3.zip yaml-cpp-yaml-cpp-0.6.3

ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"

# Setup workdir to mount, to mount files
WORKDIR /opt/cmake-exercise

CMD ["/bin/bash"]
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# 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).

# Build Docker container and run

Build the Docker container:

```bash
docker build -t cmake-exercise:local
```

*Building the `Dockerfile` could take a while, because many dependencies have to be installed. At my machine it took around 20-30min*

Start the container in interactive mode and mount the current directory:

```bash
docker run -it -v ./:/opt/cmake-exercise cmake-exercise:local
```

Clean up the `./build` directory (this is recommended but may not be required):

```bash
rm -rf build/
```

Run the `./build_and_run.sh`, to test if everything works:
```bash
./build_and_run.sh
```
this should result in a simular output (the following is a bit shortend):
```bash
...
[ 16%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[ 33%] Building CXX object CMakeFiles/main.dir/flatset/flatset.cpp.o
[ 50%] Building CXX object CMakeFiles/main.dir/filesystem/filesystem.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/fem/fem.cpp.o
[ 83%] Building CXX object CMakeFiles/main.dir/yamlParser/yamlParser.cpp.o
[100%] Linking CXX executable main
[100%] Built target main
Let's fight with CMake, Docker, and some dependencies!

Solve Poisson problem with FEM using deal.II
FEM results available in `solution.vtk`. Try visualizing with Paraview.

Modify a flat set using boost container
Elements in s1: 1 2 3 4

Inspect the current directory using boost filesystem
"." is a directory containing:
"CMakeCache.txt"
"CMakeFiles"
"Makefile"
"cmake_install.cmake"
"main"
"solution.vtk"

Parse some yaml file with yaml-cpp
../yamlParser/config.yml
Version: 1.2.3
root@e22431c56c9b:/opt/cmake-exercise# exit
exit
[silas@manacor cmake-exercise]$ ls
```
Binary file added main
Binary file not shown.
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;
}