From a17e1955918608b62ce394e29a5e6c637e36c142 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Tue, 25 Nov 2025 16:23:20 +0100 Subject: [PATCH] Add full CMake build system and Docker container setup This commit provides the complete configuration required for the exercise: Let's Fight With CMake, Docker, and Some Dependencies. Key additions: - Added Dockerfile based on Ubuntu 24.04 with all required dependencies: Boost, deal.II, and manual installation of yaml-cpp v0.6.3. - Implemented CMakeLists.txt integrating: * Boost filesystem * deal.II FEM macros (initialize + setup target) * yaml-cpp (found via find_library and linked explicitly) * Project sources and include directories - Updated main.cpp to enable all dependency-based features (FEM solver, Boost flatset, filesystem inspection, YAML parsing). - Added .gitignore and .dockerignore to exclude build artifacts. The resulting Docker image builds successfully and running the container allows executing to compile and run the full program, producing correct outputs including via deal.II. --- .dockerignore | 8 ++++++++ .gitignore | 1 + CMakeLists.txt | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++ main.cpp | 55 +++++++++++++++++++++++++------------------------- 5 files changed, 135 insertions(+), 27 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b66b8ec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +build + +.git + +.gitignore + +.DS_Store + 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..f8d0206 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.16) +project(CMakeExercise LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# CRITICAL: Add link directories BEFORE creating executable +link_directories(/usr/local/lib) + +# ---------- Find Packages ---------- +# Boost (filesystem + header-only container) +find_package(Boost REQUIRED COMPONENTS filesystem system) + +# deal.II (FEM) +find_package(deal.II REQUIRED + HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR} +) + +# yaml-cpp (manually specify since it's in /usr/local) +find_library(YAML_CPP_LIBRARY + NAMES yaml-cpp + PATHS /usr/local/lib + REQUIRED +) + +# ---------- Sources ---------- +set(SOURCES + main.cpp + flatset/flatset.cpp + filesystem/filesystem.cpp + fem/fem.cpp + yamlParser/yamlParser.cpp +) + +# ---------- Create Executable ---------- +add_executable(main ${SOURCES}) + +# ---------- Include Directories ---------- +target_include_directories(main PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${Boost_INCLUDE_DIRS} + /usr/local/include +) + +# ---------- deal.II Setup (must come AFTER add_executable) ---------- +deal_ii_initialize_cached_variables() +deal_ii_setup_target(main) + +# ---------- Link Libraries ---------- +# CRITICAL: yaml-cpp must be linked AFTER deal.II setup +target_link_libraries(main + ${Boost_LIBRARIES} + ${YAML_CPP_LIBRARY} +) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..814b737 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:24.04 + +# Avoid prompts from apt +ENV DEBIAN_FRONTEND=noninteractive + +# Base tools and dev packages +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + unzip \ + wget \ + vim \ + git \ + libboost-all-dev \ + libdeal.ii-dev \ + && rm -rf /var/lib/apt/lists/* + +# Build and install yaml-cpp v0.6.3 from source +WORKDIR /tmp +RUN wget --no-check-certificate https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.6.3.tar.gz \ + && tar -xzf yaml-cpp-0.6.3.tar.gz \ + && cd yaml-cpp-yaml-cpp-0.6.3 \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release -DYAML_BUILD_TESTS=OFF .. \ + && make -j"$(nproc)" \ + && make install \ + && cd /tmp \ + && rm -rf yaml-cpp-* + +# Make sure libraries in /usr/local/lib (yaml-cpp) are found +ENV LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH:-} + +# Workdir for the project +WORKDIR /workspace + +# Copy the repository contents +COPY . /workspace/cmake-exercise + +# Switch into the exercise folder by default +WORKDIR /workspace/cmake-exercise + +# Default command: drop into a shell +CMD ["/bin/bash"] diff --git a/main.cpp b/main.cpp index 7588360..c70927b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,39 +1,40 @@ -//#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 +#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; }