Skip to content
Snippets Groups Projects
Commit 955974d2 authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'feature/use-std-format' into 'master'

Use std::format instead of fmt, if availalbe

See merge request !3420
parents 90008198 d4c3004b
No related branches found
No related tags found
1 merge request!3420Use std::format instead of fmt, if availalbe
Pipeline #27800 passed
+4
...@@ -23,7 +23,11 @@ include(DuneMacros) ...@@ -23,7 +23,11 @@ include(DuneMacros)
# start a dune project with information from dune.module # start a dune project with information from dune.module
dune_project() dune_project()
dune_enable_all_packages(MODULE_LIBRARIES dumux_fmt dumux_parameters) if (DUMUX_HAVE_STD_FORMAT)
dune_enable_all_packages(MODULE_LIBRARIES dumux_parameters)
else()
dune_enable_all_packages(MODULE_LIBRARIES dumux_fmt dumux_parameters)
endif()
# enforce C++-17 # enforce C++-17
dune_require_cxx_standard(MODULE "DuMuX" VERSION 17) dune_require_cxx_standard(MODULE "DuMuX" VERSION 17)
......
...@@ -17,6 +17,13 @@ find_package(PVPython QUIET) ...@@ -17,6 +17,13 @@ find_package(PVPython QUIET)
find_package(Kokkos QUIET) find_package(Kokkos QUIET)
include(AddKokkosFlags) include(AddKokkosFlags)
# test if compiler supports std::format
check_cxx_symbol_exists(
"__cpp_lib_format"
"format"
DUMUX_HAVE_STD_FORMAT
)
# possibly link against TBB # possibly link against TBB
# even if an older version is found # even if an older version is found
# otherwise we get linker errors # otherwise we get linker errors
......
...@@ -170,9 +170,11 @@ public: ...@@ -170,9 +170,11 @@ public:
break; break;
case 12: case 12:
if (firstCall) if (firstCall)
std::cout << Fmt::format(" ┌{0:─^{2}}┐\n" {
" │{1: ^{2}}│\n" std::cout << " ┌──────────────────┐" << std::endl;
" └{0:─^{2}}┘\n", "", Fmt::format("DuMuX {} \u2661", DUMUX_VERSION), 20); std::cout << Fmt::format(" │{:^20}│", Fmt::format("DuMuX {} \u2661", DUMUX_VERSION)) << std::endl;
std::cout << " └──────────────────┘" << std::endl;
}
else else
std::cout << "\n" << std::endl; std::cout << "\n" << std::endl;
break; break;
......
...@@ -30,12 +30,27 @@ ...@@ -30,12 +30,27 @@
#ifndef DUMUX_IO_FORMAT_HH #ifndef DUMUX_IO_FORMAT_HH
#define DUMUX_IO_FORMAT_HH #define DUMUX_IO_FORMAT_HH
#if __has_include(<format>) // cppcheck-suppress preprocessorErrorDirective
#include <format>
#endif
#include <dumux/io/format/fmt/format.h> #include <dumux/io/format/fmt/format.h>
#include <dumux/io/format/fmt/ranges.h> #include <dumux/io/format/fmt/ranges.h>
//! Formatting tools in the style of std::format (C++20) //! Formatting tools in the style of std::format (C++20)
namespace Dumux::Fmt { namespace Dumux::Fmt {
#if __cpp_lib_format
// use std::format from C++20
using std::format;
using std::format_to;
using std::format_to_n;
using std::formatted_size;
using std::vformat;
using std::vformat_to;
using std::make_format_args;
#else
// use fallback fmt library
using Dumux::Detail::fmt::format; using Dumux::Detail::fmt::format;
using Dumux::Detail::fmt::format_to; using Dumux::Detail::fmt::format_to;
using Dumux::Detail::fmt::format_to_n; using Dumux::Detail::fmt::format_to_n;
...@@ -43,6 +58,7 @@ using Dumux::Detail::fmt::formatted_size; ...@@ -43,6 +58,7 @@ using Dumux::Detail::fmt::formatted_size;
using Dumux::Detail::fmt::vformat; using Dumux::Detail::fmt::vformat;
using Dumux::Detail::fmt::vformat_to; using Dumux::Detail::fmt::vformat_to;
using Dumux::Detail::fmt::make_format_args; using Dumux::Detail::fmt::make_format_args;
#endif
} // end namespace Dumux::Fmt } // end namespace Dumux::Fmt
......
dune_library_add_sources(dumux_fmt SOURCES format.cc) if (NOT DUMUX_HAVE_STD_FORMAT)
dune_library_add_sources(dumux_fmt SOURCES format.cc)
file(GLOB FMT_HEADERS *.h) file(GLOB FMT_HEADERS *.h)
install(FILES ${FMT_HEADERS} install(FILES ${FMT_HEADERS} format.cc
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/io/format/fmt) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/io/format/fmt)
endif()
...@@ -225,10 +225,10 @@ void runTests() ...@@ -225,10 +225,10 @@ void runTests()
const auto& expectedCenter = firstTriangle.center(); const auto& expectedCenter = firstTriangle.center();
const auto expectedRadius = (firstTriangle.corner(0) - expectedCenter).two_norm(); const auto expectedRadius = (firstTriangle.corner(0) - expectedCenter).two_norm();
if ((sphere.center() - expectedCenter).two_norm() > 1e-12*expectedRadius) if ((sphere.center() - expectedCenter).two_norm() > 1e-12*expectedRadius)
DUNE_THROW(Dune::InvalidStateException, Fmt::format( DUNE_THROW(Dune::InvalidStateException,
"Wrong circumsphere center. Expected {}, got {}.", "Wrong circumsphere center. Expected "
expectedCenter, sphere.center() << expectedCenter << " got " << sphere.center()
)); );
if (Dune::FloatCmp::ne(sphere.radius(), expectedRadius)) if (Dune::FloatCmp::ne(sphere.radius(), expectedRadius))
DUNE_THROW(Dune::InvalidStateException, Fmt::format( DUNE_THROW(Dune::InvalidStateException, Fmt::format(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment