refactor(framework): create debug output ostream that redirects to a null stream if TB_EXT_FRAMEWORK_DEBUG isn't defined or is set to 0

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-01-15 20:13:42 -05:00
parent d7ee745205
commit b6df1547e2
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
4 changed files with 23 additions and 2 deletions

View File

@ -17,6 +17,8 @@ if(NOT DEFINED QT6_ROOT_DIR)
message(FATAL_ERROR "QT6_ROOT_DIR is not defined. Please set the QT6_ROOT_DIR variable to the root directory of the Qt 6 installation.")
endif()
option(TOON_BOOM_EXTENSION_FRAMEWORK_DEBUG "Enable debug output" ON)
include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
list(APPEND CMAKE_PREFIX_PATH ${QT6_ROOT_DIR})
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")

View File

@ -19,6 +19,9 @@ list(FILTER FRAMEWORK_SOURCES EXCLUDE REGEX "/(out|build|cmake-build-|CMakeFiles
file(COPY "${QT5_ROOT_DIR}/include/QtScript" DESTINATION ${CMAKE_BINARY_DIR}/include)
find_package(minhook CONFIG REQUIRED)
function(link_libs_and_set_properties target_name)
if(TOON_BOOM_EXTENSION_FRAMEWORK_DEBUG)
target_compile_definitions(${target_name} PUBLIC TB_EXT_FRAMEWORK_DEBUG=1)
endif()
target_compile_features(${target_name} PUBLIC cxx_std_20)
target_include_directories(${target_name} PUBLIC "${CMAKE_BINARY_DIR}/include")
target_link_libraries(${target_name} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/QtScript.lib")

5
framework/debug.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "include/public/toon_boom/ext/util.hpp"
std::ostream devnull(new NullBuffer());
std::ostream& out = TB_EXT_FRAMEWORK_DEBUG ? std::cout : devnull;

View File

@ -1,7 +1,18 @@
#pragma once
#include <format>
#include <iostream>
#include <streambuf>
#if !defined(TB_EXT_FRAMEWORK_DEBUG)
#define TB_EXT_FRAMEWORK_DEBUG 0
#endif
struct NullBuffer : std::streambuf {
int overflow(int c) { return c; }
};
std::string addrToHex(void *addr);
std::string constAddrToHex(const void *addr);
extern std::ostream &out;