Skip to content

Commit

Permalink
#2216: Use macro for using correct fmt headers
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala authored and cwschilly committed Sep 20, 2024
1 parent d429bdd commit 1f7a6dc
Show file tree
Hide file tree
Showing 41 changed files with 212 additions and 107 deletions.
2 changes: 2 additions & 0 deletions cmake/configure_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ define_option(vt_build_examples "examples" "Build VT examples" ON empty_feature)
option(vt_external_fmt "Build VT with external fmt" OFF)
if(${vt_external_fmt})
message(STATUS "Building vt with external fmt library")
set(vt_feature_cmake_external_fmt "1")
else()
message(STATUS "Building vt with included fmt library")
set(vt_feature_cmake_external_fmt "0")
endif()

list(POP_BACK CMAKE_MESSAGE_INDENT)
Expand Down
14 changes: 11 additions & 3 deletions cmake/link_vt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,17 @@ function(link_target_with_vt)
if (${ARG_DEBUG_LINK})
message(STATUS "link_target_with_vt: fmt=${ARG_LINK_FMT}")
endif()
target_link_libraries(
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${FMT_LIBRARY}
)

if(${vt_external_fmt})
target_link_libraries(
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} fmt::fmt
)
else()
target_link_libraries(
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${FMT_LIBRARY}
)
endif()

endif()

if (NOT DEFINED ARG_LINK_ENG_FORMAT AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_ENG_FORMAT)
Expand Down
5 changes: 3 additions & 2 deletions cmake/load_bundled_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ add_subdirectory(${PROJECT_LIB_DIR}/CLI)
# use included fmt or external one
if(${vt_external_fmt})
# user should provide 'fmt_DIR' to CMake (unless fmt is installed in system libs)
if(${fmt_DIR})
if(fmt_DIR)
message(STATUS "vt_external_fmt = ON. Using fmt located at ${fmt_DIR}")
else()
message(STATUS "vt_external_fmt = ON but ${fmt_DIR} is not provided.")
message(STATUS "vt_external_fmt = ON but fmt_DIR is not provided!")
endif()
find_package(fmt REQUIRED)
# set(FMT_LIBRARY fmt::fmt)
else()
set(FMT_LIBRARY fmt)
add_subdirectory(${PROJECT_LIB_DIR}/fmt)
Expand Down
14 changes: 13 additions & 1 deletion cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#define vt_feature_cmake_production_build @vt_feature_cmake_production_build@
#define vt_feature_cmake_debug_verbose @vt_feature_cmake_debug_verbose@
#define vt_feature_cmake_rdma_tests @vt_feature_cmake_rdma_tests@

#define vt_feature_cmake_external_fmt @vt_feature_cmake_external_fmt@

#define vt_detected_max_num_nodes @cmake_detected_max_num_nodes@

Expand All @@ -91,3 +91,15 @@
#cmakedefine vt_has_sysconf
#cmakedefine vt_has_libunwind_h
#cmakedefine vt_has_execinfo_h

