Browse Source

Use system libfmt by default if version >= 7.0.0

Allow non-strict ansi functions

Cleanup
pull/1689/head
Jmgr 5 years ago committed by Anders Jenbo
parent
commit
ef0ca794bc
  1. 33
      3rdParty/libfmt/CMakeLists.txt
  2. 9
      CMakeLists.txt
  3. 11
      Source/DiabloUI/selgame.cpp
  4. 3
      Source/debug.cpp
  5. 6
      Source/stores.cpp
  6. 57
      Source/utils/format.hpp

33
3rdParty/libfmt/CMakeLists.txt vendored

@ -1,18 +1,23 @@
if(NOT DEVILUTIONX_SYSTEM_LIBFMT)
include(FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent_MakeAvailableExcludeFromAll)
if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
# Enable POSIX extensions such as `readlink` and `ftruncate`.
add_definitions(-D_POSIX_C_SOURCE=200809L)
# Defining _POSIX_C_SOURCE should be enough for the compiler not to define __STRICT_ANSI__
# but some still do, so we also have to explicitly undefine it.
add_compile_options(-U__STRICT_ANSI__)
endif()
if(DEVILUTIONX_STATIC_LIBFMT)
set(BUILD_SHARED_LIBS OFF)
else()
set(BUILD_SHARED_LIBS ON)
endif()
include(FetchContent)
FetchContent_Declare(fmt
URL https://github.com/fmtlib/fmt/archive/7bdf0628b1276379886c7f6dda2cef2b3b374f0b.zip
URL_HASH MD5=70e0a0beda4bdac7debe60d380e1d802
)
FetchContent_MakeAvailableExcludeFromAll(fmt)
set(fmt_SOURCE_DIR ${fmt_SOURCE_DIR} PARENT_SCOPE)
if(DEVILUTIONX_STATIC_LIBFMT)
set(BUILD_SHARED_LIBS OFF)
else()
set(BUILD_SHARED_LIBS ON)
endif()
include(FetchContent)
FetchContent_Declare(fmt
URL https://github.com/fmtlib/fmt/archive/7bdf0628b1276379886c7f6dda2cef2b3b374f0b.zip
URL_HASH MD5=70e0a0beda4bdac7debe60d380e1d802
)
FetchContent_MakeAvailableExcludeFromAll(fmt)
set(fmt_INCLUDE_DIR ${fmt_SOURCE_DIR} PARENT_SCOPE)

9
CMakeLists.txt

@ -43,7 +43,7 @@ option(DEVILUTIONX_SYSTEM_LIBSODIUM "Use system-provided libsodium" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_LIBSODIUM "Link static libsodium" OFF
"DEVILUTIONX_SYSTEM_LIBSODIUM AND NOT DIST" ON)
option(DEVILUTIONX_SYSTEM_LIBFMT "Use system-provided libfmt" OFF)
option(DEVILUTIONX_SYSTEM_LIBFMT "Use system-provided libfmt" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_LIBFMT "Link static libfmt" OFF
"DEVILUTIONX_SYSTEM_LIBFMT AND NOT DIST" ON)
@ -176,8 +176,9 @@ endif()
if(DEVILUTIONX_SYSTEM_LIBFMT)
set(fmt_USE_STATIC_LIBS ${DEVILUTIONX_STATIC_LIBFMT})
find_package(fmt REQUIRED)
else()
find_package(fmt 7.0.0 QUIET)
endif()
if(NOT fmt_FOUND)
add_subdirectory(3rdParty/libfmt)
endif()
@ -468,7 +469,7 @@ target_include_directories(${BIN_TARGET} PRIVATE
3rdParty/asio/include
3rdParty/Radon/Radon/include
3rdParty/libsmacker
${fmt_SOURCE_DIR}/include
${fmt_INCLUDE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR})
if(NOT N3DS)

11
Source/DiabloUI/selgame.cpp

@ -11,8 +11,6 @@
#include "options.h"
#include "storm/storm.h"
#include <fmt/format.h>
namespace devilution {
char selgame_Label[32];
@ -412,11 +410,10 @@ static bool IsGameCompatible(GameData *data)
if (data->programid != GAME_ID) {
UiSelOkDialog(title, "The host is running a different game than you.", false);
} else {
// An example of using a format with references. Note the references that allow a localized string to change the order of the inserted parameters.
// Note that named insertions would probably be better here, but this is just to provide an example.
auto msg = fmt::format("Your version {0} does not match the host {1}.{2}.{3}.", PROJECT_VERSION, PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH);
UiSelOkDialog(title, msg.c_str(), false);
char msg[64];
sprintf(msg, "Your version %s does not match the host %d.%d.%d.", PROJECT_VERSION, PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH);
UiSelOkDialog(title, msg, false);
}
LoadBackgroundArt("ui_art\\selgame.pcx");

3
Source/debug.cpp

@ -7,9 +7,6 @@
#include "cursor.h"
#include "inv.h"
#include "spells.h"
#include "utils/format.hpp"
#include <fmt/format.h>
namespace devilution {

6
Source/stores.cpp

@ -6,7 +6,6 @@
#include "stores.h"
#include <algorithm>
#include <fmt/format.h>
#include "cursor.h"
#include "init.h"
@ -271,9 +270,8 @@ void S_StartSBuy()
stextsize = true;
stextscrl = true;
stextsval = 0;
// An example of a named format insertion.
auto str = fmt::format("I have these items for sale: Your gold: {gold}", fmt::arg("gold", plr[myplr]._pGold));
AddSText(0, 1, true, str.c_str(), COL_GOLD, false);
sprintf(tempstr, "I have these items for sale: Your gold: %i", plr[myplr]._pGold);
AddSText(0, 1, true, tempstr, COL_GOLD, false);
AddSLine(3);
AddSLine(21);
S_ScrollSBuy(stextsval);

57
Source/utils/format.hpp

@ -1,57 +0,0 @@
#pragma once
#include "../player.h"
#include <fmt/format.h>
namespace fmt {
template <>
struct formatter<devilution::PLR_MODE> : formatter<string_view> {
template <typename FormatContext>
auto format(devilution::PLR_MODE mode, FormatContext &ctx)
{
string_view name = "unknown";
switch (mode) {
case devilution::PM_STAND:
name = "stand";
break;
case devilution::PM_WALK:
name = "walk (N, NW, or NE)";
break;
case devilution::PM_WALK2:
name = "walk (S, SW, or SE)";
break;
case devilution::PM_WALK3:
name = "walk (W or E)";
break;
case devilution::PM_ATTACK:
name = "attack";
break;
case devilution::PM_RATTACK:
name = "ranged attack";
break;
case devilution::PM_BLOCK:
name = "block";
break;
case devilution::PM_GOTHIT:
name = "got hit";
break;
case devilution::PM_DEATH:
name = "death";
break;
case devilution::PM_SPELL:
name = "spell";
break;
case devilution::PM_NEWLVL:
name = "new level";
break;
case devilution::PM_QUIT:
name = "quit";
break;
}
return formatter<string_view>::format(name, ctx);
}
};
}
Loading…
Cancel
Save