diff --git a/.gitmodules b/.gitmodules index d40f165..3a8bfae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "test/gtest"] path = test/gtest url = https://github.com/google/googletest.git -[submodule "third_party/glog"] - path = third_party/glog - url = https://github.com/google/glog.git [submodule "tools/linter"] path = tools/linter url = https://github.com/slightech/linter.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 62c59a4..9305000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,9 +44,16 @@ message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") # packages -LIST(APPEND CMAKE_PREFIX_PATH third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") +find_package(Threads QUIET) + +macro(target_link_threads NAME) + if(THREADS_HAVE_PTHREAD_ARG) + target_compile_options(PUBLIC ${NAME} "-pthread") + endif() + if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(${NAME} "${CMAKE_THREAD_LIBS_INIT}") + endif() +endmacro() LIST(APPEND CMAKE_MODULE_PATH cmake) @@ -90,19 +97,28 @@ set(MYNTEYE_CMAKE_INSTALLDIR "${MYNTEYE_CMAKE_LIBDIR}/cmake/${MYNTEYE_NAME}") ## main -add_executable(main src/main.cc) -target_link_libraries(main glog::glog) -target_include_directories(main PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_BINARY_DIR}/include -) +if(WITH_GLOG) + add_executable(main src/main.cc) + target_link_libraries(main glog::glog) + target_include_directories(main PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/include + ) +endif() ## libmynteye +if(NOT WITH_GLOG) + set(__MINIGLOG_FLAGS "-Wno-unused-parameter -Wno-format -Wno-return-type") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${__MINIGLOG_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${__MINIGLOG_FLAGS}") + unset(__MINIGLOG_FLAGS) +endif() + set(MYNTEYE_PUBLIC_H ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/callbacks.h ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/global.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/glog_init.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/logger.h ${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.h ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/types.h ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/utils.h @@ -119,6 +135,11 @@ if(WITH_API) ${CMAKE_CURRENT_SOURCE_DIR}/src/api/processor/object.h ) endif() +if(NOT WITH_GLOG) + list(APPEND MYNTEYE_PUBLIC_H + ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/miniglog.h + ) +endif() if(OS_WIN) set(UVC_SRC src/uvc/uvc-wmf.cc) @@ -163,21 +184,25 @@ if(WITH_API) src/api/processor/points_processor.cc ) endif() +if(NOT WITH_GLOG) + list(APPEND MYNTEYE_SRCS src/public/miniglog.cc) +endif() -set(MYNTEYE_LINKLIBS - glog::glog - ${UVC_LIB} -) +set(MYNTEYE_LINKLIBS ${UVC_LIB}) if(WITH_API) list(APPEND MYNTEYE_LINKLIBS ${OpenCV_LIBS}) endif() if(WITH_BOOST_FILESYSTEM) list(APPEND MYNTEYE_LINKLIBS ${Boost_LIBRARIES}) endif() +if(WITH_GLOG) + list(APPEND MYNTEYE_LINKLIBS glog::glog) +endif() #message(STATUS "MYNTEYE_LINKLIBS: ${MYNTEYE_LINKLIBS}") add_library(${MYNTEYE_NAME} SHARED ${MYNTEYE_SRCS}) target_link_libraries(${MYNTEYE_NAME} ${MYNTEYE_LINKLIBS}) +target_link_threads(${MYNTEYE_NAME}) if(OS_WIN) target_compile_definitions(${MYNTEYE_NAME} diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 0000000..95cd94f --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,2 @@ +set noparent +filter=-build/c++11 diff --git a/Makefile b/Makefile index e8555fd..974617f 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ help: @echo " make opendoc open api doc (html)" @echo " make init init project" @echo " make build build project" - @echo " make test build test and run" @echo " make install install project" + @echo " make test build test and run" @echo " make samples build samples" @echo " make tools build tools" @echo " make ros build ros wrapper" @@ -41,7 +41,7 @@ help: .PHONY: help -all: test tools samples +all: test samples tools .PHONY: all @@ -70,12 +70,7 @@ cleandoc: submodules: @git submodule update --init -third_party: submodules - @$(call echo,Make $@) - @$(call echo,Make glog,33) - @$(call cmake_build,./third_party/glog/_build) - -.PHONY: submodules third_party +.PHONY: submodules # init @@ -87,7 +82,7 @@ init: submodules # build -build: third_party +build: submodules @$(call echo,Make $@) ifeq ($(HOST_OS),Win) @$(call cmake_build,./_build,..,-DCMAKE_INSTALL_PREFIX=$(MKFILE_DIR)/_install) diff --git a/cmake/DetectGLog.cmake b/cmake/DetectGLog.cmake new file mode 100644 index 0000000..daf42d7 --- /dev/null +++ b/cmake/DetectGLog.cmake @@ -0,0 +1,26 @@ +# Copyright 2018 Slightech Co., Ltd. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake) +cmake_include_guard() + +get_filename_component(__pro_dir ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) +LIST(APPEND CMAKE_PREFIX_PATH ${__pro_dir}/third_party/glog/_build) + +find_package(glog REQUIRED) +if(glog_FOUND) + add_definitions(-DWITH_GLOG) +endif() + +unset(__pro_dir) diff --git a/cmake/Option.cmake b/cmake/Option.cmake index f649391..98e9e49 100644 --- a/cmake/Option.cmake +++ b/cmake/Option.cmake @@ -28,6 +28,10 @@ option(WITH_DEVICE_INFO_REQUIRED "Build with device info required" ON) option(WITH_BOOST "Include Boost support" ON) +# How to install glog? +# Ubuntu: `sudo apt-get install libgoogle-glog-dev` +option(WITH_GLOG "Include glog support" OFF) + # packages @@ -59,6 +63,10 @@ if(NOT WITH_FILESYSTEM) endif() endif() +if(WITH_GLOG) + include(${CMAKE_CURRENT_LIST_DIR}/DetectGLog.cmake) +endif() + find_package(CUDA QUIET) # summary @@ -125,6 +133,16 @@ if(WITH_BOOST) endif() endif() +status(" WITH_GLOG: ${WITH_GLOG}") +if(WITH_GLOG) + if(glog_FOUND) + status(" glog: YES") + status(" glog_VERSION: ${glog_VERSION}") + else() + status(" glog: NO") + endif() +endif() + status("") status("Features:") status(" Filesystem: " diff --git a/doc/zh-Hans/guide_log.md b/doc/zh-Hans/guide_log.md index ef16629..7863260 100644 --- a/doc/zh-Hans/guide_log.md +++ b/doc/zh-Hans/guide_log.md @@ -1,6 +1,6 @@ # 日志 {#guide_log} -日志系统用的 `glog` ,通用配置在头文件 `glog_init.h` 里。 +日志系统用的 `glog` ,通用配置在头文件 `logger.h` 里。 * 日志文件会存储在当前工作目录, `make cleanlog` 可以清理。 -* 如果需要打开详细日志,请取消 `glog_init.h` 里注释的 `FLAGS_v = 2;` ,重新编译。 +* 如果需要打开详细日志,请取消 `logger.h` 里注释的 `FLAGS_v = 2;` ,重新编译。 diff --git a/include/mynteye/glog_init.h b/include/mynteye/logger.h similarity index 84% rename from include/mynteye/glog_init.h rename to include/mynteye/logger.h index e2ac989..65c8270 100644 --- a/include/mynteye/glog_init.h +++ b/include/mynteye/logger.h @@ -11,10 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MYNTEYE_GLOG_INIT_H_ // NOLINT -#define MYNTEYE_GLOG_INIT_H_ +#ifndef MYNTEYE_LOGGER_H_ +#define MYNTEYE_LOGGER_H_ #pragma once +#ifdef WITH_GLOG + #include /** Helper to init glog with args. */ @@ -43,7 +45,7 @@ struct glog_init { FLAGS_log_dir = "."; // Sets the maximum log file size (in MB). - FLAGS_max_log_size = 1024; + FLAGS_max_log_size = 8; // Sets whether to avoid logging to the disk if the disk is full. FLAGS_stop_logging_if_full_disk = true; @@ -62,4 +64,20 @@ struct glog_init { } }; -#endif // MYNTEYE_GLOG_INIT_H_ NOLINT +#else + +struct glog_init { + glog_init(int argc, char *argv[]) { + (void)argc; + (void)argv; + // Do nothing. + } +}; + +#define MAX_LOG_LEVEL google::INFO + +#include "mynteye/miniglog.h" + +#endif + +#endif // MYNTEYE_LOGGER_H_ diff --git a/include/mynteye/miniglog.h b/include/mynteye/miniglog.h new file mode 100644 index 0000000..0e0a2a2 --- /dev/null +++ b/include/mynteye/miniglog.h @@ -0,0 +1,535 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Google Inc. nor the names of its contributors may be +// used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Author: settinger@google.com (Scott Ettinger) +// mierle@gmail.com (Keir Mierle) +// +// Simplified Glog style logging with Android support. Supported macros in +// decreasing severity level per line: +// +// VLOG(2), VLOG(N) +// VLOG(1), +// LOG(INFO), VLOG(0), LG +// LOG(WARNING), +// LOG(ERROR), +// LOG(FATAL), +// +// With VLOG(n), the output is directed to one of the 5 Android log levels: +// +// 2 - Verbose +// 1 - Debug +// 0 - Info +// -1 - Warning +// -2 - Error +// -3 - Fatal +// +// Any logging of level 2 and above is directed to the Verbose level. All +// Android log output is tagged with the string "native". +// +// If the symbol ANDROID is not defined, all output goes to std::cerr. +// This allows code to be built on a different system for debug. +// +// Portions of this code are taken from the GLOG package. This code is only a +// small subset of the GLOG functionality. Notable differences from GLOG +// behavior include lack of support for displaying unprintable characters and +// lack of stack trace information upon failure of the CHECK macros. On +// non-Android systems, log output goes to std::cerr and is not written to a +// file. +// +// CHECK macros are defined to test for conditions within code. Any CHECK that +// fails will log the failure and terminate the application. +// e.g. CHECK_GE(3, 2) will pass while CHECK_GE(3, 4) will fail after logging +// "Check failed 3 >= 4". +// +// The following CHECK macros are defined: +// +// CHECK(condition) - fails if condition is false and logs condition. +// CHECK_NOTNULL(variable) - fails if the variable is NULL. +// +// The following binary check macros are also defined : +// +// Macro Operator equivalent +// -------------------- ------------------- +// CHECK_EQ(val1, val2) val1 == val2 +// CHECK_NE(val1, val2) val1 != val2 +// CHECK_GT(val1, val2) val1 > val2 +// CHECK_GE(val1, val2) val1 >= val2 +// CHECK_LT(val1, val2) val1 < val2 +// CHECK_LE(val1, val2) val1 <= val2 +// +// Debug only versions of all of the check macros are also defined. These +// macros generate no code in a release build, but avoid unused variable +// warnings / errors. +// +// To use the debug only versions, prepend a D to the normal check macros, e.g. +// DCHECK_EQ(a, b). +#ifndef MYNTEYE_MINIGLOG_H_ +#define MYNTEYE_MINIGLOG_H_ + +#ifdef ANDROID +# include +#else +#include +#include +#include +#endif // ANDROID + +#include +#include +#include +#include +#include +#include +#include +#include + +// For appropriate definition of CERES_EXPORT macro. +// Modified from ceres miniglog version [begin] ------------------------------- +//#include "ceres/internal/port.h" +//#include "ceres/internal/disable_warnings.h" +#define CERES_EXPORT +// Modified from ceres miniglog version [end] --------------------------------- + +// Log severity level constants. +const int FATAL = -3; +const int ERROR = -2; +const int WARNING = -1; +const int INFO = 0; + +// ------------------------- Glog compatibility ------------------------------ + +namespace google { + +typedef int LogSeverity; +const int INFO = ::INFO; +const int WARNING = ::WARNING; +const int ERROR = ::ERROR; +const int FATAL = ::FATAL; + +// Sink class used for integration with mock and test functions. If sinks are +// added, all log output is also sent to each sink through the send function. +// In this implementation, WaitTillSent() is called immediately after the send. +// This implementation is not thread safe. +class CERES_EXPORT LogSink { + public: + virtual ~LogSink() {} + virtual void send(LogSeverity severity, + const char* full_filename, + const char* base_filename, + int line, + const struct tm* tm_time, + const char* message, + size_t message_len) = 0; + virtual void WaitTillSent() = 0; +}; + +// Global set of log sinks. The actual object is defined in logging.cc. +extern CERES_EXPORT std::set log_sinks_global; + +inline void InitGoogleLogging(char *argv) { + // Do nothing; this is ignored. +} + +// Note: the Log sink functions are not thread safe. +inline void AddLogSink(LogSink *sink) { + // TODO(settinger): Add locks for thread safety. + log_sinks_global.insert(sink); +} +inline void RemoveLogSink(LogSink *sink) { + log_sinks_global.erase(sink); +} + +} // namespace google + +// ---------------------------- Logger Class -------------------------------- + +// Class created for each use of the logging macros. +// The logger acts as a stream and routes the final stream contents to the +// Android logcat output at the proper filter level. If ANDROID is not +// defined, output is directed to std::cerr. This class should not +// be directly instantiated in code, rather it should be invoked through the +// use of the log macros LG, LOG, or VLOG. +class CERES_EXPORT MessageLogger { + public: + MessageLogger(const char *file, int line, const char *tag, int severity) + : file_(file), line_(line), tag_(tag), severity_(severity) { + // Pre-pend the stream with the file and line number. + StripBasename(std::string(file), &filename_only_); + stream_ << filename_only_ << ":" << line << " "; + } + + // Output the contents of the stream to the proper channel on destruction. + ~MessageLogger() { + stream_ << "\n"; + +#ifdef ANDROID + static const int android_log_levels[] = { + ANDROID_LOG_FATAL, // LOG(FATAL) + ANDROID_LOG_ERROR, // LOG(ERROR) + ANDROID_LOG_WARN, // LOG(WARNING) + ANDROID_LOG_INFO, // LOG(INFO), LG, VLOG(0) + ANDROID_LOG_DEBUG, // VLOG(1) + ANDROID_LOG_VERBOSE, // VLOG(2) .. VLOG(N) + }; + + // Bound the logging level. + const int kMaxVerboseLevel = 2; + int android_level_index = std::min(std::max(FATAL, severity_), + kMaxVerboseLevel) - FATAL; + int android_log_level = android_log_levels[android_level_index]; + + // Output the log string the Android log at the appropriate level. + __android_log_write(android_log_level, tag_.c_str(), stream_.str().c_str()); + + // Indicate termination if needed. + if (severity_ == FATAL) { + __android_log_write(ANDROID_LOG_FATAL, + tag_.c_str(), + "terminating.\n"); + } +#else + // For Ubuntu/Mac/Windows + // If not building on Android, log all output to std::cerr. + // Get timestamp + timeval curTime; + gettimeofday(&curTime, NULL); + int milli = curTime.tv_usec / 1000; + char buffer [20]; + strftime(buffer, 80, "%m-%d %H:%M:%S", localtime(&curTime.tv_sec)); + char time_cstr[24] = ""; + sprintf(time_cstr, "%s:%d ", buffer, milli); + // Get pid & tid + char tid_cstr[24] = ""; + pid_t pid = getpid(); + pthread_t tid = pthread_self(); + sprintf(tid_cstr, "%d/%u ", pid, tid); + if (severity_ == FATAL) { + // Magenta color if fatal + std::cerr << "\033[1;35m"<< tid_cstr << time_cstr << SeverityLabelStr() << stream_.str() << "\033[0m"; + } else if (severity_ == ERROR) { + // Red color if error + std::cerr << "\033[1;31m"<< tid_cstr << time_cstr << SeverityLabelStr() << stream_.str() << "\033[0m"; + } else if (severity_ == WARNING) { + // Yellow color if warning + std::cerr << "\033[1;33m"<< tid_cstr << time_cstr << SeverityLabelStr() << stream_.str() << "\033[0m"; + } else { + std::cerr << tid_cstr << time_cstr << SeverityLabelStr() << stream_.str(); + } +#endif + + LogToSinks(severity_); + WaitForSinks(); + + // Android logging at level FATAL does not terminate execution, so abort() + // is still required to stop the program. + if (severity_ == FATAL) { + abort(); + } + } + + // Return the stream associated with the logger object. + std::stringstream &stream() { return stream_; } + + private: + void LogToSinks(int severity) { + time_t rawtime; + time (&rawtime); + + struct tm timeinfo; +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + // On Windows, use secure localtime_s not localtime. + localtime_s(&timeinfo, &rawtime); +#else + // On non-Windows systems, use threadsafe localtime_r not localtime. + localtime_r(&rawtime, &timeinfo); +#endif + + std::set::iterator iter; + // Send the log message to all sinks. + for (iter = google::log_sinks_global.begin(); + iter != google::log_sinks_global.end(); ++iter) { + (*iter)->send(severity, file_.c_str(), filename_only_.c_str(), line_, + &timeinfo, stream_.str().c_str(), stream_.str().size()); + } + } + + void WaitForSinks() { + // TODO(settinger): Add locks for thread safety. + std::set::iterator iter; + + // Call WaitTillSent() for all sinks. + for (iter = google::log_sinks_global.begin(); + iter != google::log_sinks_global.end(); ++iter) { + (*iter)->WaitTillSent(); + } + } + + void StripBasename(const std::string &full_path, std::string *filename) { + // TODO(settinger): Add support for OSs with different path separators. + const char kSeparator = '/'; + size_t pos = full_path.rfind(kSeparator); + if (pos != std::string::npos) { + *filename = full_path.substr(pos + 1, std::string::npos); + } else { + *filename = full_path; + } + } + + char SeverityLabel() { + switch (severity_) { + case FATAL: + return 'F'; + case ERROR: + return 'E'; + case WARNING: + return 'W'; + case INFO: + return 'I'; + default: + return 'V'; + } + } + + std::string SeverityLabelStr() { + switch (severity_) { + case FATAL: + return "FATAL "; + case ERROR: + return "ERROR "; + case WARNING: + return "WARNING "; + case INFO: + return "INFO "; + default: + return "VERBOSE "; + } + } + + std::string file_; + std::string filename_only_; + int line_; + std::string tag_; + std::stringstream stream_; + int severity_; +}; + +// ---------------------- Logging Macro definitions -------------------------- + +// This class is used to explicitly ignore values in the conditional +// logging macros. This avoids compiler warnings like "value computed +// is not used" and "statement has no effect". +class CERES_EXPORT LoggerVoidify { + public: + LoggerVoidify() { } + // This has to be an operator with a precedence lower than << but + // higher than ?: + void operator&(const std::ostream &s) { } +}; + +// Log only if condition is met. Otherwise evaluates to void. +#define LOG_IF(severity, condition) \ + !(condition) ? (void) 0 : LoggerVoidify() & \ + MessageLogger((char *)__FILE__, __LINE__, "native", severity).stream() + +// Log only if condition is NOT met. Otherwise evaluates to void. +#define LOG_IF_FALSE(severity, condition) LOG_IF(severity, !(condition)) + +// LG is a convenient shortcut for LOG(INFO). Its use is in new +// google3 code is discouraged and the following shortcut exists for +// backward compatibility with existing code. +#ifdef MAX_LOG_LEVEL +# define LOG(n) LOG_IF(n, n <= MAX_LOG_LEVEL) +# define VLOG(n) LOG_IF(n, n <= MAX_LOG_LEVEL) +# define LG LOG_IF(INFO, INFO <= MAX_LOG_LEVEL) +# define VLOG_IF(n, condition) LOG_IF(n, (n <= MAX_LOG_LEVEL) && condition) +#else +# define LOG(n) MessageLogger((char *)__FILE__, __LINE__, "native", n).stream() // NOLINT +# define VLOG(n) MessageLogger((char *)__FILE__, __LINE__, "native", n).stream() // NOLINT +# define LG MessageLogger((char *)__FILE__, __LINE__, "native", INFO).stream() // NOLINT +# define VLOG_IF(n, condition) LOG_IF(n, condition) +#endif + +// Currently, VLOG is always on for levels below MAX_LOG_LEVEL. +#ifndef MAX_LOG_LEVEL +# define VLOG_IS_ON(x) (1) +#else +# define VLOG_IS_ON(x) (x <= MAX_LOG_LEVEL) +#endif + +#ifndef NDEBUG +# define DLOG LOG +#else +# define DLOG(severity) true ? (void) 0 : LoggerVoidify() & \ + MessageLogger((char *)__FILE__, __LINE__, "native", severity).stream() +#endif + + +// Log a message and terminate. +template +void LogMessageFatal(const char *file, int line, const T &message) { + MessageLogger((char *)__FILE__, __LINE__, "native", FATAL).stream() + << message; +} + +// ---------------------------- CHECK macros --------------------------------- + +// Check for a given boolean condition. +#define CHECK(condition) LOG_IF_FALSE(FATAL, condition) \ + << "Check failed: " #condition " " + +#ifndef NDEBUG +// Debug only version of CHECK +# define DCHECK(condition) LOG_IF_FALSE(FATAL, condition) \ + << "Check failed: " #condition " " +#else +// Optimized version - generates no code. +# define DCHECK(condition) if (false) LOG_IF_FALSE(FATAL, condition) \ + << "Check failed: " #condition " " +#endif // NDEBUG + +// ------------------------- CHECK_OP macros --------------------------------- + +// Generic binary operator check macro. This should not be directly invoked, +// instead use the binary comparison macros defined below. +#define CHECK_OP(val1, val2, op) LOG_IF_FALSE(FATAL, ((val1) op (val2))) \ + << "Check failed: " #val1 " " #op " " #val2 " " + +// Check_op macro definitions +#define CHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) +#define CHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) +#define CHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) +#define CHECK_LT(val1, val2) CHECK_OP(val1, val2, <) +#define CHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) +#define CHECK_GT(val1, val2) CHECK_OP(val1, val2, >) + +// qiao.helloworld@gmail.com /tzu.ta.lin@gmail.com add +// Add logging macros which are missing in glog or are not accessible for +// whatever reason. +#define CHECK_NEAR(val1, val2, margin) \ + do { \ + CHECK_LE((val1), (val2)+(margin)); \ + CHECK_GE((val1), (val2)-(margin)); \ + } while (0) + +#ifndef NDEBUG +// Debug only versions of CHECK_OP macros. +# define DCHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) +# define DCHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) +# define DCHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) +# define DCHECK_LT(val1, val2) CHECK_OP(val1, val2, <) +# define DCHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) +# define DCHECK_GT(val1, val2) CHECK_OP(val1, val2, >) +// qiao.helloworld@gmail.com /tzu.ta.lin@gmail.com add +# define DCHECK_NEAR(val1, val2, margin) CHECK_NEAR(val1, val2, margin) +#else +// These versions generate no code in optimized mode. +# define DCHECK_EQ(val1, val2) if (false) CHECK_OP(val1, val2, ==) +# define DCHECK_NE(val1, val2) if (false) CHECK_OP(val1, val2, !=) +# define DCHECK_LE(val1, val2) if (false) CHECK_OP(val1, val2, <=) +# define DCHECK_LT(val1, val2) if (false) CHECK_OP(val1, val2, <) +# define DCHECK_GE(val1, val2) if (false) CHECK_OP(val1, val2, >=) +# define DCHECK_GT(val1, val2) if (false) CHECK_OP(val1, val2, >) +// qiao.helloworld@gmail.com /tzu.ta.lin@gmail.com add +# define DCHECK_NEAR(val1, val2, margin) if (false) CHECK_NEAR(val1, val2, margin) +#endif // NDEBUG + +// ---------------------------CHECK_NOTNULL macros --------------------------- + +// Helpers for CHECK_NOTNULL(). Two are necessary to support both raw pointers +// and smart pointers. +template +T& CheckNotNullCommon(const char *file, int line, const char *names, T& t) { + if (t == NULL) { + LogMessageFatal(file, line, std::string(names)); + } + return t; +} + +template +T* CheckNotNull(const char *file, int line, const char *names, T* t) { + return CheckNotNullCommon(file, line, names, t); +} + +template +T& CheckNotNull(const char *file, int line, const char *names, T& t) { + return CheckNotNullCommon(file, line, names, t); +} + +// Check that a pointer is not null. +#define CHECK_NOTNULL(val) \ + CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) + +#ifndef NDEBUG +// Debug only version of CHECK_NOTNULL +#define DCHECK_NOTNULL(val) \ + CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) +#else +// Optimized version - generates no code. +#define DCHECK_NOTNULL(val) if (false)\ + CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) +#endif // NDEBUG + +// Modified from ceres miniglog version [begin] ------------------------------- +//#include "ceres/internal/reenable_warnings.h" +// Modified from ceres miniglog version [end] --------------------------------- + + +// ---------------------------TRACE macros --------------------------- +// qiao.helloworld@gmail.com /tzu.ta.lin@gmail.com add +#define __FILENAME__ \ + (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + +#define DEXEC(fn) \ + do { \ + DLOG(INFO) << "[EXEC " << #fn << " START]"; \ + std::chrono::steady_clock::time_point begin = \ + std::chrono::steady_clock::now(); \ + fn; \ + std::chrono::steady_clock::time_point end = \ + std::chrono::steady_clock::now(); \ + DLOG(INFO) << "[EXEC " << #fn << " FINISHED in " \ + << std::chrono::duration_cast \ + (end - begin).count() << " ms]"; \ + } while (0); +// DEXEC(fn) +// +// Usage: +// DEXEC(foo()); +// -- output -- +// foo.cpp: 123 [EXEC foo() START] +// foo.cpp: 123 [EXEC foo() FINISHED in 456 ms] + +#define DTRACE DLOG(INFO) << "of [" << __func__ << "]"; +// Usage: +// void foo() { +// DTRACE +// } +// -- output -- +// foo.cpp: 123 of [void foo(void)] + +#endif // MYNTEYE_MINIGLOG_H_ diff --git a/mynteye-config.cmake.in b/mynteye-config.cmake.in index aaeb16a..3514b78 100644 --- a/mynteye-config.cmake.in +++ b/mynteye-config.cmake.in @@ -14,4 +14,7 @@ @PACKAGE_INIT@ +set(mynteye_WITH_API @WITH_API@) +set(mynteye_WITH_GLOG @WITH_GLOG@) + include("${CMAKE_CURRENT_LIST_DIR}/mynteye-targets.cmake") diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 2a0c4c6..4781867 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -47,10 +47,6 @@ message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") # packages -LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") - LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") diff --git a/samples/api/camera.cc b/samples/api/camera.cc index 5cddd85..1159d2d 100644 --- a/samples/api/camera.cc +++ b/samples/api/camera.cc @@ -13,7 +13,7 @@ // limitations under the License. #include -#include +#include "mynteye/logger.h" #include "mynteye/api.h" #include "mynteye/times.h" diff --git a/samples/api/get_depth_with_region.cc b/samples/api/get_depth_with_region.cc index 0bd075c..5a1091b 100644 --- a/samples/api/get_depth_with_region.cc +++ b/samples/api/get_depth_with_region.cc @@ -14,8 +14,6 @@ #include #include -#include - #include "mynteye/api.h" namespace { diff --git a/samples/device/camera.cc b/samples/device/camera.cc index bcd9695..00b1f0d 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -14,7 +14,7 @@ #include #include -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/samples/tutorials/control/auto_exposure.cc b/samples/tutorials/control/auto_exposure.cc index efe77e6..b1bacc1 100644 --- a/samples/tutorials/control/auto_exposure.cc +++ b/samples/tutorials/control/auto_exposure.cc @@ -13,9 +13,8 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" #include "util/cv_painter.h" diff --git a/samples/tutorials/control/framerate.cc b/samples/tutorials/control/framerate.cc index 1d05755..6a16a19 100644 --- a/samples/tutorials/control/framerate.cc +++ b/samples/tutorials/control/framerate.cc @@ -13,11 +13,10 @@ // limitations under the License. #include -#include - #include #include "mynteye/api.h" +#include "mynteye/logger.h" #include "mynteye/times.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/control/infrared.cc b/samples/tutorials/control/infrared.cc index 7ed6286..2a7ccd2 100644 --- a/samples/tutorials/control/infrared.cc +++ b/samples/tutorials/control/infrared.cc @@ -13,9 +13,8 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/control/manual_exposure.cc b/samples/tutorials/control/manual_exposure.cc index 38afa32..386188b 100644 --- a/samples/tutorials/control/manual_exposure.cc +++ b/samples/tutorials/control/manual_exposure.cc @@ -13,9 +13,8 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" #include "util/cv_painter.h" diff --git a/samples/tutorials/data/get_depth.cc b/samples/tutorials/data/get_depth.cc index 274c8ee..28ef244 100644 --- a/samples/tutorials/data/get_depth.cc +++ b/samples/tutorials/data/get_depth.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_device_info.cc b/samples/tutorials/data/get_device_info.cc index ee41348..d188fc6 100644 --- a/samples/tutorials/data/get_device_info.cc +++ b/samples/tutorials/data/get_device_info.cc @@ -11,9 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_disparity.cc b/samples/tutorials/data/get_disparity.cc index 5a9f798..aa02e42 100644 --- a/samples/tutorials/data/get_disparity.cc +++ b/samples/tutorials/data/get_disparity.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_from_callbacks.cc b/samples/tutorials/data/get_from_callbacks.cc index cb51875..d38b7ae 100644 --- a/samples/tutorials/data/get_from_callbacks.cc +++ b/samples/tutorials/data/get_from_callbacks.cc @@ -13,14 +13,13 @@ // limitations under the License. #include -#include - #include #include #include #include #include "mynteye/api.h" +#include "mynteye/logger.h" #include "util/cv_painter.h" diff --git a/samples/tutorials/data/get_img_params.cc b/samples/tutorials/data/get_img_params.cc index 5636120..7cfac2e 100644 --- a/samples/tutorials/data/get_img_params.cc +++ b/samples/tutorials/data/get_img_params.cc @@ -11,9 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_imu.cc b/samples/tutorials/data/get_imu.cc index 6ed0552..5cda4a4 100644 --- a/samples/tutorials/data/get_imu.cc +++ b/samples/tutorials/data/get_imu.cc @@ -13,9 +13,8 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" #include "util/cv_painter.h" diff --git a/samples/tutorials/data/get_imu_params.cc b/samples/tutorials/data/get_imu_params.cc index ddcfd49..1a307f8 100644 --- a/samples/tutorials/data/get_imu_params.cc +++ b/samples/tutorials/data/get_imu_params.cc @@ -11,9 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_points.cc b/samples/tutorials/data/get_points.cc index 828418d..66f3341 100644 --- a/samples/tutorials/data/get_points.cc +++ b/samples/tutorials/data/get_points.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" #include "util/pc_viewer.h" diff --git a/samples/tutorials/data/get_stereo.cc b/samples/tutorials/data/get_stereo.cc index a82a9e9..7899765 100644 --- a/samples/tutorials/data/get_stereo.cc +++ b/samples/tutorials/data/get_stereo.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_stereo_rectified.cc b/samples/tutorials/data/get_stereo_rectified.cc index 04c4eae..ea1a8b5 100644 --- a/samples/tutorials/data/get_stereo_rectified.cc +++ b/samples/tutorials/data/get_stereo_rectified.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/data/get_with_plugin.cc b/samples/tutorials/data/get_with_plugin.cc index a2201ba..dbaa574 100644 --- a/samples/tutorials/data/get_with_plugin.cc +++ b/samples/tutorials/data/get_with_plugin.cc @@ -13,8 +13,6 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/intermediate/get_all_device_info.cc b/samples/tutorials/intermediate/get_all_device_info.cc index b113c27..ec07c3a 100644 --- a/samples/tutorials/intermediate/get_all_device_info.cc +++ b/samples/tutorials/intermediate/get_all_device_info.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "mynteye/context.h" #include "mynteye/device.h" -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" MYNTEYE_USE_NAMESPACE diff --git a/samples/tutorials/intermediate/get_depth_and_points.cc b/samples/tutorials/intermediate/get_depth_and_points.cc index c137954..03391f5 100644 --- a/samples/tutorials/intermediate/get_depth_and_points.cc +++ b/samples/tutorials/intermediate/get_depth_and_points.cc @@ -14,8 +14,6 @@ #include #include -#include - #include "mynteye/api.h" #include "util/cv_painter.h" diff --git a/samples/tutorials/util/cv_painter.cc b/samples/tutorials/util/cv_painter.cc index c0c6f6a..eaa7d8a 100644 --- a/samples/tutorials/util/cv_painter.cc +++ b/samples/tutorials/util/cv_painter.cc @@ -13,8 +13,6 @@ // limitations under the License. #include "util/cv_painter.h" -#include - #include #include @@ -22,6 +20,7 @@ #include #include +#include "mynteye/logger.h" #include "mynteye/utils.h" #define FONT_FACE cv::FONT_HERSHEY_PLAIN diff --git a/samples/tutorials/util/pc_viewer.cc b/samples/tutorials/util/pc_viewer.cc index 2fb7394..bec96dc 100644 --- a/samples/tutorials/util/pc_viewer.cc +++ b/samples/tutorials/util/pc_viewer.cc @@ -13,12 +13,12 @@ // limitations under the License. #include "util/pc_viewer.h" -#include - // #include #include +#include "mynteye/logger.h" + std::shared_ptr CustomColorVis( pcl::PointCloud::ConstPtr pc) { // -------------------------------------------- diff --git a/samples/uvc/camera.cc b/samples/uvc/camera.cc index ac20e03..4b36b44 100644 --- a/samples/uvc/camera.cc +++ b/samples/uvc/camera.cc @@ -20,7 +20,7 @@ #include #include -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/mynteye.h" #include "mynteye/types.h" #include "uvc/uvc.h" diff --git a/scripts/init.sh b/scripts/init.sh index c034f3e..ce193c2 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -14,181 +14,29 @@ # limitations under the License. # _VERBOSE_=1 +# _INIT_LINTER_=1 # _FORCE_INSRALL_=1 BASE_DIR=$(cd "$(dirname "$0")" && pwd) -source "$BASE_DIR/common/echo.sh" -source "$BASE_DIR/common/detect.sh" -source "$BASE_DIR/common/host.sh" - -PYTHON="python" -if [ "$HOST_OS" = "Win" ]; then - if ! _detect_cmd $PYTHON; then - PYTHON="python2" # try python2 on MSYS - fi -fi - -_detect $PYTHON 1 - -PYTHON_FOUND="${PYTHON}_FOUND" -if [ -z "${!PYTHON_FOUND}" ]; then - _echo_en "$PYTHON not found" -fi - -if [ "$HOST_OS" = "Linux" ]; then - _detect_install() { - _detect_cmd "$1" || [ $(dpkg-query -W -f='${Status}' "$1" 2> /dev/null \ - | grep -c "ok installed") -gt 0 ] - } -elif [ "$HOST_OS" = "Mac" ]; then - _detect_install() { - _detect_cmd "$1" || brew ls --versions "$1" > /dev/null - } -else - _detect_install() { - _detect_cmd "$1" - } -fi - -_install_deps() { - _cmd="$1"; shift; _deps_all=($@) - _echo "Install cmd: $_cmd" - _echo "Install deps: ${_deps_all[*]}" - if [ -n "${_FORCE_INSRALL_}" ]; then - _echo_d "$_cmd ${_deps_all[*]}" - $_cmd ${_deps_all[@]} - return - fi - _deps=() - for _dep in "${_deps_all[@]}"; do - _detect_install $_dep || _deps+=($_dep) - done - if [ ${#_deps[@]} -eq 0 ]; then - _echo_i "All deps already exist" - else - _echo_d "$_cmd ${_deps[*]} (not exists)" - $_cmd ${_deps[@]} - fi -} +source "$BASE_DIR/init_tools.sh" ## deps _echo_s "Init deps" if [ "$HOST_OS" = "Linux" ]; then - # detect apt-get - _detect apt-get - # apt-get install - _install_deps "sudo apt-get install" build-essential curl cmake git clang-format - _install_deps "sudo apt-get install" libv4l-dev - if ! _detect_cmd clang-format; then - # on Ubuntu 14.04, apt-cache search clang-format - _install_deps "sudo apt-get install" clang-format-3.9 - sudo ln -sf clang-format-3.9 /usr/bin/clang-format - sudo ln -sf clang-format-diff-3.9 /usr/bin/clang-format-diff - fi - # sudo - SUDO="sudo" + _install_deps "$SUDO apt-get install" libv4l-dev elif [ "$HOST_OS" = "Mac" ]; then - # detect brew - if ! _detect_cmd brew; then - _echo_sn "Install brew" - _detect curl - _detect ruby - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - fi - # brew install - _install_deps "brew install" curl cmake git clang-format - # link clang-format-diff (if not compatible with Python 3, fix it by yourself) - [ -f "/usr/local/bin/clang-format-diff" ] || \ - ln -s /usr/local/share/clang/clang-format-diff.py /usr/local/bin/clang-format-diff _install_deps "brew install" libuvc elif [ "$HOST_OS" = "Win" ]; then - # detect pacman on MSYS - _detect pacman - # pacman install (common) - _install_deps "pacman -S" curl git clang-format - if [ "$HOST_NAME" = "MINGW" ]; then - # pacman install (MINGW) - _deps=() - if [ "$HOST_ARCH" = "x64" ]; then - _deps+=(mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake) - elif [ "$HOST_ARCH" = "x86" ]; then - _deps+=(mingw-w64-i686-toolchain mingw-w64-i686-cmake) - else - _echo_e "Unknown host arch :(" - exit 1 - fi - if ! [ ${#_deps[@]} -eq 0 ]; then - _echo_d "pacman -S ${_deps[*]}" - pacman -S ${_deps[@]} - fi - else - # detect cmake on MSYS - _detect cmake - fi - # update - # pacman -Syu - # search - # pacman -Ss make - # autoremove - # pacman -Qtdq | pacman -Rs - + # _install_deps "pacman -S" ? + _echo else # unexpected _echo_e "Unknown host os :(" exit 1 fi -## pip - -# detect pip -if ! _detect_cmd pip; then - if [ -n "${!PYTHON_FOUND}" ]; then - _echo_sn "Install pip" - [ -f "get-pip.py" ] || curl -O https://bootstrap.pypa.io/get-pip.py - $SUDO $PYTHON get-pip.py - else - _echo_en "Skipped install pip, as $PYTHON not found" - fi -fi -# pip install -if _detect_cmd pip; then - _echo_d "pip install --upgrade autopep8 cpplint pylint requests" - $SUDO pip install --upgrade autopep8 cpplint pylint requests -else - _echo_en "Skipped pip install packages, as pip not found" -fi - -## realpath - -# detect realpath -if ! _detect_cmd realpath; then - _echo_sn "Install realpath" - if [ "$HOST_OS" = "Linux" ]; then - # How to install realpath on Ubuntu 14.04 - # https://www.howtoinstall.co/en/ubuntu/trusty/realpath - sudo apt-get install coreutils realpath - elif [ "$HOST_OS" = "Mac" ]; then - brew install coreutils - elif [ "$HOST_OS" = "Win" ]; then - pacman -S coreutils - else # unexpected - _echo_e "Unknown host os :(" - exit 1 - fi -fi - -ROOT_DIR=$(realpath "$BASE_DIR/..") - -## init - -if [ -n "${!PYTHON_FOUND}" ]; then - _echo_s "Init git hooks" - $PYTHON "$ROOT_DIR/tools/linter/init-git-hooks.py" -else - _echo_en "Skipped init git hooks, as $PYTHON not found" -fi - ## cmake version _echo_s "Expect cmake version >= 3.0" diff --git a/scripts/init_tools.sh b/scripts/init_tools.sh new file mode 100644 index 0000000..232b536 --- /dev/null +++ b/scripts/init_tools.sh @@ -0,0 +1,214 @@ +#!/usr/bin/env bash +# Copyright 2018 Slightech Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_INIT_BUILD_=1 +# _INIT_LINTER_=1 +# _FORCE_INSRALL_=1 + +BASE_DIR=$(cd "$(dirname "$0")" && pwd) + +source "$BASE_DIR/common/echo.sh" +source "$BASE_DIR/common/detect.sh" +source "$BASE_DIR/common/host.sh" + +## functions + +if [ "$HOST_OS" = "Linux" ]; then + _detect_install() { + _detect_cmd "$1" || [ $(dpkg-query -W -f='${Status}' "$1" 2> /dev/null \ + | grep -c "ok installed") -gt 0 ] + } +elif [ "$HOST_OS" = "Mac" ]; then + _detect_install() { + _detect_cmd "$1" || brew ls --versions "$1" > /dev/null + } +else + _detect_install() { + _detect_cmd "$1" + } +fi + +_install_deps() { + _cmd="$1"; shift; _deps_all=($@) + _echo "Install cmd: $_cmd" + _echo "Install deps: ${_deps_all[*]}" + if [ -n "${_FORCE_INSRALL_}" ]; then + _echo_d "$_cmd ${_deps_all[*]}" + $_cmd ${_deps_all[@]} + return + fi + _deps=() + for _dep in "${_deps_all[@]}"; do + _detect_install $_dep || _deps+=($_dep) + done + if [ ${#_deps[@]} -eq 0 ]; then + _echo_i "All deps already exist" + else + _echo_d "$_cmd ${_deps[*]} (not exists)" + $_cmd ${_deps[@]} + fi +} + +## init tools + +_echo_s "Init tools" + +if [ "$HOST_OS" = "Linux" ]; then + # sudo + SUDO="sudo" + # detect apt-get + _detect apt-get + # apt-get install + if [ -n "${_INIT_BUILD_}" ]; then + _install_deps "$SUDO apt-get install" build-essential curl cmake git make + fi + if [ -n "${_INIT_LINTER_}" ]; then + _install_deps "$SUDO apt-get install" clang-format + if ! _detect_cmd clang-format; then + # on Ubuntu 14.04, apt-cache search clang-format + _install_deps "$SUDO apt-get install" clang-format-3.9 + $SUDO ln -sf clang-format-3.9 /usr/bin/clang-format + $SUDO ln -sf clang-format-diff-3.9 /usr/bin/clang-format-diff + fi + fi +elif [ "$HOST_OS" = "Mac" ]; then + # detect brew + if ! _detect_cmd brew; then + _echo_sn "Install brew" + _detect curl + _detect ruby + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + fi + # brew install + if [ -n "${_INIT_BUILD_}" ]; then + _install_deps "brew install" curl cmake git make + fi + if [ -n "${_INIT_LINTER_}" ]; then + _install_deps "brew install" clang-format + # link clang-format-diff (if not compatible with Python 3, fix it by yourself) + [ -f "/usr/local/bin/clang-format-diff" ] || \ + ln -s /usr/local/share/clang/clang-format-diff.py /usr/local/bin/clang-format-diff + fi +elif [ "$HOST_OS" = "Win" ]; then + # detect pacman on MSYS + _detect pacman + # pacman install + if [ -n "${_INIT_BUILD_}" ]; then + _install_deps "pacman -S" curl git make + if [ "$HOST_NAME" = "MINGW" ]; then + # MINGW: cmake + _deps=() + if [ "$HOST_ARCH" = "x64" ]; then + _deps+=(mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake) + elif [ "$HOST_ARCH" = "x86" ]; then + _deps+=(mingw-w64-i686-toolchain mingw-w64-i686-cmake) + else + _echo_e "Unknown host arch :(" + exit 1 + fi + if ! [ ${#_deps[@]} -eq 0 ]; then + _install_deps "pacman -S" ${_deps[@]} + fi + else + # Install CMake for Windows + # https://cmake.org/ + _detect cmake + fi + fi + if [ -n "${_INIT_LINTER_}" ]; then + _install_deps "pacman -S" clang-format + fi + # update + # pacman -Syu + # search + # pacman -Ss make + # autoremove + # pacman -Qtdq | pacman -Rs - +else # unexpected + _echo_e "Unknown host os :(" + exit 1 +fi + +## init linter - optional + +if [ -n "${_INIT_LINTER_}" ]; then + +# python + +PYTHON="python" +if [ "$HOST_OS" = "Win" ]; then + if ! _detect_cmd $PYTHON; then + PYTHON="python2" # try python2 on MSYS + fi +fi + +_detect $PYTHON 1 + +PYTHON_FOUND="${PYTHON}_FOUND" +if [ -z "${!PYTHON_FOUND}" ]; then + _echo_en "$PYTHON not found" +fi + +# pip + +# detect pip +if ! _detect_cmd pip; then + if [ -n "${!PYTHON_FOUND}" ]; then + _echo_sn "Install pip" + [ -f "get-pip.py" ] || curl -O https://bootstrap.pypa.io/get-pip.py + $SUDO $PYTHON get-pip.py + else + _echo_en "Skipped install pip, as $PYTHON not found" + fi +fi +# pip install +if _detect_cmd pip; then + _echo_d "pip install --upgrade autopep8 cpplint pylint requests" + $SUDO pip install --upgrade autopep8 cpplint pylint requests +else + _echo_en "Skipped pip install packages, as pip not found" +fi + +# realpath + +# detect realpath +if ! _detect_cmd realpath; then + _echo_sn "Install realpath" + if [ "$HOST_OS" = "Linux" ]; then + # How to install realpath on Ubuntu 14.04 + # https://www.howtoinstall.co/en/ubuntu/trusty/realpath + $SUDO apt-get install coreutils realpath + elif [ "$HOST_OS" = "Mac" ]; then + brew install coreutils + elif [ "$HOST_OS" = "Win" ]; then + pacman -S coreutils + else # unexpected + _echo_e "Unknown host os :(" + exit 1 + fi +fi + +ROOT_DIR=$(realpath "$BASE_DIR/..") + +# init git hooks + +if [ -n "${!PYTHON_FOUND}" ]; then + _echo_s "Init git hooks" + $PYTHON "$ROOT_DIR/tools/linter/init-git-hooks.py" +else + _echo_en "Skipped init git hooks, as $PYTHON not found" +fi + +fi # _INIT_LINTER_ diff --git a/src/api/api.cc b/src/api/api.cc index ddf443a..8fb98bb 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -18,12 +18,10 @@ #include #endif -#include - #include #include -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/utils.h" #include "api/plugin.h" diff --git a/src/api/processor/depth_processor.cc b/src/api/processor/depth_processor.cc index 73769de..433e47d 100644 --- a/src/api/processor/depth_processor.cc +++ b/src/api/processor/depth_processor.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "api/processor/depth_processor.h" -#include +#include "mynteye/logger.h" #include diff --git a/src/api/processor/disparity_normalized_processor.cc b/src/api/processor/disparity_normalized_processor.cc index 0ce2a9a..6c24c6b 100644 --- a/src/api/processor/disparity_normalized_processor.cc +++ b/src/api/processor/disparity_normalized_processor.cc @@ -15,10 +15,10 @@ #include -#include - #include +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE const char DisparityNormalizedProcessor::NAME[] = diff --git a/src/api/processor/disparity_processor.cc b/src/api/processor/disparity_processor.cc index dbb5ab3..041e246 100644 --- a/src/api/processor/disparity_processor.cc +++ b/src/api/processor/disparity_processor.cc @@ -15,10 +15,10 @@ #include -#include - #include +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE const char DisparityProcessor::NAME[] = "DisparityProcessor"; diff --git a/src/api/processor/points_processor.cc b/src/api/processor/points_processor.cc index 0d594b1..02a70b2 100644 --- a/src/api/processor/points_processor.cc +++ b/src/api/processor/points_processor.cc @@ -15,10 +15,10 @@ #include -#include - #include +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE const char PointsProcessor::NAME[] = "PointsProcessor"; diff --git a/src/api/processor/processor.cc b/src/api/processor/processor.cc index 8ba3bca..c0d45ab 100644 --- a/src/api/processor/processor.cc +++ b/src/api/processor/processor.cc @@ -13,11 +13,11 @@ // limitations under the License. #include "api/processor/processor.h" -#include - #include #include +#include "mynteye/logger.h" + #include "internal/strings.h" #include "internal/times.h" diff --git a/src/api/processor/rectify_processor.cc b/src/api/processor/rectify_processor.cc index 31ce62c..9a45b0f 100644 --- a/src/api/processor/rectify_processor.cc +++ b/src/api/processor/rectify_processor.cc @@ -16,10 +16,10 @@ #include #include -#include - #include +#include "mynteye/logger.h" + #include "device/device.h" MYNTEYE_BEGIN_NAMESPACE diff --git a/src/api/synthetic.cc b/src/api/synthetic.cc index 3c5a194..a1a3730 100644 --- a/src/api/synthetic.cc +++ b/src/api/synthetic.cc @@ -13,12 +13,12 @@ // limitations under the License. #include "api/synthetic.h" -#include - #include #include #include +#include "mynteye/logger.h" + #include "api/plugin.h" #include "api/processor/depth_processor.h" #include "api/processor/disparity_normalized_processor.h" diff --git a/src/device/context.cc b/src/device/context.cc index e5c82c7..ef4f1ef 100644 --- a/src/device/context.cc +++ b/src/device/context.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "device/context.h" -#include +#include "mynteye/logger.h" #include "device/device.h" #include "uvc/uvc.h" diff --git a/src/device/device.cc b/src/device/device.cc index cc4d2b8..2d16d9d 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -13,13 +13,13 @@ // limitations under the License. #include "device/device.h" -#include - #include #include #include #include +#include "mynteye/logger.h" + #include "device/device_s.h" #include "internal/async_callback.h" #include "internal/channels.h" diff --git a/src/device/device_s.cc b/src/device/device_s.cc index fdffe93..377453d 100644 --- a/src/device/device_s.cc +++ b/src/device/device_s.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "device/device_s.h" -#include +#include "mynteye/logger.h" #include "internal/motions.h" diff --git a/src/internal/async_callback_impl.h b/src/internal/async_callback_impl.h index 3c502b3..cfffc0d 100644 --- a/src/internal/async_callback_impl.h +++ b/src/internal/async_callback_impl.h @@ -15,11 +15,11 @@ #define MYNTEYE_INTERNAL_ASYNC_CALLBACK_IMPL_H_ #pragma once -#include - #include #include +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE template diff --git a/src/internal/channels.cc b/src/internal/channels.cc index e8eb253..679fe61 100644 --- a/src/internal/channels.cc +++ b/src/internal/channels.cc @@ -13,8 +13,6 @@ // limitations under the License. #include "internal/channels.h" -#include - #include #include #include @@ -22,6 +20,8 @@ #include #include +#include "mynteye/logger.h" + #include "internal/strings.h" #include "internal/times.h" diff --git a/src/internal/dl.cc b/src/internal/dl.cc index 8ba22b7..2de8150 100644 --- a/src/internal/dl.cc +++ b/src/internal/dl.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "internal/dl.h" -#include +#include "mynteye/logger.h" MYNTEYE_BEGIN_NAMESPACE diff --git a/src/internal/files.cc b/src/internal/files.cc index 7d54020..556d5c9 100644 --- a/src/internal/files.cc +++ b/src/internal/files.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "internal/files.h" -#include +#include "mynteye/logger.h" #if defined(OS_WIN) && !defined(OS_MINGW) && !defined(OS_CYGWIN) #include diff --git a/src/internal/motions.cc b/src/internal/motions.cc index 7183c6a..27d3c67 100644 --- a/src/internal/motions.cc +++ b/src/internal/motions.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "internal/motions.h" -#include +#include "mynteye/logger.h" #include "internal/channels.h" diff --git a/src/internal/streams.cc b/src/internal/streams.cc index 97ae970..1f9fe64 100644 --- a/src/internal/streams.cc +++ b/src/internal/streams.cc @@ -13,13 +13,13 @@ // limitations under the License. #include "internal/streams.h" -#include - #include #include #include #include +#include "mynteye/logger.h" + #include "internal/types.h" MYNTEYE_BEGIN_NAMESPACE diff --git a/src/internal/types.cc b/src/internal/types.cc index c53ff0d..c5aa1e7 100644 --- a/src/internal/types.cc +++ b/src/internal/types.cc @@ -13,11 +13,11 @@ // limitations under the License. #include "internal/types.h" -#include - #include #include -#include +#include + +#include "mynteye/logger.h" MYNTEYE_BEGIN_NAMESPACE diff --git a/src/public/miniglog.cc b/src/public/miniglog.cc new file mode 100644 index 0000000..23a2c32 --- /dev/null +++ b/src/public/miniglog.cc @@ -0,0 +1,39 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2015 Google Inc. All rights reserved. +// http://ceres-solver.org/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Google Inc. nor the names of its contributors may be +// used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Author: keir@google.com (Keir Mierle) + +#include "mynteye/miniglog.h" + +namespace google { + +// This is the set of log sinks. This must be in a separate library to ensure +// that there is only one instance of this across the entire program. +std::set log_sinks_global; + +} // namespace google diff --git a/src/public/miniglog.readme b/src/public/miniglog.readme new file mode 100644 index 0000000..9ce8c89 --- /dev/null +++ b/src/public/miniglog.readme @@ -0,0 +1 @@ +miniglog: https://github.com/tzutalin/miniglog diff --git a/src/public/types.cc b/src/public/types.cc index 296c8a4..d8b99da 100644 --- a/src/public/types.cc +++ b/src/public/types.cc @@ -13,11 +13,11 @@ // limitations under the License. #include "mynteye/types.h" -#include - #include #include +#include "mynteye/logger.h" + #define FULL_PRECISION \ std::fixed << std::setprecision(std::numeric_limits::max_digits10) diff --git a/src/public/utils.cc b/src/public/utils.cc index 4fc9202..36ba8ff 100644 --- a/src/public/utils.cc +++ b/src/public/utils.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "mynteye/utils.h" -#include +#include "mynteye/logger.h" #include "device/context.h" #include "device/device.h" diff --git a/src/uvc/uvc-libuvc.cc b/src/uvc/uvc-libuvc.cc index 1b260d7..f2a9b92 100644 --- a/src/uvc/uvc-libuvc.cc +++ b/src/uvc/uvc-libuvc.cc @@ -13,9 +13,10 @@ // limitations under the License. #include "uvc/uvc.h" // NOLINT -#include #include +#include "mynteye/logger.h" + // #define ENABLE_DEBUG_SPAM MYNTEYE_BEGIN_NAMESPACE diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index 06fc8fc..292804c 100755 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -16,6 +16,9 @@ #include #include #include +#include +#include + #include #include #include @@ -25,13 +28,14 @@ #include #include -#include - #include #include +#include #include #include +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE namespace uvc { diff --git a/src/uvc/uvc-wmf.cc b/src/uvc/uvc-wmf.cc index 13f7f36..8e8d9c3 100644 --- a/src/uvc/uvc-wmf.cc +++ b/src/uvc/uvc-wmf.cc @@ -53,7 +53,7 @@ #include -#include +#include "mynteye/logger.h" #define VLOG_INFO VLOG(2) // #define VLOG_INFO LOG(INFO) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 11c68cd..18be45b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -57,16 +57,16 @@ message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") # packages -LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") - LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") include(${PRO_DIR}/cmake/DetectOpenCV.cmake) +if(mynteye_WITH_GLOG) + include(${PRO_DIR}/cmake/DetectGLog.cmake) +endif() + #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) ## gtest diff --git a/test/gtest_main.cc b/test/gtest_main.cc index a0e1685..edca54b 100644 --- a/test/gtest_main.cc +++ b/test/gtest_main.cc @@ -15,7 +15,7 @@ #include "gtest/gtest.h" -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" int main(int argc, char **argv) { glog_init _(argc, argv); diff --git a/third_party/glog b/third_party/glog deleted file mode 160000 index 8d7a107..0000000 --- a/third_party/glog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8d7a107d68c127f3f494bb7807b796c8c5a97a82 diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a617541..4d57c04 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -43,16 +43,16 @@ message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") # packages -LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") - LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") include(${PRO_DIR}/cmake/DetectOpenCV.cmake) +if(mynteye_WITH_GLOG) + include(${PRO_DIR}/cmake/DetectGLog.cmake) +endif() + #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) # targets diff --git a/tools/dataset/dataset.cc b/tools/dataset/dataset.cc index d156c37..165473f 100644 --- a/tools/dataset/dataset.cc +++ b/tools/dataset/dataset.cc @@ -19,14 +19,13 @@ #include #endif -#include - #include #include #include #include #include "mynteye/files.h" +#include "mynteye/logger.h" #define FULL_PRECISION \ std::fixed << std::setprecision(std::numeric_limits::max_digits10) diff --git a/tools/dataset/record.cc b/tools/dataset/record.cc index e3de362..dedf851 100644 --- a/tools/dataset/record.cc +++ b/tools/dataset/record.cc @@ -14,7 +14,7 @@ #include #include -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/tools/writer/device_info_writer.cc b/tools/writer/device_info_writer.cc index 1625b7a..6619a55 100644 --- a/tools/writer/device_info_writer.cc +++ b/tools/writer/device_info_writer.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/tools/writer/device_writer.cc b/tools/writer/device_writer.cc index 05a4e46..4a61001 100644 --- a/tools/writer/device_writer.cc +++ b/tools/writer/device_writer.cc @@ -15,12 +15,11 @@ #include -#include - #include #include "mynteye/device.h" #include "mynteye/files.h" +#include "mynteye/logger.h" MYNTEYE_BEGIN_NAMESPACE diff --git a/tools/writer/img_params_writer.cc b/tools/writer/img_params_writer.cc index 77647a5..02950e9 100644 --- a/tools/writer/img_params_writer.cc +++ b/tools/writer/img_params_writer.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/tools/writer/imu_params_writer.cc b/tools/writer/imu_params_writer.cc index 9f2034b..a60c3fe 100644 --- a/tools/writer/imu_params_writer.cc +++ b/tools/writer/imu_params_writer.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/tools/writer/save_all_infos.cc b/tools/writer/save_all_infos.cc index a4ff051..c67b5d4 100644 --- a/tools/writer/save_all_infos.cc +++ b/tools/writer/save_all_infos.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/device.h" #include "mynteye/utils.h" diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index 4cecbff..b6b3ab9 100644 --- a/wrappers/python/CMakeLists.txt +++ b/wrappers/python/CMakeLists.txt @@ -47,14 +47,6 @@ if(OS_MAC) endif() endif() -# options - -include(${PRO_DIR}/cmake/Option.cmake) - -if(NOT WITH_API) - message(FATAL_ERROR "Must with API layer :(") -endif() - # flags if(OS_WIN) @@ -77,14 +69,22 @@ message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}") # packages -LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") - LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") +if(NOT mynteye_WITH_API) + message(FATAL_ERROR "Must with API layer :(") +endif() + +include(${PRO_DIR}/cmake/DetectOpenCV.cmake) + +if(mynteye_WITH_GLOG) + include(${PRO_DIR}/cmake/DetectGLog.cmake) +endif() + +## boost & python + if(CMAKE_VERSION VERSION_LESS "3.10" OR CMAKE_VERSION VERSION_EQUAL "3.10") find_package(Boost ${BOOST_FIND_VERSION} REQUIRED COMPONENTS python${PYTHON_BOOST_CODE} # numpy${PYTHON_BOOST_CODE} @@ -103,8 +103,6 @@ message(STATUS "Found PythonLibs: ${PYTHONLIBS_VERSION_STRING}") message(STATUS " PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}") message(STATUS " PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}") -include(${PRO_DIR}/cmake/DetectOpenCV.cmake) - #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) # targets diff --git a/wrappers/python/src/mynteye_py.cc b/wrappers/python/src/mynteye_py.cc index 8107f55..ad7fbe9 100644 --- a/wrappers/python/src/mynteye_py.cc +++ b/wrappers/python/src/mynteye_py.cc @@ -26,7 +26,7 @@ #include #include "mynteye/api.h" -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" #include "mynteye/utils.h" #include "array_indexing_suite.hpp" @@ -451,7 +451,7 @@ BOOST_PYTHON_MODULE(mynteye_py) { bp::register_ptr_to_python>(); - // glog_init.h - glog_init + // logger.h - glog_init bp::class_("glog_init", bp::no_init) .def("create", &glog_init_create) diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt index 83ffce1..ae85a88 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt @@ -56,9 +56,6 @@ checkPackage("sensor_msgs" "") checkPackage("std_msgs" "") checkPackage("tf" "") -find_package(OpenCV REQUIRED) -message(STATUS "Found OpenCV: ${OpenCV_VERSION}") - ## messages add_message_files( @@ -82,14 +79,20 @@ catkin_package( get_filename_component(SDK_DIR "${PROJECT_SOURCE_DIR}/../../../.." ABSOLUTE) -LIST(APPEND CMAKE_PREFIX_PATH ${SDK_DIR}/third_party/glog/_build) -find_package(glog REQUIRED) -message(STATUS "Found glog: ${glog_VERSION}") - LIST(APPEND CMAKE_PREFIX_PATH ${SDK_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") +if(NOT mynteye_WITH_API) + message(FATAL_ERROR "Must with API layer :(") +endif() + +include(${SDK_DIR}/cmake/DetectOpenCV.cmake) + +if(mynteye_WITH_GLOG) + include(${SDK_DIR}/cmake/DetectGLog.cmake) +endif() + # targets add_compile_options(-std=c++11) diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_node.cc b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_node.cc index 5a03045..6e12566 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_node.cc +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_node.cc @@ -14,7 +14,7 @@ #include #include -#include "mynteye/glog_init.h" +#include "mynteye/logger.h" int main(int argc, char *argv[]) { glog_init _(argc, argv); diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc index fccda6d..5e6e2de 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc @@ -28,8 +28,6 @@ #include #include -#include - #define _USE_MATH_DEFINES #include #include @@ -38,6 +36,7 @@ #include "mynteye/api.h" #include "mynteye/context.h" #include "mynteye/device.h" +#include "mynteye/logger.h" #define FULL_PRECISION \ std::fixed << std::setprecision(std::numeric_limits::max_digits10)