From 59b7ec6713f4ab4a8d1dff9a28847124e16b3cbd Mon Sep 17 00:00:00 2001 From: Kilian Krampf Date: Wed, 27 Nov 2024 16:22:37 +0100 Subject: [PATCH 1/3] Create package.py for Spack package --- package.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 package.py diff --git a/package.py b/package.py new file mode 100644 index 0000000..e4abb42 --- /dev/null +++ b/package.py @@ -0,0 +1,43 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +# ---------------------------------------------------------------------------- +# If you submit this package back to Spack as a pull request, +# please first remove this boilerplate and all FIXME comments. +# +# This is a template package file for Spack. We've put "FIXME" +# next to all the things you'll want to change. Once you've handled +# them, you can save this file and test your package like this: +# +# spack install spack-exercise +# +# You can edit this file again by typing: +# +# spack edit spack-exercise +# +# See the Spack documentation for more information on packaging. +# ---------------------------------------------------------------------------- + +from spack.package import * + + +class SpackExercise(CMakePackage): + """Example Spack-Package for the spack-exercise of SSE 24/25""" + + homepage = "https://simulation-software-engineering.github.io/homepage/" + url = "https://github.com/Simulation-Software-Engineering/spack-exercise/archive/refs/tags/v0.3.0.tar.gz" + + maintainers("menkalian") + + license("MIT License", checked_by="menkalian") + + version("0.3.0", sha256="e54a4c037941d85a22fb3e6e73195df8448cf69a96aa44ef374ac518344812f0") + version("0.2.0", sha256="3dd6b4cc0f7aff179d8e290bc3879056237ae372738a4bd7222f6450fbcdfc77") + version("0.1.0", sha256="cac78e641cb703e3fe51956f91fe8347ac52f74ef037d8eadae5777c65a19a00") + + depends_on("cxx", type="build") + + depends_on("boost", when="@0.2.0:") + depends_on("yaml-cpp", when="@0.3.0:") From f113e1a91a05be042c063300029df4200225bb05 Mon Sep 17 00:00:00 2001 From: Kilian Krampf Date: Wed, 27 Nov 2024 16:28:39 +0100 Subject: [PATCH 2/3] Optional task: Add repository and main branch as version --- package.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/package.py b/package.py index e4abb42..5fd3062 100644 --- a/package.py +++ b/package.py @@ -3,23 +3,6 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) -# ---------------------------------------------------------------------------- -# If you submit this package back to Spack as a pull request, -# please first remove this boilerplate and all FIXME comments. -# -# This is a template package file for Spack. We've put "FIXME" -# next to all the things you'll want to change. Once you've handled -# them, you can save this file and test your package like this: -# -# spack install spack-exercise -# -# You can edit this file again by typing: -# -# spack edit spack-exercise -# -# See the Spack documentation for more information on packaging. -# ---------------------------------------------------------------------------- - from spack.package import * @@ -28,11 +11,13 @@ class SpackExercise(CMakePackage): homepage = "https://simulation-software-engineering.github.io/homepage/" url = "https://github.com/Simulation-Software-Engineering/spack-exercise/archive/refs/tags/v0.3.0.tar.gz" + git = "https://github.com/Simulation-Software-Engineering/spack-exercise.git" maintainers("menkalian") license("MIT License", checked_by="menkalian") + version("main", branch="main") version("0.3.0", sha256="e54a4c037941d85a22fb3e6e73195df8448cf69a96aa44ef374ac518344812f0") version("0.2.0", sha256="3dd6b4cc0f7aff179d8e290bc3879056237ae372738a4bd7222f6450fbcdfc77") version("0.1.0", sha256="cac78e641cb703e3fe51956f91fe8347ac52f74ef037d8eadae5777c65a19a00") @@ -41,3 +26,4 @@ class SpackExercise(CMakePackage): depends_on("boost", when="@0.2.0:") depends_on("yaml-cpp", when="@0.3.0:") + From 41c256a367a96b98ecac9fcf6e807d18917f726c Mon Sep 17 00:00:00 2001 From: Kilian Krampf Date: Wed, 27 Nov 2024 16:48:37 +0100 Subject: [PATCH 3/3] Optional task: Add spack package options --- CMakeLists.txt | 39 ++++++++++++++++++++++++++++----------- change_git_repo.patch | 8 ++++++++ filesystem/filesystem.cpp | 10 ++++++++++ flatset/flatset.cpp | 9 +++++++++ package.py | 14 ++++++++++++-- package2.py | 39 +++++++++++++++++++++++++++++++++++++++ yamlParser/yamlParser.cpp | 13 ++++++++++++- 7 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 change_git_repo.patch create mode 100644 package2.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c9e9e6..cc61c7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,24 @@ cmake_minimum_required(VERSION "3.12") project("spackexample" VERSION 0.3.0) -find_package(Boost - 1.65.1 - REQUIRED - filesystem - ) +option(WITH_BOOST "Include optional functionality and boost dependency" ON) +option(WITH_YAML "Build with included YAML-parsing" ON) + +if (WITH_BOOST) + find_package(Boost + 1.65.1 + REQUIRED + filesystem + ) +endif() + +if (WITH_YAML) + find_package(yaml-cpp + 0.7.0 + REQUIRED + ) +endif() -find_package(yaml-cpp - 0.7.0 - REQUIRED - ) add_library(spackexamplelib filesystem/filesystem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp) @@ -22,11 +30,20 @@ set_target_properties(spackexamplelib PUBLIC_HEADER yamlParser/yamlParser.hpp ) -include_directories(${YAML_CPP_INCLUDE_DIR}) +if (WITH_YAML) + include_directories(${YAML_CPP_INCLUDE_DIR}) +endif() add_executable(spackexample main.cpp) target_link_libraries(spackexample spackexamplelib) -target_link_libraries(spackexamplelib Boost::filesystem yaml-cpp) +if (WITH_YAML) + target_link_libraries(spackexamplelib yaml-cpp) + target_compile_definitions(spackexamplelib PRIVATE WITH_YAML) +endif() +if (WITH_BOOST) + target_link_libraries(spackexamplelib Boost::filesystem) + target_compile_definitions(spackexamplelib PRIVATE WITH_BOOST) +endif() target_include_directories(spackexamplelib PRIVATE diff --git a/change_git_repo.patch b/change_git_repo.patch new file mode 100644 index 0000000..908f903 --- /dev/null +++ b/change_git_repo.patch @@ -0,0 +1,8 @@ +14c14 +< git = "https://github.com/Simulation-Software-Engineering/spack-exercise.git" +--- +> git = "https://github.com/menkalian/spack-exercise.git" +20c20 +< version("main", branch="main") +--- +> version("main", branch="exercise-spack-krampfkn") diff --git a/filesystem/filesystem.cpp b/filesystem/filesystem.cpp index 4428da4..afe7ac1 100644 --- a/filesystem/filesystem.cpp +++ b/filesystem/filesystem.cpp @@ -2,6 +2,8 @@ #include #include #include + +#if WITH_BOOST #include using namespace boost::filesystem; @@ -44,3 +46,11 @@ void inspectDirectory() } } + +#else + +void inspectDirectory() { + std::cout << "Filesystem operations are not available without Boost. Build package with '+boost' to enable functionality" << std::endl; +} + +#endif diff --git a/flatset/flatset.cpp b/flatset/flatset.cpp index 9b5279f..abbae98 100644 --- a/flatset/flatset.cpp +++ b/flatset/flatset.cpp @@ -1,5 +1,7 @@ #include "flatset.hpp" #include + +#ifdef WITH_BOOST #include void modifyAndPrintSets() { @@ -20,3 +22,10 @@ void modifyAndPrintSets() { std::cout< +#ifdef WITH_YAML + +#include "yaml-cpp/yaml.h" void parseConfig(const std::string yamlFile){ YAML::Node config = YAML::LoadFile(yamlFile); std::cout << "Version: " << config["version"].as() << std::endl; } + +#else + +void parseConfig(const std::string yamlFile) { + std::cout << "Yaml-Parser was disabled at build time. Build package with '+yaml' to enable functionality" << std::endl; +} + +#endif