Skip to content

Commit fb3fe65

Browse files
committed
adjustments to facilitating to std::format
when it's ready, which it's not...
1 parent 7969edf commit fb3fe65

File tree

10 files changed

+41
-25
lines changed

10 files changed

+41
-25
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ option(REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduce
4646
macro(CHECK_GCC compiler_path)
4747
execute_process(COMMAND ${compiler_path} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
4848
string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT)
49-
if(${GCC_VERSION_OUT} VERSION_LESS "10")
50-
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 10 or later")
49+
if(${GCC_VERSION_OUT} VERSION_LESS "11")
50+
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 11 or later")
5151
endif()
5252
endmacro()
5353

@@ -347,13 +347,16 @@ if(BUILD_LIBRARY)
347347
endif()
348348
endif()
349349

350+
# this can be made conditional once we get to better platform support for std::format
350351
INCLUDE(FetchContent)
351352
FetchContent_Declare(
352353
fmt
353354
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
354355
GIT_TAG 790b9389ae99c4ddebdd2736a8602eca1fec684e # 12.1.0 + bugfix for MSVC warning + build time improvements
355356
)
356357
FetchContent_MakeAvailable(fmt)
358+
set(FMTLIB fmt)
359+
add_definitions("-DUSE_FMTLIB")
357360

358361
if(APPLE)
359362
# libstdc++ (GCC 4.8.5 for OS X 10.6)
@@ -436,7 +439,7 @@ macro(dfhack_test name files)
436439
if(BUILD_LIBRARY AND UNIX AND NOT APPLE) # remove this once our MSVC build env has been updated
437440
add_executable(${name} ${files})
438441
target_include_directories(${name} PUBLIC depends/googletest/googletest/include)
439-
target_link_libraries(${name} dfhack fmt gtest)
442+
target_link_libraries(${name} dfhack ${FMTLIB} gtest)
440443
add_test(NAME ${name} COMMAND ${name})
441444
endif()
442445
endmacro()

library/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(MAIN_HEADERS
5858
include/DebugManager.h
5959
include/Error.h
6060
include/Export.h
61+
include/Format.h
6162
include/Hooks.h
6263
include/LuaTools.h
6364
include/LuaWrapper.h
@@ -320,12 +321,12 @@ if(UNIX)
320321
endif()
321322

322323
if(APPLE)
323-
set(PROJECT_LIBS dl dfhack-md5 fmt ${DFHACK_TINYXML})
324+
set(PROJECT_LIBS dl dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
324325
elseif(UNIX)
325-
set(PROJECT_LIBS rt dl dfhack-md5 fmt ${DFHACK_TINYXML})
326+
set(PROJECT_LIBS rt dl dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
326327
else(WIN32)
327328
# FIXME: do we really need psapi?
328-
set(PROJECT_LIBS psapi dbghelp dfhack-md5 fmt ${DFHACK_TINYXML})
329+
set(PROJECT_LIBS psapi dbghelp dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
329330
endif()
330331

331332
set(VERSION_SRCS DFHackVersion.cpp)
@@ -391,7 +392,7 @@ else()
391392
set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" )
392393
set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" )
393394
add_library(dfhooks_dfhack SHARED Hooks.cpp)
394-
target_link_libraries(dfhooks_dfhack dfhack fmt)
395+
target_link_libraries(dfhooks_dfhack dfhack ${FMTLIB})
395396
endif()
396397

397398
# effectively disables debug builds...
@@ -420,7 +421,7 @@ endif()
420421
target_link_libraries(dfhack protobuf-lite clsocket lua jsoncpp_static dfhack-version ${PROJECT_LIBS})
421422
set_target_properties(dfhack PROPERTIES INTERFACE_LINK_LIBRARIES "")
422423

423-
target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static fmt)
424+
target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static ${FMTLIB})
424425
if(WIN32)
425426
target_link_libraries(dfhack-client dbghelp)
426427
endif()

library/Core.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ distribution.
4141
#include "LuaTools.h"
4242
#include "DFHackVersion.h"
4343
#include "md5wrapper.h"
44+
#include "Format.h"
4445

4546
#include "modules/DFSDL.h"
4647
#include "modules/DFSteam.h"
@@ -87,7 +88,6 @@ distribution.
8788
#include <filesystem>
8889
#include <SDL_events.h>
8990

90-
#include <fmt/std.h>
9191

9292
#ifdef _WIN32
9393
#define NOMINMAX
@@ -525,18 +525,19 @@ std::filesystem::path Core::findScript(std::string name)
525525
{
526526
std::vector<std::filesystem::path> paths;
527527
getScriptPaths(&paths);
528-
for (auto it = paths.begin(); it != paths.end(); ++it)
528+
for (auto& path : paths)
529529
{
530530
std::error_code ec;
531-
std::filesystem::path path = std::filesystem::weakly_canonical(*it / name, ec);
531+
auto raw_path = path / name;
532+
std::filesystem::path load_path = std::filesystem::weakly_canonical(raw_path, ec);
532533
if (ec)
533534
{
534-
con.printerr("Error loading '{}' ({})\n", *it / name, ec.message());
535+
con.printerr("Error loading '{}' ({})\n", raw_path, ec.message());
535536
continue;
536537
}
537538

538-
if (Filesystem::isfile(path))
539-
return path;
539+
if (Filesystem::isfile(load_path))
540+
return load_path;
540541
}
541542
return {};
542543
}

library/Error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Error.h"
2+
#include "Format.h"
23
#include "MiscUtils.h"
34

4-
#include <fmt/format.h>
55
#include <string>
66

77
using namespace DFHack::Error;

library/LuaTools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void signal_typeid_error(color_ostream* out, lua_State* state,
249249
int val_index, bool perr, bool signal)
250250
{
251251
std::string typestr = type ? type->getFullName() : "any pointer";
252-
std::string error = fmt::format(fmt::runtime(msg), typestr);
252+
std::string error = fmt::vformat(msg, fmt::make_format_args(typestr)); //FIXME: C++26
253253

254254
if (signal)
255255
{

library/Process.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ distribution.
3535
#include <vector>
3636
#include <filesystem>
3737

38-
#include <fmt/format.h>
39-
#include <fmt/ostream.h>
38+
#include "Format.h"
4039

4140
#ifndef WIN32
4241
#include <dirent.h>

library/VersionInfoFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem)
209209
else if (type == "md5-hash")
210210
{
211211
const char *cstr_value = pMemEntry->Attribute("value");
212-
fmt::print(stderr, "{} ({}): MD5: {}\n", cstr_name, cstr_os, cstr_value ? cstr_value : "NULL");
212+
std::cerr << fmt::format("{} ({}): MD5: {}\n", cstr_name, cstr_os, cstr_value ? cstr_value : "NULL");
213213
if(!cstr_value)
214214
throw Error::SymbolsXmlUnderspecifiedEntry(cstr_name);
215215
mem->addMD5(cstr_value);
216216
}
217217
else if (type == "binary-timestamp")
218218
{
219219
const char *cstr_value = pMemEntry->Attribute("value");
220-
fmt::print(stderr, "{} ({}): PE: {}\n", cstr_name, cstr_os, cstr_value ? cstr_value : "NULL");
220+
std::cerr << fmt::format("{} ({}): PE: {}\n", cstr_name, cstr_os, cstr_value ? cstr_value : "NULL");
221221
if(!cstr_value)
222222
throw Error::SymbolsXmlUnderspecifiedEntry(cstr_name);
223223
mem->addPE(strtol(cstr_value, 0, 16));

library/include/ColorText.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ distribution.
2424

2525
#pragma once
2626
#include "Export.h"
27+
#include "Format.h"
2728

2829
#include <list>
2930
#include <fstream>
@@ -33,9 +34,6 @@ distribution.
3334
#include <stdarg.h>
3435
#include <sstream>
3536

36-
#include <fmt/format.h>
37-
#include <fmt/std.h>
38-
3937
namespace dfproto
4038
{
4139
class CoreTextNotification;

library/include/DataDefs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ distribution.
3535

3636
#include "BitArray.h"
3737
#include "Export.h"
38-
39-
#include <fmt/format.h>
38+
#include "Format.h"
4039

4140
struct lua_State;
4241

library/include/Format.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#ifdef USE_FMTLIB
4+
5+
#include <fmt/format.h>
6+
#include <fmt/std.h>
7+
#include <fmt/ostream.h>
8+
9+
#else
10+
11+
#include <format>
12+
13+
namespace fmt = std;
14+
15+
#endif

0 commit comments

Comments
 (0)