Skip to content

[chenla] Spack exercise #7

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 5 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
57 changes: 57 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
107 changes: 75 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/spackexamplelib>
)
if(SOURCES)
target_include_directories(spackexamplelib
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/spackexamplelib>
)
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()
15 changes: 12 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
#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 <iostream>

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;

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] );
std::cout << "Parse some yaml file with yaml-cpp" << std::endl;
std::cout << " " << yamlFile << std::endl;
parseConfig( yamlFile );
}
#endif

return 0;
}
Expand Down
59 changes: 59 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
@@ -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