Skip to content

Commit 1ec0691

Browse files
committed
Add CMake argument ENABLE_VERBOSE_LOGGING, disable trace/debug logging in Release builds
1 parent 9d48560 commit 1ec0691

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

BUILDING-cmake.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ Note that `ENABLE_GLES` will be forcibly set to `ON` for Emscripten and Android
115115
The following table contains a list of build options which are only useful in special circumstances, e.g. when
116116
developing libprojectM, trying experimental features or building the library for a special use-case/environment.
117117

118-
| CMake option | Default | Required dependencies | Description |
119-
|------------------------|---------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
120-
| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. |
121-
| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. |
122-
| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. |
123-
| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. |
124-
| `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. |
118+
| CMake option | Default | Required dependencies | Description |
119+
|--------------------------|---------|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
120+
| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. |
121+
| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. |
122+
| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. |
123+
| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. |
124+
| `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. |
125+
| `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. |
125126

126127
### Path options
127128

CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ option(ENABLE_DEBUG_POSTFIX "Add \"d\" (by default) after library names for debu
2525
option(ENABLE_PLAYLIST "Enable building the playlist management library" ON)
2626
option(ENABLE_BOOST_FILESYSTEM "Force the use of boost::filesystem, even if the compiler supports C++17." OFF)
2727
option(ENABLE_SDL_UI "Build the SDL2-based developer test UI. Ignored when building with Emscripten or for Android." OFF)
28+
option(ENABLE_VERBOSE_LOGGING "Enables TRACE and DEBUG logging even in release builds, negatively affecting the performance." OFF)
2829

2930
option(BUILD_TESTING "Build the libprojectM test suite" OFF)
3031
option(BUILD_DOCS "Build documentation" OFF)
@@ -208,6 +209,11 @@ else()
208209
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
209210
endif()
210211

212+
# Disable trace/debug logging in release builds unless explicitly requested
213+
add_compile_definitions(
214+
$<$<OR:$<CONFIG:Debug>,$<BOOL:${ENABLE_VERBOSE_LOGGING}>>:ENABLE_DEBUG_LOGGING>
215+
)
216+
211217
if(BUILD_DOCS)
212218
find_package(Doxygen REQUIRED)
213219
find_package(Sphinx REQUIRED breathe exhale)
@@ -220,15 +226,15 @@ if(BUILD_DOCS)
220226
set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp")
221227

222228
doxygen_add_docs(
223-
projectm_doxygen
224-
src
225-
COMMENT "Generate HTML documentation")
229+
projectm_doxygen
230+
src
231+
COMMENT "Generate HTML documentation")
226232

227233
sphinx_add_docs(
228-
projectm_sphinx
229-
BREATHE_PROJECTS projectm_doxygen
230-
BUILDER html
231-
SOURCE_DIRECTORY docs)
234+
projectm_sphinx
235+
BREATHE_PROJECTS projectm_doxygen
236+
BUILDER html
237+
SOURCE_DIRECTORY docs)
232238
endif()
233239

234240
add_subdirectory(vendor)

src/libprojectM/Logging.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Logging
109109
thread_local static LogLevel m_threadLogLevel; //!< The thread-specific log level.
110110
};
111111

112+
#ifdef ENABLE_DEBUG_LOGGING
112113
#define LOG_TRACE(message) \
113114
if (Logging::HasCallback() && Logging::GetLogLevel() == Logging::LogLevel::Trace) \
114115
{ \
@@ -120,6 +121,10 @@ class Logging
120121
{ \
121122
Logging::Log(message, Logging::LogLevel::Debug); \
122123
}
124+
#else
125+
#define LOG_TRACE(message)
126+
#define LOG_DEBUG(message)
127+
#endif
123128

124129
#define LOG_INFO(message) \
125130
if (Logging::HasCallback() && Logging::GetLogLevel() <= Logging::LogLevel::Information) \

0 commit comments

Comments
 (0)