Skip to content

Commit 47aa1b8

Browse files
committed
#2216: Use macro for using correct fmt headers
1 parent eca2606 commit 47aa1b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+213
-109
lines changed

cmake/configure_options.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ define_option(vt_build_examples "examples" "Build VT examples" ON empty_feature)
154154
option(vt_external_fmt "Build VT with external fmt" OFF)
155155
if(${vt_external_fmt})
156156
message(STATUS "Building vt with external fmt library")
157+
set(vt_feature_cmake_external_fmt "1")
157158
else()
158159
message(STATUS "Building vt with included fmt library")
160+
set(vt_feature_cmake_external_fmt "0")
159161
endif()
160162

161163
list(POP_BACK CMAKE_MESSAGE_INDENT)

cmake/link_vt.cmake

+11-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,17 @@ function(link_target_with_vt)
170170
if (${ARG_DEBUG_LINK})
171171
message(STATUS "link_target_with_vt: fmt=${ARG_LINK_FMT}")
172172
endif()
173-
target_link_libraries(
174-
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${FMT_LIBRARY}
175-
)
173+
174+
if(${vt_external_fmt})
175+
target_link_libraries(
176+
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} fmt::fmt
177+
)
178+
else()
179+
target_link_libraries(
180+
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${FMT_LIBRARY}
181+
)
182+
endif()
183+
176184
endif()
177185

178186
if (NOT DEFINED ARG_LINK_ENG_FORMAT AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_ENG_FORMAT)

cmake/load_bundled_libraries.cmake

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ add_subdirectory(${PROJECT_LIB_DIR}/CLI)
2323
# use included fmt or external one
2424
if(${vt_external_fmt})
2525
# user should provide 'fmt_DIR' to CMake (unless fmt is installed in system libs)
26-
if(${fmt_DIR})
26+
if(fmt_DIR)
2727
message(STATUS "vt_external_fmt = ON. Using fmt located at ${fmt_DIR}")
2828
else()
29-
message(STATUS "vt_external_fmt = ON but ${fmt_DIR} is not provided.")
29+
message(STATUS "vt_external_fmt = ON but fmt_DIR is not provided!")
3030
endif()
3131
find_package(fmt REQUIRED)
32+
# set(FMT_LIBRARY fmt::fmt)
3233
else()
3334
set(FMT_LIBRARY fmt)
3435
add_subdirectory(${PROJECT_LIB_DIR}/fmt)

cmake_config.h.in

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#define vt_feature_cmake_production_build @vt_feature_cmake_production_build@
6666
#define vt_feature_cmake_debug_verbose @vt_feature_cmake_debug_verbose@
6767
#define vt_feature_cmake_rdma_tests @vt_feature_cmake_rdma_tests@
68-
68+
#define vt_feature_cmake_external_fmt @vt_feature_cmake_external_fmt@
6969

7070
#define vt_detected_max_num_nodes @cmake_detected_max_num_nodes@
7171

@@ -91,3 +91,15 @@
9191
#cmakedefine vt_has_sysconf
9292
#cmakedefine vt_has_libunwind_h
9393
#cmakedefine vt_has_execinfo_h
94+
95+
#if vt_feature_cmake_external_fmt
96+
#define INCLUDE_FMT_CORE <fmt/core.h>
97+
#define INCLUDE_FMT_FORMAT <fmt/format.h>
98+
#define INCLUDE_FMT_RANGES <fmt/ranges.h>
99+
#define INCLUDE_FMT_OSTREAM <fmt/ostream.h>
100+
#else
101+
#define INCLUDE_FMT_CORE <fmt-vt/core.h>
102+
#define INCLUDE_FMT_FORMAT <fmt-vt/format.h>
103+
#define INCLUDE_FMT_RANGES <fmt-vt/ranges.h>
104+
#define INCLUDE_FMT_OSTREAM <fmt-vt/ostream.h>
105+
#endif

