diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..060e553 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,57 @@ +{ + "files.associations": { + "iostream": "cpp", + "__bit_reference": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "atomic": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "locale": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c9e9e6..f87044e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,46 +2,89 @@ cmake_minimum_required(VERSION "3.12") project("spackexample" VERSION 0.3.0) -find_package(Boost - 1.65.1 - REQUIRED - filesystem - ) +option(ENABLE_BOOST "Enable use of boost." OFF) +option(ENABLE_YAML "Enable use of yaml-cpp." OFF) -find_package(yaml-cpp - 0.7.0 - REQUIRED - ) +set(SOURCES) -add_library(spackexamplelib filesystem/filesystem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp) +if(ENABLE_BOOST) + find_package(Boost + 1.65.1 + REQUIRED + filesystem + ) + list(APPEND SOURCES filesystem/filesystem.cpp flatset/flatset.cpp) +endif() + +if(ENABLE_YAML) + find_package(yaml-cpp + 0.7.0 + REQUIRED + ) + list(APPEND SOURCES yamlParser/yamlParser.cpp) + include_directories(${YAML_CPP_INCLUDE_DIR}) +endif() + +if(SOURCES) + add_library(spackexamplelib ${SOURCES}) + if(ENABLE_BOOST) + set_target_properties(spackexamplelib + PROPERTIES + PUBLIC_HEADER filesystem/filesystem.hpp + PUBLIC_HEADER flatset/flatset.hpp + ) + endif() + if(ENABLE_YAML) + set_target_properties(spackexamplelib + PROPERTIES + PUBLIC_HEADER yamlParser/yamlParser.hpp + ) + endif() +endif() -set_target_properties(spackexamplelib - PROPERTIES - PUBLIC_HEADER filesystem/filesystem.hpp - PUBLIC_HEADER flatset/flatset.hpp - PUBLIC_HEADER yamlParser/yamlParser.hpp - ) -include_directories(${YAML_CPP_INCLUDE_DIR}) add_executable(spackexample main.cpp) + +if(SOURCES) target_link_libraries(spackexample spackexamplelib) -target_link_libraries(spackexamplelib Boost::filesystem yaml-cpp) + if(ENABLE_BOOST) + target_link_libraries(spackexample Boost::filesystem) + target_compile_definitions(spackexample PRIVATE BOOST) + endif() + if(ENABLE_YAML) + target_link_libraries(spackexample yaml-cpp) + target_compile_definitions(spackexample PRIVATE YAML) + endif() +endif() + -target_include_directories(spackexamplelib - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib - PUBLIC - $ - $ - ) +if(SOURCES) + target_include_directories(spackexamplelib + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib + PUBLIC + $ + $ + ) +endif() # Create install targets include(GNUInstallDirs) -install(TARGETS spackexample spackexamplelib - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample - ) +if(SOURCES) + install(TARGETS spackexample spackexamplelib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample + ) +else() + install(TARGETS spackexample + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample + ) +endif() diff --git a/main.cpp b/main.cpp index 8eda2d3..79fbf7c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,18 @@ -#include "flatset/flatset.hpp" -#include "filesystem/filesystem.hpp" -#include "yamlParser/yamlParser.hpp" +#ifdef BOOST + #include "flatset/flatset.hpp" + #include "filesystem/filesystem.hpp" +#endif +#ifdef YAML + #include "yamlParser/yamlParser.hpp" +#endif #include int main(int argc, char *argv[]) { std::cout << "Let's fight with CMake, Docker, and some dependencies!" << std::endl << std::endl; + +#ifdef BOOST std::cout << "Modify a flat set using boost container" << std::endl; modifyAndPrintSets(); std::cout << std::endl; @@ -14,7 +20,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 YAML if ( argc == 2 ) { const std::string yamlFile( argv[1] ); @@ -22,6 +30,7 @@ int main(int argc, char *argv[]) std::cout << " " << yamlFile << std::endl; parseConfig( yamlFile ); } +#endif return 0; } diff --git a/package.py b/package.py new file mode 100644 index 0000000..390e1ea --- /dev/null +++ b/package.py @@ -0,0 +1,59 @@ +# 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): + """FIXME: Put a proper description of your package here.""" + + 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/lingachen/spack-exercise" + + maintainers("lingachen") + + license("MIT", checked_by="lingachen") + + version("0.3.0", sha256="e54a4c037941d85a22fb3e6e73195df8448cf69a96aa44ef374ac518344812f0") + version("0.2.0", sha256="3dd6b4cc0f7aff179d8e290bc3879056237ae372738a4bd7222f6450fbcdfc77") + version("0.1.0", sha256="cac78e641cb703e3fe51956f91fe8347ac52f74ef037d8eadae5777c65a19a00") + version("optional-dependencies", branch="optional-dependencies-dev") + + depends_on("cxx", type="build") + + variant("boost", default=False, description="Enable Boost in CMakeLists and main.cpp") + variant("boost", default=True, description="Enable Boost in CMakeLists and main.cpp", when="@0.2.0:") + depends_on("boost", when="+boost") + + variant("yaml", default=False, description="Enable yaml-cpp in CMakeLists and main.cpp") + variant("yaml", default=True, description="Enable yaml-cpp in CMakeLists and main.cpp", when="@0.3.0") + depends_on("yaml-cpp", when="+yaml") + + def cmake_args(self): + args = [ + self.define_from_variant("ENABLE_BOOST", "boost"), + self.define_from_variant("ENABLE_YAML", "yaml"), + ] + + return args +