diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c9e9e6..f4a4918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/main.cpp b/main.cpp index 8eda2d3..6e74509 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,20 @@ +#include + +// 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 +#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; @@ -14,7 +22,9 @@ int main(int argc, char *argv[]) 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] ); @@ -22,6 +32,7 @@ int main(int argc, char *argv[]) std::cout << " " << yamlFile << std::endl; parseConfig( yamlFile ); } + #endif return 0; } diff --git a/package-pip.py b/package-pip.py new file mode 100644 index 0000000..3a5b1ba --- /dev/null +++ b/package-pip.py @@ -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") diff --git a/package.py b/package.py new file mode 100644 index 0000000..4908215 --- /dev/null +++ b/package.py @@ -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