Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ option(REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduce
macro(CHECK_GCC compiler_path)
execute_process(COMMAND ${compiler_path} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT)
if(${GCC_VERSION_OUT} VERSION_LESS "10")
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 10 or later")
if(${GCC_VERSION_OUT} VERSION_LESS "11")
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 11 or later")
endif()
endmacro()

Expand Down Expand Up @@ -347,6 +347,17 @@ if(BUILD_LIBRARY)
endif()
endif()

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

if(APPLE)
# libstdc++ (GCC 4.8.5 for OS X 10.6)
# fixes crash-on-unwind bug in DF's libstdc++
Expand Down Expand Up @@ -428,7 +439,7 @@ macro(dfhack_test name files)
if(BUILD_LIBRARY AND UNIX AND NOT APPLE) # remove this once our MSVC build env has been updated
add_executable(${name} ${files})
target_include_directories(${name} PUBLIC depends/googletest/googletest/include)
target_link_libraries(${name} dfhack gtest)
target_link_libraries(${name} dfhack ${FMTLIB} gtest)
add_test(NAME ${name} COMMAND ${name})
endif()
endmacro()
Expand Down
11 changes: 11 additions & 0 deletions docs/dev/compile/Compile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,14 @@ a command starting with ``cmake .. -G Ninja`` on Linux and macOS, following the
instructions in the sections above. CMake should automatically locate files that
you placed in ``CMake/downloads``, and use them instead of attempting to
download them.

In addition, some packages used by DFHack are managed using CMake's ``FetchContent``
feature, which requires an online connection during builds. The simplest way to address
this is to have a connection during the first build (during which CMake will download the
dependencies), and then to use CMake's ``FETCHCONTENT_FULLY_DISCONNECTED`` or
``FETCHCONTENT_UPDATES_DISCONNECTED`` defines to control how CMake manages cached
dependencies. If you need even the first-time build be an offline build, you will need
to provide a CMake dependency provider. We do not provide one, but CMake's own documentation
includes a simple provider. For more information about CMake's ``FetchContent`` feature
and how to use it in offline builds, see the
`CMake documentation <https://cmake.org/cmake/help/latest/module/FetchContent.html>`_.
11 changes: 6 additions & 5 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(MAIN_HEADERS
include/DebugManager.h
include/Error.h
include/Export.h
include/Format.h
include/Hooks.h
include/LuaTools.h
include/LuaWrapper.h
Expand Down Expand Up @@ -326,12 +327,12 @@ if(UNIX)
endif()

if(APPLE)
set(PROJECT_LIBS dl dfhack-md5 ${DFHACK_TINYXML})
set(PROJECT_LIBS dl dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
elseif(UNIX)
set(PROJECT_LIBS rt dl dfhack-md5 ${DFHACK_TINYXML})
set(PROJECT_LIBS rt dl dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
else(WIN32)
# FIXME: do we really need psapi?
set(PROJECT_LIBS psapi dbghelp dfhack-md5 ${DFHACK_TINYXML})
set(PROJECT_LIBS psapi dbghelp dfhack-md5 ${FMTLIB} ${DFHACK_TINYXML})
endif()

set(VERSION_SRCS DFHackVersion.cpp)
Expand Down Expand Up @@ -397,7 +398,7 @@ else()
set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "-include Export.h" )
set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "-include Export.h" )
add_library(dfhooks_dfhack SHARED Hooks.cpp)
target_link_libraries(dfhooks_dfhack dfhack)
target_link_libraries(dfhooks_dfhack dfhack ${FMTLIB})
endif()

# effectively disables debug builds...
Expand Down Expand Up @@ -426,7 +427,7 @@ endif()
target_link_libraries(dfhack protobuf-lite clsocket lua jsoncpp_static dfhack-version ${PROJECT_LIBS})
set_target_properties(dfhack PROPERTIES INTERFACE_LINK_LIBRARIES "")

target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static)
target_link_libraries(dfhack-client protobuf-lite clsocket jsoncpp_static ${FMTLIB})
if(WIN32)
target_link_libraries(dfhack-client dbghelp)
endif()
Expand Down
48 changes: 0 additions & 48 deletions library/ColorText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,54 +91,6 @@ color_ostream::~color_ostream()
delete buf();
}

void color_ostream::print(const char *format, ...)
{
va_list args;
va_start(args, format);
vprint(format, args);
va_end(args);
}

void color_ostream::vprint(const char *format, va_list args)
{
std::string str = stl_vsprintf(format, args);

if (!str.empty()) {
flush_buffer(false);
add_text(cur_color, str);
if (str[str.size()-1] == '\n')
flush_proxy();
}
}

void color_ostream::printerr(const char * format, ...)
{
va_list args;
va_start(args, format);
vprinterr(format, args);
va_end(args);
}

void color_ostream::vprinterr(const char *format, va_list args)
{
color_value save = cur_color;

if (log_errors_to_stderr)
{
va_list args1;
va_copy(args1, args);
vfprintf(stderr, format, args1);
va_end(args1);
}

color(COLOR_LIGHTRED);
va_list args2;
va_copy(args2, args);
vprint(format, args2);
va_end(args2);
color(save);
}

void color_ostream::color(color_value c)
{
if (c == cur_color)
Expand Down
41 changes: 21 additions & 20 deletions library/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace DFHack
"See more commands by running 'ls'.\n\n"
);

