Skip to content

Commit

Permalink
Merge pull request #94 from sourcefrog/enable-trace
Browse files Browse the repository at this point in the history
Add CMake -D ENABLE_TRACE=ON
  • Loading branch information
dbaarda committed Oct 23, 2016
2 parents ba0936f + bdb21d2 commit b0b4840
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ if (NOT CMAKE_SYSTEM_NAME)
message(FATAL_ERROR "No target OS set")
endif()

set(DO_RS_TRACE 0)
option(ENABLE_TRACE "Compile in detailed trace messages" OFF)
if (ENABLE_TRACE)
set(DO_RS_TRACE 1)
endif (ENABLE_TRACE)
message(STATUS "DO_RS_TRACE=${DO_RS_TRACE}")

# Add an option to include compression support
option(ENABLE_COMPRESSION "Whether or not to build with compression support" OFF)
# TODO: Remove this warning when compression is implemented.
Expand Down Expand Up @@ -67,7 +74,6 @@ check_include_files ( zlib.h HAVE_ZLIB_H )

#Temporary configuration
set ( STDC_HEADERS 1 )
set ( DO_RS_TRACE 0 )
set ( HAVE_PROGRAM_INVOCATION_NAME 0)

# Remove compression support if not needed
Expand Down
3 changes: 3 additions & 0 deletions doc/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ default. You can turn it on by using `ENABLE_COMPRESSION` option:

$ cmake -D ENABLE_COMPRESSION=ON .

To build code for debug trace messages:

$ cmake -D ENABLE_TRACE=ON .

## Ninja builds

Expand Down
16 changes: 6 additions & 10 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ int rs_trace_level = RS_LOG_INFO;

static void rs_log_va(int level, char const *fn, char const *fmt, va_list va);

#if SIZEOF_SIZE_T > SIZEOF_LONG
# warning size_t is larger than a long integer, values in trace messages may be wrong
#endif


/**
* Log severity strings, if any. Must match ordering in
Expand Down Expand Up @@ -109,7 +105,7 @@ static void
rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
{
int level = flags & RS_LOG_PRIMASK;

if (rs_trace_impl && level <= rs_trace_level) {
char buf[1000];
char full_buf[1000];
Expand All @@ -126,7 +122,7 @@ rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
MY_NAME, rs_severities[level], fn, buf);
}

rs_trace_impl(level, full_buf);
rs_trace_impl(level, full_buf);
}
}

Expand Down Expand Up @@ -173,7 +169,7 @@ rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg)
void
rs_fatal0(char const *s, ...)
{
va_list va;
va_list va;

va_start(va, s);
rs_log_va(RS_LOG_CRIT, PACKAGE, s, va);
Expand All @@ -187,7 +183,7 @@ rs_fatal0(char const *s, ...)
void
rs_error0(char const *s, ...)
{
va_list va;
va_list va;

va_start(va, s);
rs_log_va(RS_LOG_ERR, PACKAGE, s, va);
Expand All @@ -201,7 +197,7 @@ void
rs_trace0(char const *s, ...)
{
#ifdef DO_RS_TRACE
va_list va;
va_list va;

va_start(va, s);
rs_log_va(RS_LOG_DEBUG, PACKAGE, s, va);
Expand All @@ -217,5 +213,5 @@ rs_supports_trace(void)
return 1;
#else
return 0;
#endif /* !DO_RS_TRACE */
#endif /* !DO_RS_TRACE */
}

0 comments on commit b0b4840

Please sign in to comment.