Skip to content

[krampfkn] Spack exercise #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
39 changes: 28 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions change_git_repo.patch
Original file line number Diff line number Diff line change
@@ -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")
10 changes: 10 additions & 0 deletions filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <iostream>
#include <vector>
#include <algorithm>

#if WITH_BOOST
#include <boost/filesystem.hpp>
using namespace boost::filesystem;

Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions flatset/flatset.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "flatset.hpp"
#include <iostream>

#ifdef WITH_BOOST
#include <boost/container/flat_set.hpp>

void modifyAndPrintSets() {
Expand All @@ -20,3 +22,10 @@ void modifyAndPrintSets() {
std::cout<<std::endl;
}

#else

void modifyAndPrintSets() {
std::cout << "Flattening a set is not available without Boost. Build package with '+boost' to enable functionality" << std::endl;
}

#endif
39 changes: 39 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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)

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"
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")

variant("boost", default=True, description="Build with optional features and boost dependency")
variant("yaml", default=True, description="Build with integrated yaml-parser")

depends_on("cxx", type="build")

depends_on("boost", when="@0.2.0: +boost")
depends_on("yaml-cpp", when="@0.3.0: +yaml")

class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
def cmake_args(self):
return [
self.define_from_variant("WITH_BOOST", "boost"),
self.define_from_variant("WITH_YAML", "yaml")
]

39 changes: 39 additions & 0 deletions package2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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)

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"
git = "https://github.com/menkalian/spack-exercise.git"

maintainers("menkalian")

license("MIT License", checked_by="menkalian")

version("main", branch="exercise-spack-krampfkn")
version("0.3.0", sha256="e54a4c037941d85a22fb3e6e73195df8448cf69a96aa44ef374ac518344812f0")
version("0.2.0", sha256="3dd6b4cc0f7aff179d8e290bc3879056237ae372738a4bd7222f6450fbcdfc77")
version("0.1.0", sha256="cac78e641cb703e3fe51956f91fe8347ac52f74ef037d8eadae5777c65a19a00")

variant("boost", default=True, description="Build with optional features and boost dependency")
variant("yaml", default=True, description="Build with integrated yaml-parser")

depends_on("cxx", type="build")

depends_on("boost", when="@0.2.0: +boost")
depends_on("yaml-cpp", when="@0.3.0: +yaml")

class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
def cmake_args(self):
return [
self.define_from_variant("WITH_BOOST", "boost"),
self.define_from_variant("WITH_YAML", "yaml")
]

13 changes: 12 additions & 1 deletion yamlParser/yamlParser.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#include "yamlParser.hpp"
#include "yaml-cpp/yaml.h"

#include <iostream>

#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::string>() << 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