Add CMake argument ENABLE_VERBOSE_LOGGING, disable trace/debug logging in Release builds

This commit is contained in:
Kai Blaschke
2025-12-05 12:44:11 +01:00
parent 4a0fa11f0f
commit 0a4a2b543f
3 changed files with 26 additions and 14 deletions

View File

@ -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

View File

@ -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(
$<$<OR:$<CONFIG:Debug>,$<BOOL:${ENABLE_VERBOSE_LOGGING}>>: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)

View File

@ -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) \