#if vt_feature_cmake_external_fmt
#define INCLUDE_FMT_CORE <fmt/core.h>
#define INCLUDE_FMT_FORMAT <fmt/format.h>
#define INCLUDE_FMT_RANGES <fmt/ranges.h>
#define INCLUDE_FMT_OSTREAM <fmt/ostream.h>
#else
#define INCLUDE_FMT_CORE <fmt-vt/core.h>
#define INCLUDE_FMT_FORMAT <fmt-vt/format.h>
#define INCLUDE_FMT_RANGES <fmt-vt/ranges.h>
#define INCLUDE_FMT_OSTREAM <fmt-vt/ostream.h>
#endif
4 changes: 3 additions & 1 deletion lib/fmt/include/fmt-vt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@
#ifndef FMT_BEGIN_NAMESPACE
# define FMT_BEGIN_NAMESPACE \
namespace fmt { \
inline namespace v10 {
inline namespace v10 { \
inline namespace vt {
# define FMT_END_NAMESPACE \
} \
} \
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/debug/debug_fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

#include "vt/config.h"

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

#include <iosfwd>

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/debug/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "vt/configs/debug/debug_colorize.h"
#include "vt/configs/debug/debug_var_unused.h"

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

/*
=== Debug file/line/func functionality ===
Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/assert_out.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <string>
#include <cassert>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace debug { namespace assert {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/assert_out_info.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#include <string>
#include <sstream>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace debug { namespace assert {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/error.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include <tuple>
#include <type_traits>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace error {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/keyval_printer.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <string>
#include <vector>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace util { namespace error {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/pretty_print_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <string>
#include <unistd.h> // gethostname

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace debug {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/error/soft_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#include <string>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt {

Expand Down
1 change: 1 addition & 0 deletions src/vt/configs/features/features_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#define vt_feature_libfort 0 || vt_feature_cmake_libfort
#define vt_feature_production_build 0 || vt_feature_cmake_production_build
#define vt_feature_debug_verbose 0 || vt_feature_cmake_debug_verbose
#define vt_feature_fmt_external 0 || vt_feature_cmake_external_fmt

#define vt_check_enabled(test_option) (vt_feature_ ## test_option != 0)

Expand Down
3 changes: 2 additions & 1 deletion src/vt/elm/elm_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ struct hash<vt::elm::ElementIDStruct> {

} /* end namespace std */

#include <fmt-vt/format.h>
#include "vt/cmake_config.h"
#include INCLUDE_FMT_FORMAT

namespace fmt {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/epoch/epoch_manip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "vt/utils/bits/bits_packer.h"
#include "vt/termination/term_common.h"

#include <fmt-vt/ostream.h>
#include INCLUDE_FMT_OSTREAM

namespace vt { namespace epoch {

Expand Down
3 changes: 2 additions & 1 deletion src/vt/epoch/epoch_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ struct hash<vt::epoch::EpochType> {

} /* end namespace std */

#include <fmt-vt/format.h>
#include "vt/cmake_config.h"
#include INCLUDE_FMT_FORMAT

namespace fmt {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/epoch/epoch_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "vt/epoch/epoch_window.h"
#include "vt/epoch/epoch_manip.h"

#include <fmt-vt/ostream.h>
#include INCLUDE_FMT_OSTREAM

namespace vt { namespace epoch {

Expand Down
24 changes: 17 additions & 7 deletions src/vt/rdma/rdma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,30 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);

}} //end namespace vt::rdma

template<>
struct fmt::formatter<vt::rdma::Type> : fmt::formatter<std::string_view> {
namespace fmt { inline namespace vt {
template <>
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
template <typename FormatContext>
auto format(vt::rdma::Type t, FormatContext& ctx) {
auto format(::vt::rdma::Type t, FormatContext& ctx) {
std::string_view name = "Unknown";
switch (t) {
case vt::rdma::Type::Get: name = "Get"; break;
case vt::rdma::Type::Put: name = "Put"; break;
case vt::rdma::Type::GetOrPut: name = "GetOrPut"; break;
case vt::rdma::Type::Uninitialized: name = "Uninitialized"; break;
case ::vt::rdma::Type::Get:
name = "Get";
break;
case ::vt::rdma::Type::Put:
name = "Put";
break;
case ::vt::rdma::Type::GetOrPut:
name = "GetOrPut";
break;
case ::vt::rdma::Type::Uninitialized:
name = "Uninitialized";
break;
}
return formatter<std::string_view>::format(name, ctx);
}
};
}} // namespace fmt::vt

#define PRINT_CHANNEL_TYPE(rdma_op_type) ( \
rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \
Expand Down
2 changes: 1 addition & 1 deletion src/vt/runtime/component/diagnostic_value_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "vt/runtime/component/diagnostic_enum_format.h"
#include "vt/utils/memory/memory_units.h"

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace runtime { namespace component { namespace detail {

Expand Down
2 changes: 1 addition & 1 deletion src/vt/runtime/runtime_diagnostics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <fort.hpp>
#endif /*vt_check_enabled(libfort)*/

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

#include <map>
#include <string>
Expand Down
26 changes: 12 additions & 14 deletions src/vt/termination/interval/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

#include <ostream>

#include <fmt-vt/ostream.h>
#include INCLUDE_FMT_OSTREAM

namespace vt { namespace term { namespace interval {

Expand Down Expand Up @@ -230,27 +230,25 @@ using Interval = term::interval::Interval<DomainT>;

} /* end namespace vt */

#include <fmt-vt/core.h>
#include <fmt-vt/format.h>

namespace vt { namespace term { namespace interval {

template <typename DomainT, DomainT sentinel>
struct Interval;

}}}

namespace fmt { inline namespace vt {
template <typename DomainT, DomainT sentinel>
struct fmt::formatter<vt::term::interval::Interval<DomainT, sentinel>> : fmt::formatter<std::string> {
template <typename FormatContext>
auto format(const vt::term::interval::Interval<DomainT, sentinel>& interval, FormatContext& ctx) {
return format_to(
ctx.out(),
"Interval[{}, {}]",
interval.lower(),
interval.upper()
);
}
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
: formatter<std::string> {
template <typename FormatContext>
auto format(
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
FormatContext& ctx) {
return format_to(
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
}
};
}} // namespace fmt::vt

#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/
14 changes: 7 additions & 7 deletions src/vt/timing/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#include <string>

#include <EngFormat-Cpp/eng_format.hpp>
#include <fmt-vt/core.h>
#include "vt/cmake_config.h"
#include INCLUDE_FMT_CORE

#include "vt/timing/timing_type.h"

Expand All @@ -62,16 +63,15 @@ TimeType getCurrentTime();

}} /* end namespace vt::timing */

namespace fmt {

template<>
namespace fmt { inline namespace vt {
template <>
struct formatter<::vt::TimeTypeWrapper> {
template<typename ParseContext>
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
return ctx.begin();
}

template<typename FormatContext>
template <typename FormatContext>
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
return fmt::format_to(
ctx.out(), "{}",
Expand All @@ -80,6 +80,6 @@ struct formatter<::vt::TimeTypeWrapper> {
}
};

} /* end namespace fmt */
}} // namespace fmt::vt

#endif /*INCLUDED_VT_TIMING_TIMING_H*/
16 changes: 11 additions & 5 deletions src/vt/topos/index/dense/dense_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "vt/utils/bits/bits_packer.h"
#include "vt/utils/static_checks/meta_type_eq_.h"
#include "vt/serialization/traits/byte_copy_trait.h"
#include INCLUDE_FMT_RANGES

#include <array>
#include <type_traits>
Expand Down Expand Up @@ -146,6 +147,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
std::ostream& os, DenseIndexArray<IndexT,nd> const& idx
);

friend struct fmt::formatter<vt::index::DenseIndexArray<IndexType, ndim>>;
private:
std::array<IndexType, ndim> dims = {};
};
Expand All @@ -157,15 +159,19 @@ static_assert(

}} // end namespace vt::index

namespace fmt { inline namespace vt {

template <typename IndexType, vt::index::NumDimensionsType ndim>
struct fmt::formatter<vt::index::DenseIndexArray<IndexType, ndim>> : fmt::formatter<std::string> {
template <typename IndexType, ::vt::index::NumDimensionsType ndim>
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
: formatter<std::array<IndexType, ndim>> {
template <typename FormatContext>
auto format(const vt::index::DenseIndexArray<IndexType, ndim>& idx, FormatContext& ctx) {
return formatter<std::string>::format(idx.toString(), ctx);
auto format(
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
FormatContext& ctx) {
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
}
};

}} // namespace fmt::vt

#include "vt/topos/index/dense/dense_array.impl.h"

Expand Down
2 changes: 1 addition & 1 deletion src/vt/utils/adt/histogram_approx.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <cmath>
#include <algorithm>

#include <fmt-vt/core.h>
#include INCLUDE_FMT_CORE

namespace vt { namespace util { namespace adt {

Expand Down
Loading

0 comments on commit 1f7a6dc

Please sign in to comment.