lib/fmt/include/fmt-vt/core.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@
173173
#ifndef FMT_BEGIN_NAMESPACE
174174
# define FMT_BEGIN_NAMESPACE \
175175
namespace fmt { \
176-
inline namespace v10 {
176+
inline namespace v10 { \
177+
inline namespace vt {
177178
# define FMT_END_NAMESPACE \
179+
} \
178180
} \
179181
}
180182
#endif

src/vt/configs/debug/debug_fmt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
#include "vt/config.h"
4848

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

5151
#include <iosfwd>
5252

src/vt/configs/debug/debug_print.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include "vt/configs/debug/debug_colorize.h"
5050
#include "vt/configs/debug/debug_var_unused.h"
5151

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

5454
/*
5555
=== Debug file/line/func functionality ===

src/vt/configs/error/assert_out.impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#include <string>
5757
#include <cassert>
5858

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

6161
namespace vt { namespace debug { namespace assert {
6262

src/vt/configs/error/assert_out_info.impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include <string>
5858
#include <sstream>
5959

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

6262
namespace vt { namespace debug { namespace assert {
6363

src/vt/configs/error/error.impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include <tuple>
5656
#include <type_traits>
5757

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

6060
namespace vt { namespace error {
6161

src/vt/configs/error/keyval_printer.impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#include <string>
5454
#include <vector>
5555

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

5858
namespace vt { namespace util { namespace error {
5959

src/vt/configs/error/pretty_print_message.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <string>
5151
#include <unistd.h> // gethostname
5252

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

5555
namespace vt { namespace debug {
5656

src/vt/configs/error/soft_error.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
#include <string>
6161

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

6464
namespace vt {
6565

src/vt/configs/features/features_defines.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#define vt_feature_libfort 0 || vt_feature_cmake_libfort
7373
#define vt_feature_production_build 0 || vt_feature_cmake_production_build
7474
#define vt_feature_debug_verbose 0 || vt_feature_cmake_debug_verbose
75+
#define vt_feature_fmt_external 0 || vt_feature_cmake_external_fmt
7576

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

src/vt/elm/elm_id.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ struct hash<vt::elm::ElementIDStruct> {
9494

9595
} /* end namespace std */
9696

97-
#include <fmt-vt/format.h>
97+
#include "vt/cmake_config.h"
98+
#include INCLUDE_FMT_FORMAT
9899

99100
namespace fmt {
100101

src/vt/epoch/epoch_manip.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include "vt/utils/bits/bits_packer.h"
5050
#include "vt/termination/term_common.h"
5151

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

5454
namespace vt { namespace epoch {
5555

src/vt/epoch/epoch_type.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ struct hash<vt::epoch::EpochType> {
108108

109109
} /* end namespace std */
110110

111-
#include <fmt-vt/format.h>
111+
#include "vt/cmake_config.h"
112+
#include INCLUDE_FMT_FORMAT
112113

113114
namespace fmt {
114115

src/vt/epoch/epoch_window.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "vt/epoch/epoch_window.h"
4545
#include "vt/epoch/epoch_manip.h"
4646

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

4949
namespace vt { namespace epoch {
5050

src/vt/rdma/rdma_common.h

+17-7
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,30 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);
117117

118118
}} //end namespace vt::rdma
119119

120-
template<>
121-
struct fmt::formatter<vt::rdma::Type> : fmt::formatter<std::string_view> {
120+
namespace fmt { inline namespace vt {
121+
template <>
122+
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
122123
template <typename FormatContext>
123-
auto format(vt::rdma::Type t, FormatContext& ctx) {
124+
auto format(::vt::rdma::Type t, FormatContext& ctx) {
124125
std::string_view name = "Unknown";
125126
switch (t) {
126-
case vt::rdma::Type::Get: name = "Get"; break;
127-
case vt::rdma::Type::Put: name = "Put"; break;
128-
case vt::rdma::Type::GetOrPut: name = "GetOrPut"; break;
129-
case vt::rdma::Type::Uninitialized: name = "Uninitialized"; break;
127+
case ::vt::rdma::Type::Get:
128+
name = "Get";
129+
break;
130+
case ::vt::rdma::Type::Put:
131+
name = "Put";
132+
break;
133+
case ::vt::rdma::Type::GetOrPut:
134+
name = "GetOrPut";
135+
break;
136+
case ::vt::rdma::Type::Uninitialized:
137+
name = "Uninitialized";
138+
break;
130139
}
131140
return formatter<std::string_view>::format(name, ctx);
132141
}
133142
};
143+
}} // namespace fmt::vt
134144

135145
#define PRINT_CHANNEL_TYPE(rdma_op_type) ( \
136146
rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \

src/vt/runtime/component/diagnostic_value_format.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include "vt/runtime/component/diagnostic_enum_format.h"
5050
#include "vt/utils/memory/memory_units.h"
5151

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

5454
namespace vt { namespace runtime { namespace component { namespace detail {
5555

src/vt/runtime/runtime_diagnostics.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#include <fort.hpp>
5757
#endif /*vt_check_enabled(libfort)*/
5858

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

6161
#include <map>
6262
#include <string>

src/vt/termination/interval/interval.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#include <ostream>
5050

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

5353
namespace vt { namespace term { namespace interval {
5454

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

231231
} /* end namespace vt */
232232

233-
#include <fmt-vt/core.h>
234-
#include <fmt-vt/format.h>
235-
236233
namespace vt { namespace term { namespace interval {
237234

238235
template <typename DomainT, DomainT sentinel>
239236
struct Interval;
240237

241238
}}}
242239

240+
namespace fmt { inline namespace vt {
243241
template <typename DomainT, DomainT sentinel>
244-
struct fmt::formatter<vt::term::interval::Interval<DomainT, sentinel>> : fmt::formatter<std::string> {
245-
template <typename FormatContext>
246-
auto format(const vt::term::interval::Interval<DomainT, sentinel>& interval, FormatContext& ctx) {
247-
return format_to(
248-
ctx.out(),
249-
"Interval[{}, {}]",
250-
interval.lower(),
251-
interval.upper()
252-
);
253-
}
242+
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
243+
: formatter<std::string> {
244+
template <typename FormatContext>
245+
auto format(
246+
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
247+
FormatContext& ctx) {
248+
return format_to(
249+
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
250+
}
254251
};
252+
}} // namespace fmt::vt
255253

256254
#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/

src/vt/timing/timing.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
#include <string>
4848

4949
#include <EngFormat-Cpp/eng_format.hpp>
50-
#include <fmt-vt/core.h>
50+
#include "vt/cmake_config.h"
51+
#include INCLUDE_FMT_CORE
5152

5253
#include "vt/timing/timing_type.h"
5354

@@ -62,24 +63,22 @@ TimeType getCurrentTime();
6263

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

65-
namespace fmt {
66-
67-
template<>
66+
namespace fmt { inline namespace vt {
67+
template <>
6868
struct formatter<::vt::TimeTypeWrapper> {
69-
template<typename ParseContext>
69+
template <typename ParseContext>
7070
constexpr auto parse(ParseContext& ctx) {
7171
return ctx.begin();
7272
}
7373

74-
template<typename FormatContext>
74+
template <typename FormatContext>
7575
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
7676
return fmt::format_to(
7777
ctx.out(), "{}",
78-
to_engineering_string(t.seconds(), 3, eng_exponential, "s")
79-
);
78+
to_engineering_string(t.seconds(), 3, eng_exponential, "s"));
8079
}
8180
};
8281

83-
} /* end namespace fmt */
82+
}} // namespace fmt::vt
8483

8584
#endif /*INCLUDED_VT_TIMING_TIMING_H*/

src/vt/topos/index/dense/dense_array.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "vt/utils/bits/bits_packer.h"
5050
#include "vt/utils/static_checks/meta_type_eq_.h"
5151
#include "vt/serialization/traits/byte_copy_trait.h"
52+
#include INCLUDE_FMT_RANGES
5253

5354
#include <array>
5455
#include <type_traits>
@@ -146,6 +147,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
146147
std::ostream& os, DenseIndexArray<IndexT,nd> const& idx
147148
);
148149

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

158160
}} // end namespace vt::index
159161

162+
namespace fmt { inline namespace vt {
160163

161-
template <typename IndexType, vt::index::NumDimensionsType ndim>
162-
struct fmt::formatter<vt::index::DenseIndexArray<IndexType, ndim>> : fmt::formatter<std::string> {
164+
template <typename IndexType, ::vt::index::NumDimensionsType ndim>
165+
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
166+
: formatter<std::array<IndexType, ndim>> {
163167
template <typename FormatContext>
164-
auto format(const vt::index::DenseIndexArray<IndexType, ndim>& idx, FormatContext& ctx) {
165-
return formatter<std::string>::format(idx.toString(), ctx);
168+
auto format(
169+
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
170+
FormatContext& ctx) {
171+
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
166172
}
167173
};
168-
174+
}} // namespace fmt::vt
169175

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

src/vt/utils/adt/histogram_approx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include <cmath>
5353
#include <algorithm>
5454

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

5757
namespace vt { namespace util { namespace adt {
5858

0 commit comments

Comments
 (0)