Skip to content

Commit

Permalink
Merge pull request #4988 from franzpoeschel/toml11-4.0
Browse files Browse the repository at this point in the history
Support for toml11 library version 4.0 (adapt to breaking changes)
  • Loading branch information
ikbuibui authored Jul 11, 2024
2 parents bab708a + 45fa9ee commit 5f1bbb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
7 changes: 6 additions & 1 deletion include/picongpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ if(PIC_SEARCH_openPMD)
# explicitly.
EXCLUDE_FROM_ALL)
else()
find_package(toml11 3.7.0 CONFIG REQUIRED)
# Since toml11 4.0 was a breaking change,
# it needs separate find_package() calls
find_package(toml11 3.7.0 CONFIG QUIET)
if(NOT toml11_FOUND)
find_package(toml11 4.0 CONFIG REQUIRED)
endif()
message(STATUS "toml11: Found version '${toml11_VERSION}'")
endif()
list(PREPEND HOST_LIBS openPMD::openPMD)
Expand Down
42 changes: 24 additions & 18 deletions include/picongpu/plugins/openPMD/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,36 @@ namespace
// 1. option: dataSources is an array:
for(auto& value : *dataSourcesInToml.as_ok())
{
auto dataSource
= toml::expect<std::string>(value)
.or_else(
[](auto const&) -> toml::success<std::string>
{
throw std::runtime_error("[openPMD plugin] Data sources in TOML "
"file must be a string or a vector of strings.");
})
.value;
auto dataSource = [&]()
{
try
{
return toml::get<std::string>(value);
}
catch(toml::type_error const&)
{
throw std::runtime_error("[openPMD plugin] Data sources in TOML "
"file must be a string or a vector of strings.");
}
}();
dataSources.push_back(std::move(dataSource));
}
}
else
{
// 2. option: dataSources is no array, check if it is a simple string
auto dataSource
= toml::expect<std::string>(pair.second)
.or_else(
[](auto const&) -> toml::success<std::string>
{
throw std::runtime_error("[openPMD plugin] Data sources in TOML "
"file must be a string or a vector of strings.");
})
.value;
auto dataSource = [&]()
{
try
{
return toml::get<std::string>(pair.second);
}
catch(toml::type_error const&)
{
throw std::runtime_error("[openPMD plugin] Data sources in TOML "
"file must be a string or a vector of strings.");
}
}();
dataSources.push_back(std::move(dataSource));
}

Expand Down

0 comments on commit 5f1bbb3

Please sign in to comment.