Skip to content

Commit

Permalink
Fix fmt on compile using cmake
Browse files Browse the repository at this point in the history
* Fix fmt on compile using cmake.

https://discord.com/channels/1034803542512369704/1058105393932406964

* Fix compiler erro in format date on linux
  • Loading branch information
alfuveam authored Feb 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ffae0a6 commit 265d458
Showing 3 changed files with 16 additions and 30 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ find_package(PugiXML REQUIRED)
find_package(MySQL)
find_package(Threads)
find_package(ZLIB REQUIRED)
find_package(fmt 6.1.2 REQUIRED)

# Selects LuaJIT if user defines or auto-detected
if(DEFINED USE_LUAJIT AND NOT USE_LUAJIT)
@@ -50,7 +51,17 @@ add_subdirectory(src)
add_executable(tfs ${tfs_SRC})

include_directories(${MYSQL_INCLUDE_DIR} ${LUA_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR} ${Crypto++_INCLUDE_DIR})
target_link_libraries(tfs ${MYSQL_CLIENT_LIBS} ${ZLIB_LIBRARY} ${LUA_LIBRARIES} ${Boost_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY} ${PUGIXML_LIBRARIES} ${Crypto++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(tfs
${MYSQL_CLIENT_LIBS}
${ZLIB_LIBRARY}
${LUA_LIBRARIES}
${Boost_LIBRARIES}
${Boost_FILESYSTEM_LIBRARY}
${PUGIXML_LIBRARIES}
${Crypto++_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
fmt::fmt
)

set_target_properties(tfs PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "src/otpch.h")
set_target_properties(tfs PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
1 change: 0 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@
#include "weapons.h"
#include "script.h"

#define FMT_HEADER_ONLY
#include <fmt/format.h>

extern ConfigManager g_config;
32 changes: 4 additions & 28 deletions src/tools.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@
#include "tools.h"
#include "configmanager.h"

#include <fmt/chrono.h>

extern ConfigManager g_config;

void printXMLError(const std::string& where, const std::string& fileName, const pugi::xml_parse_result& result)
@@ -614,35 +616,9 @@ std::string convertIPToString(uint32_t ip)
return buffer;
}

std::string formatDate(time_t time)
{
const tm* tms = localtime(&time);
if (!tms) {
return {};
}

char buffer[20];
int res = sprintf(buffer, "%02d/%02d/%04d %02d:%02d:%02d", tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec);
if (res < 0) {
return {};
}
return {buffer, 19};
}

std::string formatDateShort(time_t time)
{
const tm* tms = localtime(&time);
if (!tms) {
return {};
}
std::string formatDate(time_t time) { return fmt::format("{:%d/%m/%Y %H:%M:%S}", fmt::localtime(time)); }

char buffer[12];
size_t res = strftime(buffer, 12, "%d %b %Y", tms);
if (res == 0) {
return {};
}
return {buffer, 11};
}
std::string formatDateShort(time_t time) { return fmt::format("{:%d %b %Y}", fmt::localtime(time)); }

Direction getDirection(const std::string& string)
{

0 comments on commit 265d458

Please sign in to comment.