[Bf-blender-cvs] [bbf1272] master: Cycles: Fully support WITH_CYCLES_LOGGING option

Sergey Sharybin noreply at git.blender.org
Wed Dec 31 21:32:50 CET 2014


Commit: bbf12722edb7d1cfbbdedd6757275ff386211fe0
Author: Sergey Sharybin
Date:   Sun Nov 16 01:12:19 2014 +0500
Branches: master
https://developer.blender.org/rBbbf12722edb7d1cfbbdedd6757275ff386211fe0

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.

===================================================================

M	intern/cycles/CMakeLists.txt
M	intern/cycles/app/CMakeLists.txt
M	intern/cycles/app/cycles_standalone.cpp
M	intern/cycles/blender/blender_logging.cpp
M	intern/cycles/cmake/external_libs.cmake
M	intern/cycles/util/util_logging.cpp
M	intern/cycles/util/util_logging.h

===================================================================

diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 56deb8d..06a6120 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -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).
diff --git a/intern/cycles/app/CMakeLists.txt b/intern/cycles/app/CMakeLists.txt
index 63cd0bc..d48ef51 100644
--- a/intern/cycles/app/CMakeLists.txt
+++ b/intern/cycles/app/CMakeLists.txt
@@ -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()
 
diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp
index 1950e0b..ce3fb96 100644
--- a/intern/cycles/app/cycles_standalone.cpp
+++ b/intern/cycles/app/cycles_standalone.cpp
@@ -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);
 
diff --git a/intern/cycles/blender/blender_logging.cpp b/intern/cycles/blender/blender_logging.cpp
index 24ec2b4..f4f8692 100644
--- a/intern/cycles/blender/blender_logging.cpp
+++ b/intern/cycles/blender/blender_logging.cpp
@@ -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);
 }
diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake
index 537de2e..465f2d2 100644
--- a/intern/cycles/cmake/external_libs.cmake
+++ b/intern/cycles/cmake/external_libs.cmake
@@ -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()
diff --git a/intern/cycles/util/util_logging.cpp b/intern/cycles/util/util_logging.cpp
index accd8c0..1aff647 100644
--- a/intern/cycles/util/util_logging.cpp
+++ b/intern/cycles/util/util_logging.cpp
@@ -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)
 {
diff --git a/intern/cycles/util/util_logging.h b/intern/cycles/util/util_logging.h
index 58c7aff..7fc42ac 100644
--- a/intern/cycles/util/util_logging.h
+++ b/intern/cycles/util/util_logging.h
@@ -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);




More information about the Bf-blender-cvs mailing list