Added a CMake option that allows to show debug messages in release mode

This commit is contained in:
Tsuda Kageyu 2013-06-09 23:52:05 +09:00
parent 12953b3fdc
commit 2f29ed003c
4 changed files with 23 additions and 12 deletions

View File

@ -90,6 +90,11 @@ if(WITH_MP4)
set(TAGLIB_WITH_MP4 TRUE)
endif()
option(TRACE_IN_RELEASE "Output debug messages even in release mode" OFF)
if(TRACE_IN_RELEASE)
set(TAGLIB_TRACE_IN_RELEASE TRUE)
endif()
configure_file(taglib/taglib_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h)
add_subdirectory(taglib)

View File

@ -3,3 +3,4 @@
#define TAGLIB_WITH_ASF 1
#define TAGLIB_WITH_MP4 1
#cmakedefine TAGLIB_TRACE_IN_RELEASE 1

View File

@ -24,6 +24,7 @@
***************************************************************************/
#include "config.h"
#include "taglib_config.h"
#include "tdebug.h"
#include "tstring.h"
@ -67,11 +68,17 @@ namespace
void TagLib::debug(const String &s)
{
#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE)
getDebugListener()->printMessage("TagLib: " + s + "\n");
#endif
}
void TagLib::debugData(const ByteVector &v)
{
#if !defined(NDEBUG) || defined(TAGLIB_TRACE_IN_RELEASE)
for(size_t i = 0; i < v.size(); ++i)
{
String msg
@ -85,4 +92,6 @@ void TagLib::debugData(const ByteVector &v)
getDebugListener()->printMessage(msg);
}
#endif
}

View File

@ -25,12 +25,11 @@
#include "tdebuglistener.h"
#ifndef NDEBUG
# include <iostream>
# include <bitset>
# ifdef _WIN32
# include <windows.h>
# endif
#include <iostream>
#include <bitset>
#ifdef _WIN32
# include <windows.h>
#endif
using namespace TagLib;
@ -42,8 +41,7 @@ namespace
public:
virtual void printMessage(const String &msg)
{
#ifndef NDEBUG
# ifdef _WIN32
#ifdef _WIN32
const wstring wstr = msg.toWString();
const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
@ -54,13 +52,11 @@ namespace
std::cerr << std::string(&buf[0]);
}
# else
#else
std::cerr << msg;
# endif
#endif
#endif
}
};