From 0a4a2b543f96f5db15bb59c6af00168e16f50281 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Fri, 5 Dec 2025 12:44:11 +0100 Subject: [PATCH] Add CMake argument ENABLE_VERBOSE_LOGGING, disable trace/debug logging in Release builds --- BUILDING-cmake.md | 15 ++++++++------- CMakeLists.txt | 20 +++++++++++++------- src/libprojectM/Logging.hpp | 5 +++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/BUILDING-cmake.md b/BUILDING-cmake.md index 53d020afb..ee27dee7f 100644 --- a/BUILDING-cmake.md +++ b/BUILDING-cmake.md @@ -115,13 +115,14 @@ Note that `ENABLE_GLES` will be forcibly set to `ON` for Emscripten and Android The following table contains a list of build options which are only useful in special circumstances, e.g. when developing libprojectM, trying experimental features or building the library for a special use-case/environment. -| CMake option | Default | Required dependencies | Description | -|------------------------|---------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. | -| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. | -| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. | -| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. | -| `ENABLE_CXX_INTERFACE` | `OFF` | | Exports symbols for the `ProjectM` and `PCM` C++ classes and installs the additional the headers. Using the C++ interface is not recommended and unsupported. | +| CMake option | Default | Required dependencies | Description | +|--------------------------|---------|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. | +| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. | +| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. | +| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. | +| `ENABLE_CXX_INTERFACE` | `OFF` | | Exports symbols for the `ProjectM` and `PCM` C++ classes and installs the additional the headers. Using the C++ interface is not recommended and unsupported. | +| `ENABLE_VERBOSE_LOGGING` | `OFF` | | Enables code for `TRACE` and `DEBUG` log levels in release builds. By default, these will only be compiled for `Debug` builds. Enabling this will negatively affect performance, even if the actual log level is set to `INFORMATION` or higher. | ### Path options diff --git a/CMakeLists.txt b/CMakeLists.txt index da747d156..32000a1bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(ENABLE_DEBUG_POSTFIX "Add \"d\" (by default) after library names for debu option(ENABLE_PLAYLIST "Enable building the playlist management library" ON) option(ENABLE_BOOST_FILESYSTEM "Force the use of boost::filesystem, even if the compiler supports C++17." OFF) option(ENABLE_SDL_UI "Build the SDL2-based developer test UI. Ignored when building with Emscripten or for Android." OFF) +option(ENABLE_VERBOSE_LOGGING "Enables TRACE and DEBUG logging even in release builds, negatively affecting the performance." OFF) option(BUILD_TESTING "Build the libprojectM test suite" OFF) option(BUILD_DOCS "Build documentation" OFF) @@ -208,6 +209,11 @@ else() set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) endif() +# Disable trace/debug logging in release builds unless explicitly requested +add_compile_definitions( + $<$,$>:ENABLE_DEBUG_LOGGING> + ) + if(BUILD_DOCS) find_package(Doxygen REQUIRED) find_package(Sphinx REQUIRED breathe exhale) @@ -220,15 +226,15 @@ if(BUILD_DOCS) set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp") doxygen_add_docs( - projectm_doxygen - src - COMMENT "Generate HTML documentation") + projectm_doxygen + src + COMMENT "Generate HTML documentation") sphinx_add_docs( - projectm_sphinx - BREATHE_PROJECTS projectm_doxygen - BUILDER html - SOURCE_DIRECTORY docs) + projectm_sphinx + BREATHE_PROJECTS projectm_doxygen + BUILDER html + SOURCE_DIRECTORY docs) endif() add_subdirectory(vendor) diff --git a/src/libprojectM/Logging.hpp b/src/libprojectM/Logging.hpp index 6cec3a25a..1b0ce021b 100644 --- a/src/libprojectM/Logging.hpp +++ b/src/libprojectM/Logging.hpp @@ -109,6 +109,7 @@ private: thread_local static LogLevel m_threadLogLevel; //!< The thread-specific log level. }; +#ifdef ENABLE_DEBUG_LOGGING #define LOG_TRACE(message) \ if (Logging::HasCallback() && Logging::GetLogLevel() == Logging::LogLevel::Trace) \ { \ @@ -120,6 +121,10 @@ private: { \ Logging::Log(message, Logging::LogLevel::Debug); \ } +#else +#define LOG_TRACE(message) +#define LOG_DEBUG(message) +#endif #define LOG_INFO(message) \ if (Logging::HasCallback() && Logging::GetLogLevel() <= Logging::LogLevel::Information) \