From 6c30f41443629ddc647875887768d1af17815409 Mon Sep 17 00:00:00 2001 From: Attila Mark Date: Fri, 24 Jan 2020 19:39:01 -0800 Subject: [PATCH 1/5] Configure fmt.pc library name correctly. Simplify getting library name. Add FMT_DEBUG_SUFFIX variable. --- CMakeLists.txt | 10 +++++++++- support/cmake/fmt.pc.in | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b4ec0a7..a645ef32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,9 +174,17 @@ target_include_directories(fmt PUBLIC $ $) +set(FMT_DEBUG_POSTFIX d) + set_target_properties(fmt PROPERTIES VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR} - DEBUG_POSTFIX d) + DEBUG_POSTFIX ${FMT_DEBUG_POSTFIX}) + +# Set FMT_LIB_NAME for pkg-config fmt.pc. +get_target_property(FMT_LIB_NAME fmt OUTPUT_NAME) +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(FMT_LIB_NAME ${FMT_LIB_NAME}${FMT_DEBUG_POSTFIX}) +endif () if (BUILD_SHARED_LIBS) if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") diff --git a/support/cmake/fmt.pc.in b/support/cmake/fmt.pc.in index e935dc78..4e030afd 100644 --- a/support/cmake/fmt.pc.in +++ b/support/cmake/fmt.pc.in @@ -6,6 +6,6 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: fmt Description: A modern formatting library Version: @FMT_VERSION@ -Libs: -L${libdir} -lfmt +Libs: -L${libdir} -l@FMT_LIB_NAME@ Cflags: -I${includedir} From f499b393d1a196f0a7d86371b37d911b35a2759a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 25 Jan 2020 17:02:22 -0800 Subject: [PATCH 2/5] Apply coding conventions --- include/fmt/chrono.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 80cbe697..421d464a 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -495,12 +495,12 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin, handler.on_text(ptr - 1, ptr); break; case 'n': { - const Char newline[]{'\n', 0}; + const Char newline[] = {'\n'}; handler.on_text(newline, newline + 1); break; } case 't': { - const Char tab[]{'\t', 0}; + const Char tab[] = {'\t'}; handler.on_text(tab, tab + 1); break; } @@ -761,10 +761,10 @@ inline std::chrono::duration get_milliseconds( template OutputIt format_duration_value(OutputIt out, Rep val, int precision) { - const Char pr_f[]{'{', ':', '.', '{', '}', 'f', '}', 0}; + const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0}; if (precision >= 0) return format_to(out, pr_f, val, precision); - const Char fp_f[]{'{', ':', 'g', '}', 0}; - const Char format[]{'{', '}', 0}; + const Char fp_f[] = {'{', ':', 'g', '}', 0}; + const Char format[] = {'{', '}', 0}; return format_to(out, std::is_floating_point::value ? fp_f : format, val); } @@ -779,9 +779,9 @@ OutputIt format_duration_unit(OutputIt out) { } return std::copy(s.begin(), s.end(), out); } - const Char num_f[]{'[', '{', '}', ']', 's', 0}; + const Char num_f[] = {'[', '{', '}', ']', 's', 0}; if (Period::den == 1) return format_to(out, num_f, Period::num); - const Char num_def_f[]{'[', '{', '}', '/', '{', '}', ']', 's', 0}; + const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0}; return format_to(out, num_def_f, Period::num, Period::den); } From 314e15001f1d2f6b23c3ca21c4dcf676ce842d97 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 30 Jan 2020 15:26:18 +0100 Subject: [PATCH 3/5] Fix symbol visibility on Linux when compiling with -fvisibility=hidden (#1535) Make FMT_API symbols use the default visibility on non-Windows platforms. Otherwise, one cannot use the generated fmt library when compiling globally with -fvisibility=hidden. Fixes compile errors like: ``` ../3rdParty/fmt/include/fmt/core.h:757: error: undefined reference to 'fmt::v6::internal::assert_fail(char const*, int, char const*)' ``` Note that the symbol exists, but is local: ``` $ nm -C libfmtd.so.6.1.3 | grep assert_fail U __assert_fail 0000000000233ffa t fmt::v6::internal::assert_fail(char const*, int, char const*) ``` With this patch, the compile error is gone and the symbol is properly exported: ``` $ nm -a bin/libfmtd.so -C | grep assert_fail U __assert_fail 00000000002366ba T fmt::v6::internal::assert_fail(char const*, int, char const*) ``` Change-Id: I96054e622d9a2ae81907e1b01a1033e629767a91 --- include/fmt/core.h | 11 ++++++++++- src/format.cc | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 5aefcc14..32bc88e3 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -185,11 +185,20 @@ # define FMT_CLASS_API #endif #ifndef FMT_API -# define FMT_API +# if FMT_GCC_VERSION || FMT_CLANG_VERSION +# define FMT_API __attribute__((visibility("default"))) +# define FMT_EXTERN_TEMPLATE_API FMT_API +# define FMT_INSTANTIATION_DEF_API +# else +# define FMT_API +# endif #endif #ifndef FMT_EXTERN_TEMPLATE_API # define FMT_EXTERN_TEMPLATE_API #endif +#ifndef FMT_INSTANTIATION_DEF_API +# define FMT_INSTANTIATION_DEF_API FMT_API +#endif #ifndef FMT_HEADER_ONLY # define FMT_EXTERN extern diff --git a/src/format.cc b/src/format.cc index e6fde7c3..9a9abf8d 100644 --- a/src/format.cc +++ b/src/format.cc @@ -121,7 +121,7 @@ template FMT_API char* internal::sprintf_format(long double, internal::buffer&, sprintf_specs); -template struct FMT_API internal::basic_data; +template struct FMT_INSTANTIATION_DEF_API internal::basic_data; // Workaround a bug in MSVC2013 that prevents instantiation of format_float. int (*instantiate_format_float)(double, int, internal::float_specs, From 4098970db23b283ab99826fc080429152f5be535 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 31 Jan 2020 11:33:51 -0800 Subject: [PATCH 4/5] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 34427826..af9f9252 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,7 @@ Features * Safe `printf implementation `_ including the POSIX extension for positional arguments. -* Implementation of `C++20 std::format `__. +* Implementation of `C++20 std::format `__. * Support for user-defined types. * High performance: faster than common standard library implementations of `printf `_ and From b55ea587053a01e242c8a83d84fa81e0acf7d973 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 1 Feb 2020 08:38:00 -0800 Subject: [PATCH 5/5] string_view::char_type -> value_type (#1539) --- include/fmt/core.h | 5 +++-- test/core-test.cc | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 32bc88e3..6824c125 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -313,7 +313,8 @@ template class basic_string_view { size_t size_; public: - using char_type = Char; + using char_type FMT_DEPRECATED_ALIAS = Char; + using value_type = Char; using iterator = const Char*; FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} @@ -471,7 +472,7 @@ struct is_string : std::is_class()))> { template struct char_t_impl {}; template struct char_t_impl::value>> { using result = decltype(to_string_view(std::declval())); - using type = typename result::char_type; + using type = typename result::value_type; }; struct error_handler { diff --git a/test/core-test.cc b/test/core-test.cc index 08f27024..8f233ece 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -402,8 +402,12 @@ TEST(ArgTest, VisitInvalidArg) { fmt::visit_format_arg(visitor, arg); } +TEST(StringViewTest, ValueType) { + static_assert(std::is_same::value, ""); +} + TEST(StringViewTest, Length) { - // Test that StringRef::size() returns string length, not buffer size. + // Test that string_view::size() returns string length, not buffer size. char str[100] = "some string"; EXPECT_EQ(std::strlen(str), string_view(str).size()); EXPECT_LT(std::strlen(str), sizeof(str));