con.print("DFHack version %s\n", dfhack_version_desc().c_str());
con.print("DFHack version {}\n", dfhack_version_desc());
}
else
{
Expand Down Expand Up @@ -100,12 +100,12 @@ namespace DFHack
}
}
if (ret != CR_OK)
con.printerr("%s failed\n", first.c_str());
con.printerr("{} failed\n", first.c_str());
return ret;
}
else
{
con.printerr("%s: no arguments\n", first.c_str());
con.printerr("{}: no arguments\n", first.c_str());
return CR_FAILURE;
}

Expand All @@ -128,7 +128,7 @@ namespace DFHack

if (has_backslashes(part))
{
con.printerr("Replacing backslashes with forward slashes in \"%s\"\n", part.c_str());
con.printerr("Replacing backslashes with forward slashes in \"{}\"\n", part);
replace_backslashes_with_forwardslashes(part);
}

Expand All @@ -146,20 +146,20 @@ namespace DFHack
else
{
res = CR_NOT_FOUND;
con.printerr("No such plugin or Lua script: %s\n", part.c_str());
con.printerr("No such plugin or Lua script: {}\n", part);
}
}
else if (!plug->can_set_enabled())
{
res = CR_NOT_IMPLEMENTED;
con.printerr("Cannot %s plugin: %s\n", first.c_str(), part.c_str());
con.printerr("Cannot {} plugin: {}\n", first, part);
}
else
{
res = plug->set_enabled(con, enable);

if (res != CR_OK || plug->is_enabled() != enable)
con.printerr("Could not %s plugin: %s\n", first.c_str(), part.c_str());
con.printerr("Could not {} plugin: {}\n", first, part);
}
}

Expand All @@ -174,7 +174,7 @@ namespace DFHack
if (!plug->can_be_enabled()) continue;

con.print(
"%21s %-3s%s\n",
"{:>21} {:<3}{}\n",
(key + ":").c_str(),
plug->is_enabled() ? "on" : "off",
plug->can_set_enabled() ? "" : " (controlled internally)"
Expand All @@ -189,8 +189,8 @@ namespace DFHack

command_result Commands::plug(color_ostream& con, Core& core, const std::string& first, const std::vector<std::string>& parts)
{
constexpr auto header_format = "%30s %10s %4s %8s\n";
constexpr auto row_format = "%30s %10s %4zu %8s\n";
constexpr auto header_format = "{:30} {:10} {:4} {:8}\n";
constexpr auto row_format = header_format;

con.print(header_format, "Name", "State", "Cmds", "Enabled");

Expand Down Expand Up @@ -227,7 +227,7 @@ namespace DFHack
}
con.color(color);
con.print(row_format,
plug->getName().c_str(),
plug->getName(),
Plugin::getStateDescription(plug->getState()),
plug->size(),
(plug->can_be_enabled()
Expand Down Expand Up @@ -293,11 +293,11 @@ namespace DFHack
for (const auto& part : parts | std::views::drop(2) | std::views::reverse) {
auto spec = KeySpec::parse(keystr, &parse_error);
if (!spec.has_value()) {
con.printerr("%s\n", parse_error.c_str());
con.printerr("{}\n", parse_error);
break;
}
if (!hotkey_mgr->addKeybind(spec.value(), part)) {
con.printerr("Invalid command: '%s'\n", part.c_str());
con.printerr("Invalid command: '{}'\n", part);
break;
}
}
Expand All @@ -306,7 +306,7 @@ namespace DFHack
for (const auto& part : parts | std::views::drop(1)) {
auto spec = KeySpec::parse(part, &parse_error);
if (!spec.has_value()) {
con.printerr("%s\n", parse_error.c_str());
con.printerr("{}\n", parse_error);
}
if (!hotkey_mgr->removeKeybind(spec.value())) {
con.printerr("No matching keybinds to remove\n");
Expand All @@ -317,7 +317,7 @@ namespace DFHack
else if (parts.size() == 2 && parts[0] == "list") {
auto spec = KeySpec::parse(parts[1], &parse_error);
if (!spec.has_value()) {
con.printerr("%s\n", parse_error.c_str());
con.printerr("{}\n", parse_error);
return CR_FAILURE;
}
std::vector<std::string> list = hotkey_mgr->listKeybinds(spec.value());
Expand All @@ -326,7 +326,8 @@ namespace DFHack
for (const auto& kb : list)
con << " " << kb << std::endl;
}
else {
else
{
con << "Usage:\n"
<< " keybinding list <key>\n"
<< " keybinding clear <key>[@context]...\n"
Expand All @@ -350,15 +351,15 @@ namespace DFHack
std::vector<std::string> cmd(parts.begin() + 2, parts.end());
if (!core.AddAlias(name, cmd, parts[0] == "replace"))
{
con.printerr("Could not add alias %s - already exists\n", name.c_str());
con.printerr("Could not add alias {} - already exists\n", name);
return CR_FAILURE;
}
}
else if (parts.size() >= 2 && (parts[0] == "delete" || parts[0] == "clear"))
{
if (!core.RemoveAlias(parts[1]))
{
con.printerr("Could not remove alias %s\n", parts[1].c_str());
con.printerr("Could not remove alias {}\n", parts[1]);
return CR_FAILURE;
}
}
Expand Down Expand Up @@ -490,10 +491,10 @@ namespace DFHack
{
if (!parts[1].size() || (state_script.event == sc_event_id(parts[1])))
{
con.print("%s (%s): %s%s\n", sc_event_name(state_script.event).c_str(),
con.print("{} ({}): {}{}\n", sc_event_name(state_script.event),
state_script.save_specific ? "save-specific" : "global",
state_script.save_specific ? "<save folder>/raw/" : "<DF folder>/",
state_script.path.c_str());
state_script.path);
}
}
return CR_OK;
Expand Down
Loading