1
0
Fork 0

Codechange: Compile fmt internals in a separate translation unit

Instead of defining FMT_HEADER_ONLY to include fmt internals
in the headers included by all fmt-using translation units.
pull/13527/head
Jonathan G Rennison 2025-02-10 21:44:08 +00:00
parent 765264f4b6
commit 15ec3340c9
6 changed files with 47 additions and 3 deletions

View File

@ -260,6 +260,7 @@ target_precompile_headers(openttd_lib
src/stdafx.h src/stdafx.h
src/core/format.hpp src/core/format.hpp
) )
set_source_files_properties(src/3rdparty/fmt/format.cc PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
add_subdirectory(${CMAKE_SOURCE_DIR}/bin) add_subdirectory(${CMAKE_SOURCE_DIR}/bin)
add_subdirectory(${CMAKE_SOURCE_DIR}/src) add_subdirectory(${CMAKE_SOURCE_DIR}/src)

View File

@ -1,6 +1,7 @@
add_files( add_files(
chrono.h chrono.h
core.h core.h
format.cc
format.h format.h
format-inl.h format-inl.h
ostream.h ostream.h

43
src/3rdparty/fmt/format.cc vendored 100644
View File

@ -0,0 +1,43 @@
// Formatting library for C++
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#include "format-inl.h"
FMT_BEGIN_NAMESPACE
namespace detail {
template FMT_API auto dragonbox::to_decimal(float x) noexcept
-> dragonbox::decimal_fp<float>;
template FMT_API auto dragonbox::to_decimal(double x) noexcept
-> dragonbox::decimal_fp<double>;
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template FMT_API locale_ref::locale_ref(const std::locale& loc);
template FMT_API auto locale_ref::get<std::locale>() const -> std::locale;
#endif
// Explicit instantiations for char.
template FMT_API auto thousands_sep_impl(locale_ref)
-> thousands_sep_result<char>;
template FMT_API auto decimal_point_impl(locale_ref) -> char;
template FMT_API void buffer<char>::append(const char*, const char*);
template FMT_API void vformat_to(buffer<char>&, string_view,
typename vformat_args<>::type, locale_ref);
// Explicit instantiations for wchar_t.
template FMT_API auto thousands_sep_impl(locale_ref)
-> thousands_sep_result<wchar_t>;
template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
template FMT_API void buffer<wchar_t>::append(const wchar_t*, const wchar_t*);
} // namespace detail
FMT_END_NAMESPACE

View File

@ -5,6 +5,7 @@ if (NOT HOST_BINARY_DIR)
set(sourcefiles set(sourcefiles
settingsgen.cpp settingsgen.cpp
../3rdparty/fmt/format.cc
../core/alloc_func.cpp ../core/alloc_func.cpp
../misc/getoptdata.cpp ../misc/getoptdata.cpp
../error.cpp ../error.cpp

View File

@ -298,9 +298,6 @@ char (&ArraySizeHelper(T (&array)[N]))[N];
# define GNU_TARGET(x) # define GNU_TARGET(x)
#endif /* __GNUC__ || __clang__ */ #endif /* __GNUC__ || __clang__ */
/* For the FMT library we only want to use the headers, not link to some library. */
#define FMT_HEADER_ONLY
[[noreturn]] void NOT_REACHED(const std::source_location location = std::source_location::current()); [[noreturn]] void NOT_REACHED(const std::source_location location = std::source_location::current());
[[noreturn]] void AssertFailedError(const char *expression, const std::source_location location = std::source_location::current()); [[noreturn]] void AssertFailedError(const char *expression, const std::source_location location = std::source_location::current());

View File

@ -8,6 +8,7 @@ if (NOT HOST_BINARY_DIR)
set(sourcefiles set(sourcefiles
strgen.cpp strgen.cpp
strgen_base.cpp strgen_base.cpp
../3rdparty/fmt/format.cc
../core/alloc_func.cpp ../core/alloc_func.cpp
../misc/getoptdata.cpp ../misc/getoptdata.cpp
../error.cpp ../error.cpp