Cycles: Fully support WITH_CYCLES_LOGGING option

This commit generalizes logging module a little bit in making it possible to use
Glog logging in standalone Cycles repository.
This commit is contained in:
Sergey Sharybin 2014-11-16 01:12:19 +05:00
parent f2665d52e2
commit bbf12722ed
7 changed files with 94 additions and 51 deletions

@ -134,19 +134,11 @@ add_definitions(
if(WITH_CYCLES_LOGGING)
add_definitions(-DWITH_CYCLES_LOGGING)
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
if(WIN32)
include_directories(
SYSTEM
../../extern/libmv/third_party/glog/src/windows
../../extern/libmv/third_party/gflags
)
else()
include_directories(
SYSTEM
../../extern/libmv/third_party/glog/src
../../extern/libmv/third_party/gflags
)
endif()
include_directories(
SYSTEM
${GLOG_INCLUDE_DIRS}
${GFLAGS_INCLUDE_DIRS}
)
endif()
# Debugging capabilities (debug passes etc).

@ -37,7 +37,14 @@ if(NOT PUGIXML_LIBRARIES STREQUAL "")
list(APPEND LIBRARIES ${PUGIXML_LIBRARIES})
endif()
if(NOT CYCLES_STANDALONE_REPOSITORY)
if(CYCLES_STANDALONE_REPOSITORY)
if(WITH_CYCLES_LOGGING)
list(APPEND LIBRARIES
${GLOG_LIBRARIES}
${GFLAGS_LIBRARIES}
)
endif()
else()
list(APPEND LIBRARIES bf_intern_glew_mx)
endif()

@ -25,6 +25,7 @@
#include "util_args.h"
#include "util_foreach.h"
#include "util_function.h"
#include "util_logging.h"
#include "util_path.h"
#include "util_progress.h"
#include "util_string.h"
@ -331,7 +332,8 @@ static void options_parse(int argc, const char **argv)
/* parse options */
ArgParse ap;
bool help = false;
bool help = false, debug = false;
int verbosity = 1;
ap.options ("Usage: cycles [options] file.xml",
"%*", files_parse, "",
@ -347,6 +349,10 @@ static void options_parse(int argc, const char **argv)
"--width %d", &options.width, "Window width in pixel",
"--height %d", &options.height, "Window height in pixel",
"--list-devices", &list, "List information about all available devices",
#ifdef WITH_CYCLES_LOGGING
"--debug", &debug, "Enable debug logging",
"--verbose %d", &verbosity, "Set verbosity of the logger",
#endif
"--help", &help, "Print help message",
NULL);
@ -355,7 +361,13 @@ static void options_parse(int argc, const char **argv)
ap.usage();
exit(EXIT_FAILURE);
}
else if(list) {
if (debug) {
util_logging_start();
util_logging_verbosity_set(verbosity);
}
if(list) {
vector<DeviceInfo>& devices = Device::available_devices();
printf("Devices:\n");
@ -435,6 +447,7 @@ using namespace ccl;
int main(int argc, const char **argv)
{
util_logging_init(argv[0]);
path_init();
options_parse(argc, argv);

@ -15,51 +15,19 @@
*/
#include "CCL_api.h"
#include <stdio.h>
#include "util_logging.h"
#ifdef _MSC_VER
# define snprintf _snprintf
#endif
void CCL_init_logging(const char *argv0)
{
#ifdef WITH_CYCLES_LOGGING
/* Make it so FATAL messages are always print into console. */
char severity_fatal[32];
snprintf(severity_fatal, sizeof(severity_fatal), "%d",
google::GLOG_FATAL);
google::InitGoogleLogging(argv0);
gflags::SetCommandLineOption("logtostderr", "1");
gflags::SetCommandLineOption("v", "0");
gflags::SetCommandLineOption("stderrthreshold", severity_fatal);
gflags::SetCommandLineOption("minloglevel", severity_fatal);
#else
(void) argv0;
#endif
ccl::util_logging_init(argv0);
}
void CCL_start_debug_logging(void)
{
#ifdef WITH_CYCLES_LOGGING
gflags::SetCommandLineOption("logtostderr", "1");
gflags::SetCommandLineOption("v", "2");
gflags::SetCommandLineOption("stderrthreshold", "1");
gflags::SetCommandLineOption("minloglevel", "0");
#endif
ccl::util_logging_start();
}
void CCL_logging_verbosity_set(int verbosity)
{
#ifdef WITH_CYCLES_LOGGING
char val[10];
snprintf(val, sizeof(val), "%d", verbosity);
gflags::SetCommandLineOption("v", val);
#else
(void) verbosity;
#endif
ccl::util_logging_verbosity_set(verbosity);
}

@ -109,5 +109,20 @@ if(CYCLES_STANDALONE_REPOSITORY)
find_package(LLVM REQUIRED)
endif()
####
# Logging
if(WITH_CYCLES_LOGGING)
find_package(Glog REQUIRED)
find_package(Gflags REQUIRED)
endif()
unset(_lib_DIR)
else()
if(WIN32)
set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/libmv/third_party/glog/src/windows)
set(GFLAGS_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/libmv/third_party/gflags)
else()
set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/libmv/third_party/glog/src)
set(GFLAGS_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/libmv/third_party/gflags)
endif()
endif()

@ -18,8 +18,52 @@
#include "util_math.h"
#include <stdio.h>
#ifdef _MSC_VER
# define snprintf _snprintf
#endif
CCL_NAMESPACE_BEGIN
void util_logging_init(const char *argv0)
{
#ifdef WITH_CYCLES_LOGGING
/* Make it so FATAL messages are always print into console. */
char severity_fatal[32];
snprintf(severity_fatal, sizeof(severity_fatal), "%d",
google::GLOG_FATAL);
google::InitGoogleLogging(argv0);
gflags::SetCommandLineOption("logtostderr", "1");
gflags::SetCommandLineOption("v", "0");
gflags::SetCommandLineOption("stderrthreshold", severity_fatal);
gflags::SetCommandLineOption("minloglevel", severity_fatal);
#else
(void) argv0;
#endif
}
void util_logging_start(void)
{
#ifdef WITH_CYCLES_LOGGING
gflags::SetCommandLineOption("logtostderr", "1");
gflags::SetCommandLineOption("v", "2");
gflags::SetCommandLineOption("stderrthreshold", "1");
gflags::SetCommandLineOption("minloglevel", "0");
#endif
}
void util_logging_verbosity_set(int verbosity)
{
#ifdef WITH_CYCLES_LOGGING
char val[10];
snprintf(val, sizeof(val), "%d", verbosity);
gflags::SetCommandLineOption("v", val);
#else
(void) verbosity;
#endif
}
std::ostream& operator <<(std::ostream &os,
const float3 &value)
{

@ -45,6 +45,10 @@ public:
struct float3;
void util_logging_init(const char *argv0);
void util_logging_start(void);
void util_logging_verbosity_set(int verbosity);
std::ostream& operator <<(std::ostream &os,
const float3 &value);