diff --git a/CMakeLists.txt b/CMakeLists.txt index 5299cb0..4b25354 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() if(WITH_API) include(cmake/DetectOpenCV.cmake) @@ -106,20 +113,28 @@ set(MYNTEYE_CMAKE_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib") 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 @@ -136,6 +151,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) @@ -180,21 +200,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}) +option(WITH_GLOG "Include glog support" OFF) 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 5c65f55..3091003 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,10 @@ help: @echo " make apidoc make api doc" @echo " make opendoc open api doc (html)" @echo " make init init project" + @echo " make 3rdparty build 3rdparty: glog" @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" @@ -35,7 +36,7 @@ help: .PHONY: help -all: test tools samples +all: test samples tools .PHONY: all @@ -66,7 +67,9 @@ third_party: submodules @$(call echo,Make glog,33) @$(call cmake_build,./third_party/glog/_build) -.PHONY: submodules third_party +3rdparty: third_party + +.PHONY: submodules third_party 3rdparty # init @@ -78,7 +81,7 @@ init: submodules # build -build: third_party +build: submodules @$(call echo,Make $@) @$(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 ac68eac..a169987 100644 --- a/cmake/Option.cmake +++ b/cmake/Option.cmake @@ -16,3 +16,5 @@ option(WITH_API "Build with API layer, need OpenCV" ON) message(STATUS "Options:") message(STATUS " WITH_API: ${WITH_API}") + +option(WITH_GLOG "Include glog support" OFF) diff --git a/config/SN07C624160009071F/device.info b/config/SN07C624160009071F/device.info new file mode 100644 index 0000000..1a515df --- /dev/null +++ b/config/SN07C624160009071F/device.info @@ -0,0 +1,10 @@ +%YAML:1.0 +--- +device_name: MYNT-EYE-S210A +serial_number: "07C624160009071F" +firmware_version: "0.1" +hardware_version: "1.0" +spec_version: "1.1" +lens_type: "0000" +imu_type: "0000" +nominal_baseline: 0 diff --git a/config/SN07C624160009071F/img.params b/config/SN07C624160009071F/img.params new file mode 100644 index 0000000..d78da8d --- /dev/null +++ b/config/SN07C624160009071F/img.params @@ -0,0 +1,53 @@ +%YAML:1.0 +--- +version: "1.1" +in_left_map: + - + width: 640 + height: 400 + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + model: 0 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] + - + width: 1280 + height: 800 + fx: 1.9739641213416058e+02 + fy: 1.9772337597617189e+02 + cx: 3.2611983633916327e+02 + cy: 1.9986969132833946e+02 + model: 0 + coeffs: [ 1.2135236310725651e-01, -8.5442776049177036e-02, + 2.4914898631983504e-03, -3.7752063658256863e-03, 0. ] +in_right_map: + - + width: 640 + height: 400 + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + model: 0 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] + - + width: 1280 + height: 800 + fx: 2.0335498653655989e+02 + fy: 2.0453858622699008e+02 + cx: 3.1589962248180814e+02 + cy: 2.1871688038954812e+02 + model: 0 + coeffs: [ 2.2904330559241560e-02, -2.9561990079971841e-02, + 3.9725942760981507e-03, -3.9689073214945591e-03, 0. ] +ex_left_to_right: + rotation: [ 9.9998850083695123e-01, -1.9263678722299450e-03, + -4.3917309443490191e-03, 1.8166060642710027e-03, + 9.9968925981619028e-01, -2.4861290203142431e-02, + 4.4382582477776426e-03, 2.4853026274046636e-02, + 9.9968126367795229e-01 ] + translation: [ -8.2270200890555529e+01, -1.9535144360069059e+00, + 2.2588034344482368e+00 ] diff --git a/config/SN07C624160009071F/imu.params b/config/SN07C624160009071F/imu.params new file mode 100644 index 0000000..070f13a --- /dev/null +++ b/config/SN07C624160009071F/imu.params @@ -0,0 +1,15 @@ +%YAML:1.0 +--- +in_accel: + scale: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + drift: [ 0., 0., 0. ] + noise: [ 0., 0., 0. ] + bias: [ 0., 0., 0. ] +in_gyro: + scale: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + drift: [ 0., 0., 0. ] + noise: [ 0., 0., 0. ] + bias: [ 0., 0., 0. ] +ex_left_to_imu: + rotation: [ 0., 0., 0., 0., 0., 0., 0., 0., 0. ] + translation: [ 0., 0., 0. ] 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/global.h b/include/mynteye/global.h index 7a58f4e..f60e341 100644 --- a/include/mynteye/global.h +++ b/include/mynteye/global.h @@ -67,9 +67,9 @@ #endif #if defined(OS_WIN) && !defined(OS_MINGW) && !defined(OS_CYGWIN) -#define OS_SEP "\\" +#define MYNTEYE_OS_SEP "\\" #else -#define OS_SEP "/" +#define MYNTEYE_OS_SEP "/" #endif #define STRINGIFY_HELPER(X) #X diff --git a/include/mynteye/glog_init.h b/include/mynteye/logger.h similarity index 51% rename from include/mynteye/glog_init.h rename to include/mynteye/logger.h index c095f20..83a7642 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. */ @@ -25,14 +27,30 @@ struct glog_init { glog_init(int argc, char *argv[]) { (void)argc; - // FLAGS_logtostderr = true; - FLAGS_alsologtostderr = true; + // Set whether log messages go to stderr instead of logfiles + FLAGS_logtostderr = true; + + // Set whether log messages go to stderr in addition to logfiles. + // FLAGS_alsologtostderr = true; + + // Set color messages logged to stderr (if supported by terminal). FLAGS_colorlogtostderr = true; - // FLAGS_log_dir = "."; - FLAGS_max_log_size = 1024; + // Log suppression level: messages logged at a lower level than this + // are suppressed. + FLAGS_minloglevel = google::GLOG_INFO; + + // If specified, logfiles are written into this directory instead of the + // default logging directory. + FLAGS_log_dir = "."; + + // Sets the maximum log file size (in MB). + 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; + // Show all VLOG(m) messages for m <= this. // FLAGS_v = 2; google::InitGoogleLogging(argv[0]); @@ -46,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 MYNTEYE_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..02d377a --- /dev/null +++ b/include/mynteye/miniglog.h @@ -0,0 +1,469 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2013 Google Inc. All rights reserved. +// http://code.google.com/p/ceres-solver/ +// +// 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_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mynteye/mynteye.h" + +#ifdef MYNTEYE_OS_ANDROID +# include +#endif // ANDROID + +// Log severity level constants. +#ifdef MYNTEYE_OS_WIN + +const int FATAL = -1; +#ifndef ERROR // NOT windows.h +const int ERROR = 0; +#endif +const int WARNING = 1; +const int INFO = 2; + +#else + +const int FATAL = -3; +const int ERROR = -2; +const int WARNING = -1; +const int INFO = 0; + +#endif + +// ------------------------- Glog compatibility ------------------------------ + +namespace google { + +typedef int LogSeverity; +const int FATAL = ::FATAL; +#ifndef ERROR // NOT windows.h +const int ERROR = ::ERROR; +#endif +const int WARNING = ::WARNING; +const int INFO = ::INFO; + +// 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 MYNTEYE_API 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. +MYNTEYE_API extern std::set log_sinks_global; + +// Added by chachi - a runtime global maximum log level. Defined in logging.cc +MYNTEYE_API extern int log_severity_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 MYNTEYE_API 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_ << SeverityLabel() << "/" << filename_only_ << ":" << line << " "; + } + + // Output the contents of the stream to the proper channel on destruction. + ~MessageLogger() { + stream_ << "\n"; + +#ifdef MYNTEYE_OS_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 + // If not building on Android, log all output to std::cerr. + std::cerr << stream_.str(); +#endif // ANDROID + + 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; + struct tm* timeinfo; + + time (&rawtime); + timeinfo = localtime(&rawtime); + 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(MYNTEYE_OS_SEP); + if (pos != std::string::npos) { + *filename = full_path.substr(pos + 1, std::string::npos); + } else { + *filename = full_path; + } + } + + char SeverityLabel() { + switch (severity_) { + case INFO: + return 'I'; + case WARNING: + return 'W'; + case ERROR: + return 'E'; + case FATAL: + return 'F'; + default: + return 'V'; + } + } + + 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 MYNTEYE_API 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) \ + (static_cast(severity) > google::log_severity_global || !(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 MYNTEYE_MAX_LOG_LEVEL +# define LOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL)) +# define VLOG(n) LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL)) +# define LG LOG_IF(INFO, (INFO <= MYNTEYE_MAX_LOG_LEVEL)) +# define VLOG_IF(n, condition) \ + LOG_IF(n, (n <= MYNTEYE_MAX_LOG_LEVEL) && condition) +#else +# define LOG(n) LOG_IF(n, true) +# define VLOG(n) LOG_IF(n, true) +# define LG LOG_IF(INFO, true) +# define VLOG_IF(n, condition) LOG_IF(n, condition) +#endif + +// Currently, VLOG is always on for levels below MYNTEYE_MAX_LOG_LEVEL. +#ifndef MYNTEYE_MAX_LOG_LEVEL +# define VLOG_IS_ON(x) (1) +#else +# define VLOG_IS_ON(x) (x <= MYNTEYE_MAX_LOG_LEVEL) +#endif + +#ifdef MYNTEYE_OS_WIN // INFO is 2, change VLOG(2) to VLOG(4) +#undef VLOG +#undef VLOG_IF +#undef VLOG_IS_ON + +#ifdef MYNTEYE_MAX_LOG_LEVEL +# define VLOG(n) LOG_IF(n+2, (n+2 <= MYNTEYE_MAX_LOG_LEVEL)) +# define VLOG_IF(n, condition) \ + LOG_IF(n+2, (n+2 <= MYNTEYE_MAX_LOG_LEVEL) && condition) +#else +# define VLOG(n) LOG_IF(n+2, true) +# define VLOG_IF(n, condition) LOG_IF(n+2, condition) +#endif + +#ifndef MYNTEYE_MAX_LOG_LEVEL +# define VLOG_IS_ON(x) (1+2) +#else +# define VLOG_IS_ON(x) (x+2 <= MYNTEYE_MAX_LOG_LEVEL) +#endif + +#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(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, >) + +#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, >) +#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, >) +#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 + +#endif // MYNTEYE_MINIGLOG_H_ diff --git a/mynteye-config.cmake.in b/mynteye-config.cmake.in index aaeb16a..9fff75c 100644 --- a/mynteye-config.cmake.in +++ b/mynteye-config.cmake.in @@ -13,5 +13,7 @@ # limitations under the License. @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 58a0157..31bcdaf 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -47,9 +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) @@ -57,6 +54,10 @@ 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/samples/api/camera.cc b/samples/api/camera.cc index a90c102..1e5cde2 100644 --- a/samples/api/camera.cc +++ b/samples/api/camera.cc @@ -13,8 +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 4698e2f..344a0a6 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" #define WIN_FLAGS \ diff --git a/samples/device/camera.cc b/samples/device/camera.cc index c79028e..190d0b6 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 55cfd30..a6ab3b3 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..5dcf1f5 100644 --- a/samples/tutorials/data/get_depth.cc +++ b/samples/tutorials/data/get_depth.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/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..f706354 100644 --- a/samples/tutorials/data/get_disparity.cc +++ b/samples/tutorials/data/get_disparity.cc @@ -13,9 +13,9 @@ // limitations under the License. #include -#include #include "mynteye/api.h" +#include "mynteye/logger.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 3f09524..d741853 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..49aeeaf 100644 --- a/samples/tutorials/data/get_points.cc +++ b/samples/tutorials/data/get_points.cc @@ -13,9 +13,8 @@ // limitations under the License. #include -#include - #include "mynteye/api.h" +#include "mynteye/logger.h" #include "util/pc_viewer.h" diff --git a/samples/tutorials/data/get_stereo.cc b/samples/tutorials/data/get_stereo.cc index a82a9e9..b06ec42 100644 --- a/samples/tutorials/data/get_stereo.cc +++ b/samples/tutorials/data/get_stereo.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/data/get_stereo_rectified.cc b/samples/tutorials/data/get_stereo_rectified.cc index 04c4eae..2012996 100644 --- a/samples/tutorials/data/get_stereo_rectified.cc +++ b/samples/tutorials/data/get_stereo_rectified.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/data/get_with_plugin.cc b/samples/tutorials/data/get_with_plugin.cc index a2201ba..65f7d19 100644 --- a/samples/tutorials/data/get_with_plugin.cc +++ b/samples/tutorials/data/get_with_plugin.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/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 ec73a11..079c6fe 100644 --- a/samples/tutorials/intermediate/get_depth_and_points.cc +++ b/samples/tutorials/intermediate/get_depth_and_points.cc @@ -14,7 +14,6 @@ #include #include -#include #include "mynteye/api.h" diff --git a/samples/tutorials/util/cv_painter.cc b/samples/tutorials/util/cv_painter.cc index 83fa767..ec59f73 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 04b6010..cf0287d 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..c75a70f 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -14,181 +14,30 @@ # limitations under the License. # _VERBOSE_=1 +# _INIT_LINTER_=1 # _FORCE_INSRALL_=1 +_INSTALL_OPTIONS_=$@ 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..0078271 --- /dev/null +++ b/scripts/init_tools.sh @@ -0,0 +1,219 @@ +#!/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 +# _INSTALL_OPTIONS_=-y + +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=($@) + if [ -n "${_INSTALL_OPTIONS_}" ]; then + _cmd="$_cmd $_INSTALL_OPTIONS_" + fi + _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_cmd $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/scripts/version.sh b/scripts/version.sh new file mode 100755 index 0000000..e3903e1 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# 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. + +BASE_DIR=$(cd "$(dirname "$0")" && pwd) +ROOT_DIR=$(dirname "$BASE_DIR") +CONFIG_FILE="$ROOT_DIR/CMakeLists.txt" + +version=$(cat "$CONFIG_FILE" | grep -m1 "mynteye VERSION") +version=$(echo "${version%LANGUAGES*}") +version=$(echo "${version#*VERSION}" | tr -d '[:space:]') + +echo "$version" diff --git a/scripts/win/cmake/mynteye-targets-release.cmake b/scripts/win/cmake/mynteye-targets-release.cmake new file mode 100644 index 0000000..a009b81 --- /dev/null +++ b/scripts/win/cmake/mynteye-targets-release.cmake @@ -0,0 +1,29 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "Release". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "mynteye" for configuration "Release" +set_property(TARGET mynteye APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(mynteye PROPERTIES + IMPORTED_IMPLIB_RELEASE "${MYNTEYES_SDK_ROOT}/lib/mynteye.lib" + IMPORTED_LOCATION_RELEASE "${MYNTEYES_SDK_ROOT}/bin/mynteye.dll" + ) + +# Import target "mynteye" for configuration "Debug" +set_property(TARGET mynteye APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) +set_target_properties(mynteye PROPERTIES + IMPORTED_IMPLIB_DEBUG "${MYNTEYES_SDK_ROOT}/lib/mynteyed.lib" + IMPORTED_LOCATION_DEBUG "${MYNTEYES_SDK_ROOT}/bin/mynteyed.dll" + ) + +list(APPEND _IMPORT_CHECK_TARGETS mynteye ) +list(APPEND _IMPORT_CHECK_FILES_FOR_mynteye + "${MYNTEYES_SDK_ROOT}/lib/mynteye.lib" "${MYNTEYES_SDK_ROOT}/bin/mynteye.dll" + "${MYNTEYES_SDK_ROOT}/lib/mynteyed.lib" "${MYNTEYES_SDK_ROOT}/bin/mynteyed.dll" + ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/scripts/win/cmake/mynteye-targets.cmake b/scripts/win/cmake/mynteye-targets.cmake new file mode 100644 index 0000000..dd35c23 --- /dev/null +++ b/scripts/win/cmake/mynteye-targets.cmake @@ -0,0 +1,102 @@ +# Generated by CMake + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) + message(FATAL_ERROR "CMake >= 2.6.0 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.6) +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget mynteye) + list(APPEND _expectedTargets ${_expectedTarget}) + if(NOT TARGET ${_expectedTarget}) + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + endif() +endforeach() +if("${_targetsDefined}" STREQUAL "${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + set(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + + +if(NOT MYNTEYES_SDK_ROOT) + if(DEFINED ENV{MYNTEYES_SDK_ROOT}) + set(MYNTEYES_SDK_ROOT $ENV{MYNTEYES_SDK_ROOT}) + else() + get_filename_component(MYNTEYES_SDK_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) + endif() +endif() + +# The installation prefix configured by this project. +set(_IMPORT_PREFIX "${MYNTEYES_SDK_ROOT}") + +# Create imported target mynteye +add_library(mynteye SHARED IMPORTED) + +set_target_properties(mynteye PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "GLOG_NO_ABBREVIATED_SEVERITIES" + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" + INTERFACE_LINK_LIBRARIES "opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_world" +) + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") +endif() + +# Load information for each installed configuration. +get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(GLOB CONFIG_FILES "${_DIR}/mynteye-targets-*.cmake") +foreach(f ${CONFIG_FILES}) + include(${f}) +endforeach() + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(target ${_IMPORT_CHECK_TARGETS} ) + foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) + if(NOT EXISTS "${file}" ) + message(FATAL_ERROR "The imported target \"${target}\" references the file + \"${file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + unset(_IMPORT_CHECK_FILES_FOR_${target}) +endforeach() +unset(_IMPORT_CHECK_TARGETS) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) diff --git a/scripts/win/generate.bat b/scripts/win/generate.bat new file mode 100644 index 0000000..71d5e8d --- /dev/null +++ b/scripts/win/generate.bat @@ -0,0 +1,20 @@ +@echo off +setlocal +set _MY_DIR=%~dp0 + +set _VS_GEN="Visual Studio 15 2017 Win64" +REM set _VS_GEN="Visual Studio 14 2015 Win64" + +cd %_MY_DIR% + +mkdir _build +cd _build/ + +cmake -DCMAKE_BUILD_TYPE=Release ^ +-DCMAKE_PREFIX_PATH="%_MY_DIR%/../lib/cmake" ^ +-DOpenCV_DIR="%_MY_DIR%/../3rdparty/opencv/build" ^ +-G %_VS_GEN% ^ +.. + +cd %_MY_DIR% +pause diff --git a/scripts/win/nsis/Include/EnvVarUpdate.nsh b/scripts/win/nsis/Include/EnvVarUpdate.nsh new file mode 100644 index 0000000..8aeba45 --- /dev/null +++ b/scripts/win/nsis/Include/EnvVarUpdate.nsh @@ -0,0 +1,350 @@ +/** + * EnvVarUpdate.nsh + * : Environmental Variables: append, prepend, and remove entries + * + * WARNING: If you use StrFunc.nsh header then include it before this file + * with all required definitions. This is to avoid conflicts + * + * Usage: + * ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString" + * + * Credits: + * Version 1.0 + * * Cal Turney (turnec2) + * * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this + * function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar, + * WriteEnvStr, and un.DeleteEnvStr + * * Diego Pedroso (deguix) for StrTok + * * Kevin English (kenglish_hi) for StrContains + * * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry + * (dandaman32) for StrReplace + * + * Version 1.1 (compatibility with StrFunc.nsh) + * * techtonik + * + * http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries + * + */ + + +!ifndef ENVVARUPDATE_FUNCTION +!define ENVVARUPDATE_FUNCTION +!verbose push +!verbose 3 +!include "LogicLib.nsh" +!include "WinMessages.NSH" +!include "StrFunc.nsh" + +; ---- Fix for conflict if StrFunc.nsh is already includes in main file ----------------------- +!macro _IncludeStrFunction StrFuncName + !ifndef ${StrFuncName}_INCLUDED + ${${StrFuncName}} + !endif + !ifndef Un${StrFuncName}_INCLUDED + ${Un${StrFuncName}} + !endif + !define un.${StrFuncName} "${Un${StrFuncName}}" +!macroend + +!insertmacro _IncludeStrFunction StrTok +!insertmacro _IncludeStrFunction StrStr +!insertmacro _IncludeStrFunction StrRep + +; ---------------------------------- Macro Definitions ---------------------------------------- +!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString + Push "${EnvVarName}" + Push "${Action}" + Push "${RegLoc}" + Push "${PathString}" + Call EnvVarUpdate + Pop "${ResultVar}" +!macroend +!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"' + +!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString + Push "${EnvVarName}" + Push "${Action}" + Push "${RegLoc}" + Push "${PathString}" + Call un.EnvVarUpdate + Pop "${ResultVar}" +!macroend +!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"' +; ---------------------------------- Macro Definitions end------------------------------------- + +;----------------------------------- EnvVarUpdate start---------------------------------------- +!define hklm_all_users 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' +!define hkcu_current_user 'HKCU "Environment"' + +!macro EnvVarUpdate UN + +Function ${UN}EnvVarUpdate + + Push $0 + Exch 4 + Exch $1 + Exch 3 + Exch $2 + Exch 2 + Exch $3 + Exch + Exch $4 + Push $5 + Push $6 + Push $7 + Push $8 + Push $9 + Push $R0 + + /* After this point: + ------------------------- + $0 = ResultVar (returned) + $1 = EnvVarName (input) + $2 = Action (input) + $3 = RegLoc (input) + $4 = PathString (input) + $5 = Orig EnvVar (read from registry) + $6 = Len of $0 (temp) + $7 = tempstr1 (temp) + $8 = Entry counter (temp) + $9 = tempstr2 (temp) + $R0 = tempChar (temp) */ + + ; Step 1: Read contents of EnvVarName from RegLoc + ; + ; Check for empty EnvVarName + ${If} $1 == "" + SetErrors + DetailPrint "ERROR: EnvVarName is blank" + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + + ; Check for valid Action + ${If} $2 != "A" + ${AndIf} $2 != "P" + ${AndIf} $2 != "R" + SetErrors + DetailPrint "ERROR: Invalid Action - must be A, P, or R" + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + + ${If} $3 == HKLM + ReadRegStr $5 ${hklm_all_users} $1 ; Get EnvVarName from all users into $5 + ${ElseIf} $3 == HKCU + ReadRegStr $5 ${hkcu_current_user} $1 ; Read EnvVarName from current user into $5 + ${Else} + SetErrors + DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"' + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + + ; Check for empty PathString + ${If} $4 == "" + SetErrors + DetailPrint "ERROR: PathString is blank" + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + + ;;khc - here check if length is going to be greater then max string length + ;; and abort if so - also abort if original path empty - may mean + ;; it was too long as well- write message to say set it by hand + Push $6 + Push $7 + Push $8 + StrLen $7 $4 + StrLen $6 $5 + IntOp $8 $6 + $7 + ${If} $5 == "" + ${OrIf} $8 >= ${NSIS_MAX_STRLEN} + SetErrors + DetailPrint "Current $1 length ($6) too long to modify in NSIS; set manually if needed" + Pop $8 + Pop $7 + Pop $6 + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + Pop $8 + Pop $7 + Pop $6 + ;;khc + + ; Make sure we've got some work to do + ${If} $5 == "" + ${AndIf} $2 == "R" + SetErrors + DetailPrint "$1 is empty - Nothing to remove" + Goto EnvVarUpdate_Restore_Vars + ${EndIf} + + ; Step 2: Scrub EnvVar + ; + StrCpy $0 $5 ; Copy the contents to $0 + ; Remove spaces around semicolons (NOTE: spaces before the 1st entry or + ; after the last one are not removed here but instead in Step 3) + ${If} $0 != "" ; If EnvVar is not empty ... + ${Do} + ${${UN}StrStr} $7 $0 " ;" + ${If} $7 == "" + ${ExitDo} + ${EndIf} + ${${UN}StrRep} $0 $0 " ;" ";" ; Remove ';' + ${Loop} + ${Do} + ${${UN}StrStr} $7 $0 "; " + ${If} $7 == "" + ${ExitDo} + ${EndIf} + ${${UN}StrRep} $0 $0 "; " ";" ; Remove ';' + ${Loop} + ${Do} + ${${UN}StrStr} $7 $0 ";;" + ${If} $7 == "" + ${ExitDo} + ${EndIf} + ${${UN}StrRep} $0 $0 ";;" ";" + ${Loop} + + ; Remove a leading or trailing semicolon from EnvVar + StrCpy $7 $0 1 0 + ${If} $7 == ";" + StrCpy $0 $0 "" 1 ; Change ';' to '' + ${EndIf} + StrLen $6 $0 + IntOp $6 $6 - 1 + StrCpy $7 $0 1 $6 + ${If} $7 == ";" + StrCpy $0 $0 $6 ; Change ';' to '' + ${EndIf} + ; DetailPrint "Scrubbed $1: [$0]" ; Uncomment to debug + ${EndIf} + + /* Step 3. Remove all instances of the target path/string (even if "A" or "P") + $6 = bool flag (1 = found and removed PathString) + $7 = a string (e.g. path) delimited by semicolon(s) + $8 = entry counter starting at 0 + $9 = copy of $0 + $R0 = tempChar */ + + ${If} $5 != "" ; If EnvVar is not empty ... + StrCpy $9 $0 + StrCpy $0 "" + StrCpy $8 0 + StrCpy $6 0 + + ${Do} + ${${UN}StrTok} $7 $9 ";" $8 "0" ; $7 = next entry, $8 = entry counter + + ${If} $7 == "" ; If we've run out of entries, + ${ExitDo} ; were done + ${EndIf} ; + + ; Remove leading and trailing spaces from this entry (critical step for Action=Remove) + ${Do} + StrCpy $R0 $7 1 + ${If} $R0 != " " + ${ExitDo} + ${EndIf} + StrCpy $7 $7 "" 1 ; Remove leading space + ${Loop} + ${Do} + StrCpy $R0 $7 1 -1 + ${If} $R0 != " " + ${ExitDo} + ${EndIf} + StrCpy $7 $7 -1 ; Remove trailing space + ${Loop} + ${If} $7 == $4 ; If string matches, remove it by not appending it + StrCpy $6 1 ; Set 'found' flag + ${ElseIf} $7 != $4 ; If string does NOT match + ${AndIf} $0 == "" ; and the 1st string being added to $0, + StrCpy $0 $7 ; copy it to $0 without a prepended semicolon + ${ElseIf} $7 != $4 ; If string does NOT match + ${AndIf} $0 != "" ; and this is NOT the 1st string to be added to $0, + StrCpy $0 $0;$7 ; append path to $0 with a prepended semicolon + ${EndIf} ; + + IntOp $8 $8 + 1 ; Bump counter + ${Loop} ; Check for duplicates until we run out of paths + ${EndIf} + + ; Step 4: Perform the requested Action + ; + ${If} $2 != "R" ; If Append or Prepend + ${If} $6 == 1 ; And if we found the target + DetailPrint "Target is already present in $1. It will be removed and" + ${EndIf} + ${If} $0 == "" ; If EnvVar is (now) empty + StrCpy $0 $4 ; just copy PathString to EnvVar + ${If} $6 == 0 ; If found flag is either 0 + ${OrIf} $6 == "" ; or blank (if EnvVarName is empty) + DetailPrint "$1 was empty and has been updated with the target" + ${EndIf} + ${ElseIf} $2 == "A" ; If Append (and EnvVar is not empty), + StrCpy $0 $0;$4 ; append PathString + ${If} $6 == 1 + DetailPrint "appended to $1" + ${Else} + DetailPrint "Target was appended to $1" + ${EndIf} + ${Else} ; If Prepend (and EnvVar is not empty), + StrCpy $0 $4;$0 ; prepend PathString + ${If} $6 == 1 + DetailPrint "prepended to $1" + ${Else} + DetailPrint "Target was prepended to $1" + ${EndIf} + ${EndIf} + ${Else} ; If Action = Remove + ${If} $6 == 1 ; and we found the target + DetailPrint "Target was found and removed from $1" + ${Else} + DetailPrint "Target was NOT found in $1 (nothing to remove)" + ${EndIf} + ${If} $0 == "" + DetailPrint "$1 is now empty" + ${EndIf} + ${EndIf} + + ; Step 5: Update the registry at RegLoc with the updated EnvVar and announce the change + ; + ClearErrors + ${If} $3 == HKLM + WriteRegExpandStr ${hklm_all_users} $1 $0 ; Write it in all users section + ${ElseIf} $3 == HKCU + WriteRegExpandStr ${hkcu_current_user} $1 $0 ; Write it to current user section + ${EndIf} + + IfErrors 0 +4 + MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3" + DetailPrint "Could not write updated $1 to $3" + Goto EnvVarUpdate_Restore_Vars + + ; "Export" our change + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + + EnvVarUpdate_Restore_Vars: + ; + ; Restore the user's variables and return ResultVar + Pop $R0 + Pop $9 + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Push $0 ; Push my $0 (ResultVar) + Exch + Pop $0 ; Restore his $0 + +FunctionEnd + +!macroend ; EnvVarUpdate UN +!insertmacro EnvVarUpdate "" +!insertmacro EnvVarUpdate "un." +;----------------------------------- EnvVarUpdate end---------------------------------------- + +!verbose pop +!endif diff --git a/scripts/win/nsis/mynt.ico b/scripts/win/nsis/mynt.ico new file mode 100644 index 0000000..f4d3c39 Binary files /dev/null and b/scripts/win/nsis/mynt.ico differ diff --git a/scripts/win/nsis/winpack.nsi.in b/scripts/win/nsis/winpack.nsi.in new file mode 100644 index 0000000..b70cd3d --- /dev/null +++ b/scripts/win/nsis/winpack.nsi.in @@ -0,0 +1,198 @@ +; winpack.nsi + +!addincludedir scripts\win\nsis\Include +!include EnvVarUpdate.nsh + +!addplugindir scripts\win\nsis\Plugins + +!include WinMessages.nsh + +!define VERSION "@mynteye_VERSION@" +!define OpenCV_VERSION "@OpenCV_VERSION@" + +!define DSETDIR "$APPDATA" +;!define DSETDIR "$PROGRAMFILES64" + +; HKLM (all users) vs HKCU (current user) defines +!define ENV_HKLM 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' +!define ENV_HKCU 'HKCU "Environment"' + +;-------------------------------- + +; The name of the installer +Name "MYNTEYE S SDK ${VERSION}" + +; The icon of the installer +Icon "scripts\win\nsis\mynt.ico" + +; The file to write +OutFile "mynteye-s-${VERSION}-win-x64-opencv-${OpenCV_VERSION}.exe" + +; The default installation directory +InstallDir ${DSETDIR}\Slightech\MYNTEYES\SDK\${VERSION} + +; Registry key to check for directory (so if you install again, it will +; overwrite the old one automatically) +InstallDirRegKey HKLM "Software\MYNTEYESSDK" "Install_Dir" + +; Request application privileges for Windows Vista +;RequestExecutionLevel user +RequestExecutionLevel admin + +;-------------------------------- + +; Pages + +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +;-------------------------------- + +; The stuff to install +Section "SDK (required)" + + SectionIn RO + + ; Set output path to the installation directory. + SetOutPath $INSTDIR + + ; Put file there + File /r "mynteye-s-${VERSION}-win-x64-opencv-${OpenCV_VERSION}\*" + + ; Write the installation path into the registry + WriteRegStr HKLM "SOFTWARE\MYNTEYESSDK" "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for Windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYNTEYESSDK" "DisplayName" "MYNTEYE S SDK" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYNTEYESSDK" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYNTEYESSDK" "NoModify" 1 + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYNTEYESSDK" "NoRepair" 1 + WriteUninstaller "uninstall.exe" + + ; Set variables for local machine + WriteRegExpandStr ${ENV_HKLM} MYNTEYES_SDK_ROOT "$INSTDIR" + + ;${EnvVarUpdate} $0 "PATH" "P" "HKLM" "%MYNTEYES_SDK_PATH%" + ${EnvVarUpdate} $0 "PATH" "P" "HKLM" "$INSTDIR\bin;$INSTDIR\3rdparty\opencv\build\x64\vc15\bin" + + ; Push "%MYNTEYES_SDK_PATH%" + ; Call AddToPath + + ; Make sure windows knows about the change + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + +SectionEnd + +; Optional section (can be disabled by the user) +Section "Desktop Shortcuts" + + CreateShortcut "$DESKTOP\MYNTEYE S SDK ${VERSION}.lnk" "$INSTDIR" "" "$INSTDIR" 0 + +SectionEnd + +Function .onInstSuccess + + WriteRegStr "HKLM" "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" \ + "View MYNTEYES README.txt" \ + "cmd.exe /c start /max notepad.exe $INSTDIR\README.txt" + + MessageBox MB_OKCANCEL "Reboot your system now?" /SD IDOK IDCANCEL NoReboot + Reboot + NoReboot: + +FunctionEnd + +Function .onInstFailed + MessageBox MB_OK "Install failed." +FunctionEnd + +;-------------------------------- + +; Uninstaller + +Section "Uninstall" + + ; Remove registry keys + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MYNTEYESSDK" + DeleteRegKey HKLM "SOFTWARE\MYNTEYESSDK" + + ; Remove install stuff + RMDir /r "$INSTDIR" + + ; Remove shortcuts, if any + Delete "$DESKTOP\MYNTEYE S SDK ${VERSION}.lnk" + + ; Remove directories used + StrCpy $0 "${DSETDIR}\Slightech\MYNTEYES" + Call un.DeleteDirIfEmpty + StrCpy $0 "${DSETDIR}\Slightech" + Call un.DeleteDirIfEmpty + + RMDir /r "$APPDATA\Slightech\MYNTEYES" + StrCpy $0 "$APPDATA\Slightech" + Call un.DeleteDirIfEmpty + + ; Delete variables + DeleteRegValue ${ENV_HKLM} MYNTEYES_SDK_ROOT + + ;${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "%MYNTEYES_SDK_PATH%" + ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin" + ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\3rdparty\opencv\build\x64\vc15\bin" + + ; Push "%MYNTEYES_SDK_PATH%" + ; Call un.RemoveFromPath + + ; Make sure windows knows about the change + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + +SectionEnd + +Function un.onUninstSuccess + MessageBox MB_OK "Uninstall success." +FunctionEnd + +Function un.onUninstFailed + MessageBox MB_OK "Uninstall failed." +FunctionEnd + +;-------------------------------- + +; DeleteDirIfEmpty - Delete dir only if empty + +Function un.DeleteDirIfEmpty + FindFirst $R0 $R1 "$0\*.*" + strcmp $R1 "." 0 NoDelete + FindNext $R0 $R1 + strcmp $R1 ".." 0 NoDelete + ClearErrors + FindNext $R0 $R1 + IfErrors 0 NoDelete + FindClose $R0 + Sleep 1000 + RMDir "$0" + NoDelete: + FindClose $R0 +FunctionEnd + +;-------------------------------- + +; Path Manipulation +; http://nsis.sourceforge.net/Path_Manipulation +; Environmental Variables: append, prepend, and remove entries +; http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries +; Setting Environment Variables +; http://nsis.sourceforge.net/Setting_Environment_Variables +; Setting Environment Variables to Active Installer Process +; http://nsis.sourceforge.net/Setting_Environment_Variables_to_Active_Installer_Process + +; Delete files and subdirectories +; http://nsis.sourceforge.net/Delete_files_and_subdirectories +; Delete dir only if empty +; http://nsis.sourceforge.net/Delete_dir_only_if_empty + +;https://gist.github.com/azalea/deb3c1ed2a984eadf96be77b81dd49b1 +;!include ProcessEnvPrependPath.nsh diff --git a/scripts/win/winpack.sh b/scripts/win/winpack.sh new file mode 100644 index 0000000..e081ac9 --- /dev/null +++ b/scripts/win/winpack.sh @@ -0,0 +1,179 @@ +#!/usr/bin/env bash +# 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. + +BASE_DIR=$(cd "$(dirname "$0")" && pwd) +ROOT_DIR=$(realpath "$BASE_DIR/../..") +SCRIPTS_DIR=$(realpath "$BASE_DIR/..") + +source "$SCRIPTS_DIR/common/echo.sh" +source "$SCRIPTS_DIR/common/detect.sh" + +if [ ! -d "$ROOT_DIR/3rdparty/opencv" ]; then + _echo_e "3rdparty/opencv not found, please manually download it to here." + _echo_e + _echo_e " OpenCV Win pack 3.4.3: https://opencv.org/releases.html" + exit 1 +fi + +if ! _detect_cmd makensis; then + _echo_e "makensis not found, please manually download and install it." + _echo_e + _echo_e " NSIS: http://nsis.sourceforge.net" + exit 1 +fi + +export OpenCV_DIR="$ROOT_DIR/3rdparty/opencv/build" + +_rm() { + [ -e "$1" ] && (rm -r "$1" && _echo_i "RM: $1") +} + +_md() { + [ ! -d "$1" ] && (mkdir -p "$1" && _echo_i "MD: $1") +} + +# _mv_subs [sub1 sub2 ...] +_mv_subs() { + _src_dir="$1"; shift; _dst_dir="$1"; shift; _subs="$@"; + if [ -z "$_subs" ]; then + _subs=`ls $_src_dir` + fi + for _sub in $_subs; do + _src="$_src_dir/$_sub" + [ ! -e "$_src" ] && (_echo_i "Not exist: $_src") && continue + _dst= + [ -f "$_src" ] && _dst="$_dst_dir" + [ -d "$_src" ] && _dst="$_dst_dir/$_sub" + [ -z "$_dst" ] && continue + # _echo "_src: $_src" + # _echo "_dst: $_dst" + mv "$_src" "$_dst" + done +} + +################################################################################ +# build release + +make samples tools + +################################################################################ +# build debug + +rm -r "$ROOT_DIR/_build" +rm -r "$ROOT_DIR/_output" +make build BUILD_TYPE=Debug + +mv "$ROOT_DIR/_output/bin/mynteyed.dll" "$ROOT_DIR/_install/bin/mynteyed.dll" +mv "$ROOT_DIR/_output/lib/mynteyed.lib" "$ROOT_DIR/_install/lib/mynteyed.lib" + +################################################################################ +# move to _install + +# 3rdparty/opencv +_md "$ROOT_DIR/_install/3rdparty" +mv "$ROOT_DIR/3rdparty/opencv" "$ROOT_DIR/_install/3rdparty/opencv" + +# cmake +mv "$ROOT_DIR/cmake" "$ROOT_DIR/_install/cmake" + +# samples +mv "$ROOT_DIR/samples/_output/bin" "$ROOT_DIR/_install/bin/samples" +mv "$ROOT_DIR/samples/_output/lib" "$ROOT_DIR/_install/lib/samples" +_rm "$ROOT_DIR/samples/_build" +_rm "$ROOT_DIR/samples/_output" +mv "$ROOT_DIR/samples" "$ROOT_DIR/_install/samples" + +# tools +mv "$ROOT_DIR/tools/_output/bin" "$ROOT_DIR/_install/bin/tools" +mv "$ROOT_DIR/tools/_output/lib" "$ROOT_DIR/_install/lib/tools" +_rm "$ROOT_DIR/tools/_build" +_rm "$ROOT_DIR/tools/_output" +mv "$ROOT_DIR/tools/linter" "$ROOT_DIR/3rdparty/linter" +mv "$ROOT_DIR/tools" "$ROOT_DIR/_install/tools" + +# platforms/win +mv "$ROOT_DIR/platforms/win/README.txt" "$ROOT_DIR/_install" + +_rm "$ROOT_DIR/platforms/projects/vs2017/mynteyes_demo/.vs" +_rm "$ROOT_DIR/platforms/projects/vs2017/mynteyes_demo/x64" +_rm "$ROOT_DIR/platforms/projects/vs2017/mynteyes_demo/mynteyes_demo/x64" +_rm "$ROOT_DIR/platforms/projects/vs2017/mynteyes_demo/mynteyes_demo/mynteyes_demo.vcxproj.user" +mv "$ROOT_DIR/platforms/projects" "$ROOT_DIR/_install/projects" + +################################################################################ +# copy to _install + +cp -f "$ROOT_DIR/scripts/win/cmake/mynteye-targets.cmake" "$ROOT_DIR/_install/lib/cmake/mynteye/" +cp -f "$ROOT_DIR/scripts/win/cmake/mynteye-targets-release.cmake" "$ROOT_DIR/_install/lib/cmake/mynteye/" + +cp -f "$ROOT_DIR/scripts/win/generate.bat" "$ROOT_DIR/_install/samples/" +cp -f "$ROOT_DIR/scripts/win/generate.bat" "$ROOT_DIR/_install/tools/" + +################################################################################ +# archive exe + +source "$ROOT_DIR/pkginfo.sh" +_pkgname="$1-opencv-$OpenCV_VERSION" + +_rm "$ROOT_DIR/$_pkgname.exe" +mv "$ROOT_DIR/_install" "$ROOT_DIR/$_pkgname" + +makensis "$ROOT_DIR/winpack.nsi" + +if _detect_cmd git; then + _git_branch=`git symbolic-ref --short -q HEAD` + if [ "$_git_branch" == "develop" ]; then + _git_hash=`git rev-parse --short HEAD` + mv "$ROOT_DIR/$_pkgname.exe" "$ROOT_DIR/$_pkgname-dev-$_git_hash.exe" + fi +fi + +mv "$ROOT_DIR/$_pkgname" "$ROOT_DIR/_install" + +################################################################################ +# remove from _install + +_rm "$ROOT_DIR/_install/samples/generate.bat" +_rm "$ROOT_DIR/_install/tools/generate.bat" + +################################################################################ +# move back from _install + +# 3rdparty/opencv +mv "$ROOT_DIR/_install/3rdparty/opencv" "$ROOT_DIR/3rdparty/opencv" + +# cmake +mv "$ROOT_DIR/_install/cmake" "$ROOT_DIR/cmake" + +# samples +mv "$ROOT_DIR/_install/samples" "$ROOT_DIR/samples" + +# tools +mv "$ROOT_DIR/_install/tools" "$ROOT_DIR/tools" +mv "$ROOT_DIR/3rdparty/linter" "$ROOT_DIR/tools/linter" + +# platforms/win +mv "$ROOT_DIR/_install/README.txt" "$ROOT_DIR/platforms/win" + +mv "$ROOT_DIR/_install/projects" "$ROOT_DIR/platforms/projects" + +################################################################################ +# clean build + +_rm "$ROOT_DIR/_build" +_rm "$ROOT_DIR/_output" + + +_echo_d "Win pack success" diff --git a/src/api/api.cc b/src/api/api.cc index a7b8a8d..3f3c640 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" @@ -92,7 +90,7 @@ bool dir_exists(const std::string &p) { std::vector get_plugin_paths() { std::string info_path(MYNTEYE_SDK_INSTALL_DIR); - info_path.append(OS_SEP "share" OS_SEP "mynteye" OS_SEP "build.info"); + info_path.append(MYNTEYE_OS_SEP "share" MYNTEYE_OS_SEP "mynteye" MYNTEYE_OS_SEP "build.info"); cv::FileStorage fs(info_path, cv::FileStorage::READ); if (!fs.isOpened()) { @@ -189,13 +187,13 @@ std::vector get_plugin_paths() { std::vector dirs{MYNTEYE_SDK_ROOT_DIR, MYNTEYE_SDK_INSTALL_DIR}; for (auto &&plat : plats) { for (auto &&dir : dirs) { - auto &&plat_dir = dir + OS_SEP "plugins" + OS_SEP + plat; + auto &&plat_dir = dir + MYNTEYE_OS_SEP "plugins" + MYNTEYE_OS_SEP + plat; // VLOG(2) << "plat_dir: " << plat_dir; if (!dir_exists(plat_dir)) continue; for (auto &&name : names) { // VLOG(2) << " name: " << name; - auto &&path = plat_dir + OS_SEP + name; + auto &&path = plat_dir + MYNTEYE_OS_SEP + name; if (!file_exists(path)) continue; paths.push_back(path); diff --git a/src/api/processor/depth_processor.cc b/src/api/processor/depth_processor.cc index 8d5c9d4..1fa4dfd 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 fa13844..22227ad 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 DisparityNormalizedProcessor::DisparityNormalizedProcessor( diff --git a/src/api/processor/disparity_processor.cc b/src/api/processor/disparity_processor.cc index ff3e71c..b6b177c 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 DisparityProcessor::DisparityProcessor(std::int32_t proc_period) diff --git a/src/api/processor/points_processor.cc b/src/api/processor/points_processor.cc index 0bb82ec..6fa6345 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 PointsProcessor::PointsProcessor(cv::Mat Q, std::int32_t proc_period) 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 6197f0b..938e82c 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 ac6075e..873a9ef 100644 --- a/src/api/synthetic.cc +++ b/src/api/synthetic.cc @@ -13,13 +13,14 @@ // limitations under the License. #include "api/synthetic.h" -#include #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 c25b794..503f48c 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -13,13 +13,14 @@ // 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 23f8ead..865488b 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 05dfc80..9f82b9e 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 @@ -25,6 +23,8 @@ #include "internal/strings.h" #include "internal/times.h" +#include "mynteye/logger.h" + #define IMU_TRACK_PERIOD 25 // ms MYNTEYE_BEGIN_NAMESPACE 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..9a47eaf 100644 --- a/src/internal/files.cc +++ b/src/internal/files.cc @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "internal/files.h" - -#include +#include "mynteye/logger.h" #if defined(OS_WIN) && !defined(OS_MINGW) && !defined(OS_CYGWIN) #include @@ -51,7 +50,7 @@ bool _mkdir(const std::string &path) { } bool mkdir(const std::string &path) { - auto &&dirs = strings::split(path, OS_SEP); + auto &&dirs = strings::split(path, MYNTEYE_OS_SEP); auto &&size = dirs.size(); if (size <= 0) return false; @@ -59,7 +58,7 @@ bool mkdir(const std::string &path) { if (!_mkdir(p)) return false; for (std::size_t i = 1; i < size; i++) { - p.append(OS_SEP).append(dirs[i]); + p.append(MYNTEYE_OS_SEP).append(dirs[i]); if (!_mkdir(p)) return false; } diff --git a/src/internal/motions.cc b/src/internal/motions.cc index 349a5ea..1e2b61c 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 de34e15..24b7331 100644 --- a/src/internal/streams.cc +++ b/src/internal/streams.cc @@ -13,14 +13,13 @@ // limitations under the License. #include "internal/streams.h" -#include - #include #include #include #include #include "internal/types.h" +#include "mynteye/logger.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/main.cc b/src/main.cc index 360e2a0..9137481 100644 --- a/src/main.cc +++ b/src/main.cc @@ -16,13 +16,13 @@ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) #define GLOG_NO_ABBREVIATED_SEVERITIES #endif -#include #ifdef HAVE_LIB_GFLAGS #include #endif #include "mynteye/mynteye.h" +#include "mynteye/logger.h" int main(int /*argc*/, char *argv[]) { // Set whether log messages go to stderr instead of logfiles diff --git a/src/public/miniglog.cc b/src/public/miniglog.cc new file mode 100644 index 0000000..0bda4be --- /dev/null +++ b/src/public/miniglog.cc @@ -0,0 +1,41 @@ +// Ceres Solver - A fast non-linear least squares minimizer +// Copyright 2012 Google Inc. All rights reserved. +// http://code.google.com/p/ceres-solver/ +// +// 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; + +int log_severity_global(INFO); + +} // namespace google diff --git a/src/public/miniglog.readme b/src/public/miniglog.readme new file mode 100644 index 0000000..e10b189 --- /dev/null +++ b/src/public/miniglog.readme @@ -0,0 +1,3 @@ +miniglog: + * https://github.com/arpg/miniglog + * https://github.com/tzutalin/miniglog diff --git a/src/public/types.cc b/src/public/types.cc index 8af31e4..ecee3a5 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 c8d2d77..217cc3f 100644 --- a/src/public/utils.cc +++ b/src/public/utils.cc @@ -13,11 +13,11 @@ // limitations under the License. #include "mynteye/utils.h" -#include - #include "device/context.h" #include "device/device.h" +#include "mynteye/logger.h" + MYNTEYE_BEGIN_NAMESPACE namespace device { diff --git a/src/uvc/uvc-libuvc.cc b/src/uvc/uvc-libuvc.cc index 1b260d7..5ec0896 100644 --- a/src/uvc/uvc-libuvc.cc +++ b/src/uvc/uvc-libuvc.cc @@ -13,9 +13,9 @@ // 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 f86a209..cc21af6 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/tools/CMakeLists.txt b/tools/CMakeLists.txt index a617541..892cc52 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -43,10 +43,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/tools/dataset/dataset.cc b/tools/dataset/dataset.cc index 392e8bf..33cbd6c 100644 --- a/tools/dataset/dataset.cc +++ b/tools/dataset/dataset.cc @@ -14,7 +14,6 @@ #include "dataset/dataset.h" #include #include -#include #include #include @@ -22,6 +21,7 @@ #include #include "mynteye/files.h" +#include "mynteye/logger.h" #define FULL_PRECISION \ std::fixed << std::setprecision(std::numeric_limits::max_digits10) @@ -62,7 +62,7 @@ void Dataset::SaveStreamData( << std::endl; if (data.frame) { std::stringstream ss; - ss << writer->outdir << OS_SEP << std::dec + ss << writer->outdir << MYNTEYE_OS_SEP << std::dec << std::setw(IMAGE_FILENAME_WIDTH) << std::setfill('0') << seq << ".png"; if (data.frame->format() == Format::GREY) { cv::Mat img( @@ -120,15 +120,15 @@ Dataset::writer_t Dataset::GetStreamWriter(const Stream &stream) { writer_t writer = std::make_shared(); switch (stream) { case Stream::LEFT: { - writer->outdir = outdir_ + OS_SEP "left"; + writer->outdir = outdir_ + MYNTEYE_OS_SEP "left"; } break; case Stream::RIGHT: { - writer->outdir = outdir_ + OS_SEP "right"; + writer->outdir = outdir_ + MYNTEYE_OS_SEP "right"; } break; default: LOG(FATAL) << "Unsupported stream: " << stream; } - writer->outfile = writer->outdir + OS_SEP "stream.txt"; + writer->outfile = writer->outdir + MYNTEYE_OS_SEP "stream.txt"; files::mkdir(writer->outdir); writer->ofs.open(writer->outfile, std::ofstream::out); @@ -145,7 +145,7 @@ Dataset::writer_t Dataset::GetMotionWriter() { if (motion_writer_ == nullptr) { writer_t writer = std::make_shared(); writer->outdir = outdir_; - writer->outfile = writer->outdir + OS_SEP "motion.txt"; + writer->outfile = writer->outdir + MYNTEYE_OS_SEP "motion.txt"; files::mkdir(writer->outdir); writer->ofs.open(writer->outfile, std::ofstream::out); diff --git a/tools/writer/device_writer.cc b/tools/writer/device_writer.cc index be3f5e0..8c7b5b7 100644 --- a/tools/writer/device_writer.cc +++ b/tools/writer/device_writer.cc @@ -15,14 +15,13 @@ #include -#include - #include #include #include "mynteye/device.h" #include "mynteye/files.h" #include "mynteye/types.h" +#include "mynteye/logger.h" #include "internal/types.h" @@ -230,16 +229,16 @@ void DeviceWriter::SaveAllInfos(const std::string &dir) { if (!files::mkdir(dir)) { LOG(FATAL) << "Create directory failed: " << dir; } - SaveDeviceInfo(*device_->GetInfo(), dir + OS_SEP "device.info"); + SaveDeviceInfo(*device_->GetInfo(), dir + MYNTEYE_OS_SEP "device.info"); SaveImgParams( - *device_->GetInfo(), device_->GetImgParams(), dir + OS_SEP "img.params"); + *device_->GetInfo(), device_->GetImgParams(), dir + MYNTEYE_OS_SEP "img.params"); auto &&m_in = device_->GetMotionIntrinsics(); SaveImuParams( { false, m_in.accel, m_in.gyro, device_->GetMotionExtrinsics(Stream::LEFT), }, - dir + OS_SEP "imu.params"); + dir + MYNTEYE_OS_SEP "imu.params"); } namespace { diff --git a/tools/writer/save_all_infos.cc b/tools/writer/save_all_infos.cc index a4ff051..2823268 100644 --- a/tools/writer/save_all_infos.cc +++ b/tools/writer/save_all_infos.cc @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { if (!device) return 1; - dir.append(OS_SEP "SN").append(device->GetInfo()->serial_number); + dir.append(MYNTEYE_OS_SEP "SN").append(device->GetInfo()->serial_number); tools::DeviceWriter writer(device); writer.SaveAllInfos(dir); diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index 4cecbff..fd4c11c 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,23 @@ 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 +104,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/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt index a8ef045..79cb94a 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,21 @@ 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_nodelet.cc b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc index dd33f48..6037d19 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 @@ -26,8 +26,6 @@ #include #include -#include - #define _USE_MATH_DEFINES #include #include @@ -36,6 +34,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)