From 6de66c6ee7d8eee3564dc10ff161fbafcc0d5a8b Mon Sep 17 00:00:00 2001 From: Ricardo Sandi <50056806+RickySandi@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:52:11 +0000 Subject: [PATCH] Add building and container recipes --- CMakeLists.txt | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++ main.cpp | 52 +++++++++++++++++++++++++------------------------- 3 files changed, 119 insertions(+), 26 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 Dockerfile diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4eacf8a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.14) + +project(FightingDependencies) + +# --- 1. Find Dependencies --- + +# Boost: We need filesystem (linked) and system. +# Container is header-only so it comes along for the ride. +find_package(Boost REQUIRED COMPONENTS filesystem system) + +# deal.II: The heavy FEM library +find_package(deal.II REQUIRED) + +# yaml-cpp: The manual install +find_package(yaml-cpp REQUIRED) + + +# --- 2. Define the Executable --- + +add_executable(main + main.cpp + # We must compile the implementation files in the subdirectories + flatset/flatset.cpp + filesystem/filesystem.cpp + fem/fem.cpp + yamlParser/yamlParser.cpp +) + + +# --- 3. Include Directories --- + +# This allows main.cpp to do #include "flatset.hpp" without adding the path prefix +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 +) + + +# --- 4. Link Libraries --- + +# Link Boost and Yaml +target_link_libraries(main + Boost::filesystem + yaml-cpp +) + +# Deal.II usually prefers its own macro to setup the target +# This attaches all necessary libraries and compile flags to 'main' +DEAL_II_SETUP_TARGET(main) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..69ad09d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM ubuntu:24.04 + +# 1. Install standard build tools and library dependencies available in repo +# - build-essential: gcc/g++ and make +# - cmake: build system +# - wget/unzip: to fetch yaml-cpp +# - libboost-all-dev: Boost Container and Filesystem +# - libdeal.ii-dev: The FEM library +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + git \ + wget \ + unzip \ + vim \ + libboost-all-dev \ + libdeal.ii-dev \ + && rm -rf /var/lib/apt/lists/* + +# 2. The "Bonus" Task: Build yaml-cpp v0.6.3 from source +WORKDIR /tmp +RUN wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.zip -O yaml-cpp.zip \ + && unzip yaml-cpp.zip \ + && cd yaml-cpp-yaml-cpp-0.6.3 \ + && mkdir build \ + && cd build \ + && cmake -DYAML_BUILD_SHARED_LIBS=ON .. \ + && make -j$(nproc) \ + && make install \ + && cd /tmp \ + && rm -rf yaml-cpp* + +# 3. Set Environment Variable +# CMake usually installs to /usr/local/lib. We need to tell the OS to look there. +# ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH + ENV LD_LIBRARY_PATH=/usr/local/lib + +# 4. Setup working directory for the user +WORKDIR /root/cmake-exercise + +# Default command (optional, but good for interactive mode) +CMD ["bash"] \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7588360..ba913dc 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; }