Skip to content

[kieslijn] Spack exercise #15

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 11 commits into
base: main
Choose a base branch
from
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ cmake_minimum_required(VERSION "3.12")

project("spackexample" VERSION 0.3.0)

option(USE_BOOST "Enable Boost support" ON)
option(USE_YAML_CPP "Enable YAML-CPP support" ON)

if(USE_BOOST)
find_package(Boost
1.65.1
REQUIRED
filesystem
)
endif()

if(USE_YAML_CPP)
find_package(yaml-cpp
0.7.0
REQUIRED
)
endif()

add_library(spackexamplelib filesystem/filesystem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp)

Expand All @@ -26,7 +33,14 @@ include_directories(${YAML_CPP_INCLUDE_DIR})

add_executable(spackexample main.cpp)
target_link_libraries(spackexample spackexamplelib)
target_link_libraries(spackexamplelib Boost::filesystem yaml-cpp)

if(USE_YAML_CPP)
target_link_libraries(spackexamplelib yaml-cpp)
endif()

if(USE_BOOST)
target_link_libraries(spackexamplelib Boost::filesystem)
endif()

target_include_directories(spackexamplelib
PRIVATE
Expand Down
13 changes: 12 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
#include <iostream>

// Conditionally include Boost and YAML-CPP based on CMake options
#ifdef USE_BOOST
#include "flatset/flatset.hpp"
#include "filesystem/filesystem.hpp"
#endif

#ifdef USE_YAML_CPP
#include "yamlParser/yamlParser.hpp"
#include <iostream>
#endif

int main(int argc, char *argv[])
{
std::cout << "Let's fight with CMake, Docker, and some dependencies!" << std::endl << std::endl;

#ifdef USE_BOOST
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;
#endif

#ifdef USE_YAML_CPP
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 );
}
#endif

return 0;
}
Expand Down
41 changes: 41 additions & 0 deletions package-pip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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 py-diffusion2d
#
# You can edit this file again by typing:
#
# spack edit py-diffusion2d
#
# See the Spack documentation for more information on packaging.
# ----------------------------------------------------------------------------

from spack.package import *


class PyDiffusion2d(PythonPackage):
"""This package solves the diffusion equation in 2D over a square domain which is at a certain temperature"""

homepage = "https://simulation-software-engineering.github.io/homepage/"

url = "https://github.com/legendofa/diffusion2D/archive/refs/tags/v0.0.7.tar.gz"

maintainers("legendofa")

license("CC-BY-4.0", checked_by="legendofa")

version("0.0.7", sha256="ec6cf0f809caf592342e228b81b32465679ccd1ea040b2653d89c4630786082e")

depends_on("python@3.6:", type=("build", "run"))
depends_on("py-setuptools", type="build")
depends_on("py-versioneer", type="build")
62 changes: 62 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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):
"""This is the example spack packaging exercise of the SSE course."""

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/legendofa/spack-exercise"
maintainers("legendofa")

license("MIT", checked_by="legendofa")

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="Enable Boost support")
variant("yaml-cpp", default=True, description="Enable YAML-CPP support")

depends_on("cxx", type="build")
depends_on("yaml-cpp@0.7:", when="@0.3.0,main+yaml-cpp")
depends_on("boost@1.65.1:", when="@0.2.0:0.3.0,main+boost")

def cmake_args(self):
args = super(SpackExercise, self).cmake_args()

# Add CMake options based on Spack variants
if "+boost" in self.spec:
args.append("-DUSE_BOOST=ON")
else:
args.append("-DUSE_BOOST=OFF")

if "+yaml-cpp" in self.spec:
args.append("-DUSE_YAML_CPP=ON")
else:
args.append("-DUSE_YAML_CPP=OFF")

return args