diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..58eb0f0 --- /dev/null +++ b/CMakeLists.txt @@ -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) + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b232d9b --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 9e27f1f..dd49b8d 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/main b/main new file mode 100755 index 0000000..26d02cb Binary files /dev/null and b/main differ 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; }