From 1a3cc91c8c3a2f6c2c7ddd714df0d5f0fdcb1510 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 28 Nov 2022 19:16:32 +0200 Subject: [PATCH 1/6] added LIBREALSENSE_ELPP_ID, configure_elpp_logger --- src/ds5/ds5-private.h | 2 +- src/gl/rs-gl.cpp | 2 +- src/ipDeviceCommon/NetdevLog.h | 8 ++-- src/ipDeviceCommon/RsUsageEnvironment.cpp | 4 +- src/linux/backend-hid.cpp | 2 +- src/linux/backend-v4l2.h | 2 +- src/log.cpp | 2 +- .../utilities/easylogging/easyloggingpp.h | 25 ++++++++-- .../utilities/src/configure-elpp-logger.cpp | 48 +++++++++++++++++++ unit-tests/log/test-vs-LOG-shared.cpp | 3 +- unit-tests/log/test-vs-LOG-static.cpp | 8 ++-- 11 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 third-party/utilities/src/configure-elpp-logger.cpp diff --git a/src/ds5/ds5-private.h b/src/ds5/ds5-private.h index 1127e124a9..ccb47dea29 100644 --- a/src/ds5/ds5-private.h +++ b/src/ds5/ds5-private.h @@ -13,7 +13,7 @@ //#define DEBUG_THERMAL_LOOP #ifdef DEBUG_THERMAL_LOOP -#define LOG_DEBUG_THERMAL_LOOP(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false) +#define LOG_DEBUG_THERMAL_LOOP(...) do { CLOG(WARNING ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) #else #define LOG_DEBUG_THERMAL_LOOP(...) #endif //DEBUG_THERMAL_LOOP diff --git a/src/gl/rs-gl.cpp b/src/gl/rs-gl.cpp index 7edff5bdd2..7b6276a326 100644 --- a/src/gl/rs-gl.cpp +++ b/src/gl/rs-gl.cpp @@ -272,7 +272,7 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version) #ifdef SHARED_LIBS INITIALIZE_EASYLOGGINGPP #endif -char log_gl_name[] = "librealsense"; +char log_gl_name[] = LIBREALSENSE_ELPP_ID; static logger_type logger_gl; #endif diff --git a/src/ipDeviceCommon/NetdevLog.h b/src/ipDeviceCommon/NetdevLog.h index 7d229ef86f..5731a10e09 100644 --- a/src/ipDeviceCommon/NetdevLog.h +++ b/src/ipDeviceCommon/NetdevLog.h @@ -5,7 +5,7 @@ #include -#define DBG CLOG(DEBUG, "librealsense") -#define ERR CLOG(ERROR, "librealsense") -#define WRN CLOG(WARNING, "librealsense") -#define INF CLOG(INFO, "librealsense") +#define DBG CLOG(DEBUG, LIBREALSENSE_ELPP_ID) +#define ERR CLOG(ERROR, LIBREALSENSE_ELPP_ID) +#define WRN CLOG(WARNING, LIBREALSENSE_ELPP_ID) +#define INF CLOG(INFO, LIBREALSENSE_ELPP_ID) diff --git a/src/ipDeviceCommon/RsUsageEnvironment.cpp b/src/ipDeviceCommon/RsUsageEnvironment.cpp index 6926a851b6..19ca32cb09 100644 --- a/src/ipDeviceCommon/RsUsageEnvironment.cpp +++ b/src/ipDeviceCommon/RsUsageEnvironment.cpp @@ -17,7 +17,7 @@ RSUsageEnvironment::~RSUsageEnvironment() { CLOG(INFO, "netdev") << "RealSense network logging closed"; - el::Loggers::unregisterLogger("librealsense"); + el::Loggers::unregisterLogger(LIBREALSENSE_ELPP_ID); el::Loggers::unregisterLogger("netdev"); } @@ -29,7 +29,7 @@ RSUsageEnvironment* RSUsageEnvironment::createNew(TaskScheduler& taskScheduler) { env->ptr = env->buffer; env->netdev_log = el::Loggers::getLogger("netdev"); - env->lrs_log = el::Loggers::getLogger("librealsense"); + env->lrs_log = el::Loggers::getLogger(LIBREALSENSE_ELPP_ID); el::Loggers::reconfigureAllLoggers(el::Level::Global, el::ConfigurationType::Format, "%datetime{%y%M%d%H%m%s.%g} [%logger]\t%levshort: %msg"); el::Loggers::reconfigureAllLoggers(el::Level::Debug, el::ConfigurationType::Enabled, "false"); diff --git a/src/linux/backend-hid.cpp b/src/linux/backend-hid.cpp index ab7c057294..9c63ab4b1a 100644 --- a/src/linux/backend-hid.cpp +++ b/src/linux/backend-hid.cpp @@ -26,7 +26,7 @@ const std::string HID_CUSTOM_PATH("/sys/bus/platform/drivers/hid_sensor_custom") //#define DEBUG_HID #ifdef DEBUG_HID -#define LOG_DEBUG_HID(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false) +#define LOG_DEBUG_HID(...) do { CLOG(DEBUG ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) #else #define LOG_DEBUG_HID(...) #endif //DEBUG_HID diff --git a/src/linux/backend-v4l2.h b/src/linux/backend-v4l2.h index ed7d380573..17fdb0e504 100644 --- a/src/linux/backend-v4l2.h +++ b/src/linux/backend-v4l2.h @@ -63,7 +63,7 @@ constexpr bool metadata_node = false; #undef DEBUG_V4L #ifdef DEBUG_V4L -#define LOG_DEBUG_V4L(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false) +#define LOG_DEBUG_V4L(...) do { CLOG(DEBUG ,LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) #else #define LOG_DEBUG_V4L(...) #endif //DEBUG_V4L diff --git a/src/log.cpp b/src/log.cpp index 389edf9bef..8751d6fd5f 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -10,7 +10,7 @@ INITIALIZE_EASYLOGGINGPP namespace librealsense { - char log_name[] = "librealsense"; + char log_name[] = LIBREALSENSE_ELPP_ID; static logger_type logger; } diff --git a/third-party/utilities/include/utilities/easylogging/easyloggingpp.h b/third-party/utilities/include/utilities/easylogging/easyloggingpp.h index 2ea356fe62..964d9ae12a 100644 --- a/third-party/utilities/include/utilities/easylogging/easyloggingpp.h +++ b/third-party/utilities/include/utilities/easylogging/easyloggingpp.h @@ -22,6 +22,9 @@ #include +#define LIBREALSENSE_ELPP_ID "librealsense" + + #ifdef __ANDROID__ #include #include @@ -40,11 +43,23 @@ #else //__ANDROID__ -#define LOG_DEBUG(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false) -#define LOG_INFO(...) do { CLOG(INFO ,"librealsense") << __VA_ARGS__; } while(false) -#define LOG_WARNING(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false) -#define LOG_ERROR(...) do { CLOG(ERROR ,"librealsense") << __VA_ARGS__; } while(false) -#define LOG_FATAL(...) do { CLOG(FATAL ,"librealsense") << __VA_ARGS__; } while(false) +#define LOG_DEBUG(...) do { CLOG(DEBUG , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) +#define LOG_INFO(...) do { CLOG(INFO , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) +#define LOG_WARNING(...) do { CLOG(WARNING , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) +#define LOG_ERROR(...) do { CLOG(ERROR , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) +#define LOG_FATAL(...) do { CLOG(FATAL , LIBREALSENSE_ELPP_ID) << __VA_ARGS__; } while(false) + +namespace utilities { + + +// Configure the same logger as librealsense (by default), to disable/enable debug output +void configure_elpp_logger( bool enable_debug = false, + std::string const & nested_indent = "", + std::string const & logger_id = LIBREALSENSE_ELPP_ID ); + + +} // namespace utilities + #endif // __ANDROID__ diff --git a/third-party/utilities/src/configure-elpp-logger.cpp b/third-party/utilities/src/configure-elpp-logger.cpp new file mode 100644 index 0000000000..cdee73b175 --- /dev/null +++ b/third-party/utilities/src/configure-elpp-logger.cpp @@ -0,0 +1,48 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2022 Intel Corporation. All Rights Reserved. + +#ifdef BUILD_EASYLOGGINGPP +#include + +namespace utilities { + + +void configure_elpp_logger( bool enable_debug, std::string const & nested_indent, std::string const & logger_id ) +{ + el::Configurations defaultConf; + + el::Logger * logger = el::Loggers::getLogger( logger_id ); + el::Configurations * configs; + if( logger ) + { + configs = logger->configurations(); + } + else + { + // First initialization + defaultConf.setToDefault(); + defaultConf.setGlobally( el::ConfigurationType::ToStandardOutput, "false" ); + defaultConf.set( el::Level::Error, el::ConfigurationType::ToStandardOutput, "true" ); + configs = &defaultConf; + } + + std::string format = "-%levshort- %datetime{%H:%m:%s.%g} %msg (%fbase:%line [%thread])"; + if( ! nested_indent.empty() ) + format = '[' + nested_indent + "] " + format; + configs->setGlobally( el::ConfigurationType::Format, format ); + + auto enable_str = enable_debug ? "true" : "false"; + configs->set( el::Level::Warning, el::ConfigurationType::ToStandardOutput, enable_str ); + configs->set( el::Level::Info, el::ConfigurationType::ToStandardOutput, enable_str ); + configs->set( el::Level::Debug, el::ConfigurationType::ToStandardOutput, enable_str ); + + if( logger ) + logger->reconfigure(); + else + el::Loggers::reconfigureLogger( logger_id, defaultConf ); +} + + +} // namespace utilities + +#endif // BUILD_EASYLOGGINGPP diff --git a/unit-tests/log/test-vs-LOG-shared.cpp b/unit-tests/log/test-vs-LOG-shared.cpp index 20521813c6..7379e20de1 100644 --- a/unit-tests/log/test-vs-LOG-shared.cpp +++ b/unit-tests/log/test-vs-LOG-shared.cpp @@ -70,8 +70,7 @@ TEST_CASE_METHOD( test_fixture, "rs2::log vs LOG()", "[log]" ) { REQUIRE( n_callbacks_our == 1 ); } SECTION( "our logger is separate from librealsense logger" ) { - // ("librealsense" is the name of the LRS logger; look in log.cpp) - CLOG( INFO, "librealsense" ) << "LOG() message to \"librealsense\" logger"; + CLOG( INFO, LIBREALSENSE_ELPP_ID ) << "LOG() message to \"librealsense\" logger"; REQUIRE( n_callbacks_lrs == 0 ); REQUIRE( n_callbacks_our == 1 ); } diff --git a/unit-tests/log/test-vs-LOG-static.cpp b/unit-tests/log/test-vs-LOG-static.cpp index 86ec5af617..eb4e5fe6a2 100644 --- a/unit-tests/log/test-vs-LOG-static.cpp +++ b/unit-tests/log/test-vs-LOG-static.cpp @@ -33,7 +33,8 @@ TEST_CASE( "rs2_log vs LOG() - internal", "[log]" ) protected: void handle( const el::LogDispatchData* data ) noexcept override { - (*pn_callbacks)++; + if( pn_callbacks ) + (*pn_callbacks)++; TRACE( data->logMessage()->logger()->logBuilder()->build( data->logMessage(), true )); } }; @@ -47,15 +48,12 @@ TEST_CASE( "rs2_log vs LOG() - internal", "[log]" ) LOG(INFO) << "Log message to default logger"; REQUIRE( n_callbacks == 1 ); - // CLOG(XXX,"librealsense") is the librealsense logger - CLOG(INFO, "librealsense") << "Log message to \"librealsense\" logger"; + CLOG(INFO, LIBREALSENSE_ELPP_ID) << "Log message to \"librealsense\" logger"; REQUIRE( n_callbacks == 2 ); - // LOG_XXX() is same as CLOG( ..., "librealsense" ) LOG_INFO( "Log message using LOG_INFO()" ); REQUIRE( n_callbacks == 3 ); - // LOG_XXX() is same as CLOG( ..., "librealsense" ) REQUIRE_NOTHROW( rs2_log( RS2_LOG_SEVERITY_INFO, "Log message using rs2_log()", nullptr )); REQUIRE( n_callbacks == 4 ); From 13fc8196c121650e857a6fc8f019d444b94aa3ff Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 28 Nov 2022 21:49:56 +0200 Subject: [PATCH 2/6] utilities files now in tree; shared-init -> elpp-init auto use in dependents --- third-party/utilities/CMakeLists.txt | 27 ++++++++++++++----- .../utilities/easylogging/elpp-init.cpp | 17 ++++++++++++ .../utilities/easylogging/shared-init.cmake | 10 ------- .../utilities/easylogging/shared-init.cpp | 12 --------- 4 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 third-party/utilities/include/utilities/easylogging/elpp-init.cpp delete mode 100644 third-party/utilities/include/utilities/easylogging/shared-init.cmake delete mode 100644 third-party/utilities/include/utilities/easylogging/shared-init.cpp diff --git a/third-party/utilities/CMakeLists.txt b/third-party/utilities/CMakeLists.txt index 56253a9efa..33e96b9aa7 100644 --- a/third-party/utilities/CMakeLists.txt +++ b/third-party/utilities/CMakeLists.txt @@ -1,6 +1,6 @@ # License: Apache 2.0. See LICENSE file in root directory. # Copyright(c) 2022 Intel Corporation. All Rights Reserved. - +cmake_minimum_required(VERSION 3.8.0) # source_group(TREE) project( utilities ) add_library( ${PROJECT_NAME} STATIC "" ) @@ -20,11 +20,14 @@ file(GLOB_RECURSE UTILITIES_HEADER_FILES "${UTILITIES_INCLUDE_DIR}/*.h" ) if( BUILD_EASYLOGGINGPP ) - list( APPEND UTILITIES_HEADER_FILES - "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.h" - ) + target_sources( ${PROJECT_NAME} + PRIVATE "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.h" ) endif() target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_HEADER_FILES} ) +source_group( + TREE ${UTILITIES_INCLUDE_DIR} + PREFIX "Header Files" + FILES ${UTILITIES_HEADER_FILES} ) # Sources ----------------------------------------------------------------------------------- @@ -36,11 +39,21 @@ file(GLOB_RECURSE UTILITIES_SOURCE_FILES "${UTILITIES_SRC_DIR}/*" ) if( BUILD_EASYLOGGINGPP ) - list( APPEND UTILITIES_SOURCE_FILES - "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.cc" - ) + target_sources( ${PROJECT_NAME} + PRIVATE "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.cc" ) + # EasyLogging++ initialization needs to happen in any client of ours, or else + # they will not have a working instance. This .cpp file will be automatically + # added to any dependent target, but the initialization can be disabled with + # NO_ELPP_INIT in the target makefile, e.g.: + # target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) + target_sources( ${PROJECT_NAME} + PUBLIC $ ) endif() target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_SOURCE_FILES} ) +source_group( + TREE ${UTILITIES_SRC_DIR} + PREFIX "Source Files" + FILES ${UTILITIES_SOURCE_FILES} ) # Install ----------------------------------------------------------------------------------- diff --git a/third-party/utilities/include/utilities/easylogging/elpp-init.cpp b/third-party/utilities/include/utilities/easylogging/elpp-init.cpp new file mode 100644 index 0000000000..dfd0ee69ac --- /dev/null +++ b/third-party/utilities/include/utilities/easylogging/elpp-init.cpp @@ -0,0 +1,17 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2022 Intel Corporation. All Rights Reserved. + +#ifdef BUILD_EASYLOGGINGPP +#ifndef NO_ELPP_INIT +#include + +// ELPP requires static initialization, otherwise nothing will work: +// +INITIALIZE_EASYLOGGINGPP +// +// The above can be disabled with NO_ELPP_INIT! This is needed in special cases such as librealsense +// where other static initialization is used to automatically set up the logging mechanism based on +// environment variables. + +#endif // ! NO_ELPP_INIT +#endif // BUILD_EASYLOGGINGPP diff --git a/third-party/utilities/include/utilities/easylogging/shared-init.cmake b/third-party/utilities/include/utilities/easylogging/shared-init.cmake deleted file mode 100644 index c2d65229ec..0000000000 --- a/third-party/utilities/include/utilities/easylogging/shared-init.cmake +++ /dev/null @@ -1,10 +0,0 @@ -# License: Apache 2.0. See LICENSE file in root directory. -# Copyright(c) 2022 Intel Corporation. All Rights Reserved. - -if( BUILD_EASYLOGGINGPP AND BUILD_SHARED_LIBS ) - set( ELPP_SOURCES - ${CMAKE_CURRENT_LIST_DIR}/shared-init.cpp - ) - target_sources( ${PROJECT_NAME} PRIVATE ${ELPP_SOURCES} ) - source_group( "Common Files" FILES ${ELPP_SOURCES} ) -endif() diff --git a/third-party/utilities/include/utilities/easylogging/shared-init.cpp b/third-party/utilities/include/utilities/easylogging/shared-init.cpp deleted file mode 100644 index 17bf58b45e..0000000000 --- a/third-party/utilities/include/utilities/easylogging/shared-init.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2022 Intel Corporation. All Rights Reserved. - -#ifdef BUILD_EASYLOGGINGPP -#include -#ifdef BUILD_SHARED_LIBS -// With static linkage, ELPP is initialized by librealsense, so doing it here will -// create errors. When we're using the shared .so/.dll, the two are separate and we have -// to initialize ours if we want to use the APIs! -INITIALIZE_EASYLOGGINGPP -#endif -#endif \ No newline at end of file From 082cb0798346a201a1157cb2a54c00f215bbc046 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 28 Nov 2022 21:47:35 +0200 Subject: [PATCH 3/6] librs uses NO_ELPP_INIT; dependents, too, in static --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c20acd4da..067deac9d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,14 @@ include(src/CMakeLists.txt) include(third-party/CMakeLists.txt) include(common/utilities/CMakeLists.txt) -target_link_libraries( ${LRS_TARGET} PRIVATE utilities ) +target_link_libraries( ${LRS_TARGET} PUBLIC utilities ) +# librealsense does its own INITIALIZE_EASYLOGGINGPP and moving it to utilities won't work (static code +# initialization order gets fubar - see src/log.cpp). So disable any automatic initialization for us: +target_compile_definitions( ${LRS_TARGET} PRIVATE NO_ELPP_INIT ) +if( NOT BUILD_SHARED_LIBS ) + # Static linkage will use our ELPP so no need to initialize in any target, either: + target_compile_definitions( ${LRS_TARGET} INTERFACE NO_ELPP_INIT ) +endif() # configure the project according to OS specific requirments # macro definition located at "CMake/_config.cmake" From 97294a6b01ab80b51d3549c344e5002a33215814 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 28 Nov 2022 21:48:40 +0200 Subject: [PATCH 4/6] update all dependent projects --- CMake/opengl_config.cmake | 2 +- src/compression/CMakeLists.txt | 2 +- src/ethernet/CMakeLists.txt | 11 +++++--- src/gl/CMakeLists.txt | 3 +++ third-party/utilities/py/CMakeLists.txt | 2 -- third-party/utilities/py/pyrsutils.cpp | 34 +++++-------------------- tools/CMakeLists.txt | 2 +- tools/depth-quality/CMakeLists.txt | 2 -- tools/realsense-viewer/CMakeLists.txt | 2 -- tools/rs-server/CMakeLists.txt | 15 ++++++----- unit-tests/CMakeLists.txt | 2 +- unit-tests/unit-test-config.py | 2 -- wrappers/CMakeLists.txt | 2 +- wrappers/python/CMakeLists.txt | 4 +++ 14 files changed, 34 insertions(+), 51 deletions(-) diff --git a/CMake/opengl_config.cmake b/CMake/opengl_config.cmake index 08517f68b1..3c75caf036 100644 --- a/CMake/opengl_config.cmake +++ b/CMake/opengl_config.cmake @@ -1,2 +1,2 @@ find_package(OpenGL REQUIRED) -set(DEPENDENCIES realsense2 utilities glfw ${OPENGL_LIBRARIES}) +set(DEPENDENCIES realsense2 glfw ${OPENGL_LIBRARIES}) diff --git a/src/compression/CMakeLists.txt b/src/compression/CMakeLists.txt index 7ef96f3dec..5e148228b1 100644 --- a/src/compression/CMakeLists.txt +++ b/src/compression/CMakeLists.txt @@ -7,7 +7,7 @@ project(realsense2-compression VERSION 1.0.0 LANGUAGES CXX C) # Save the command line compile commands in the build output set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -list( APPEND DEPENDENCIES realsense2 utilities ) +list( APPEND DEPENDENCIES realsense2 ) file(GLOB COMPRESSION_SOURCES "*.h" diff --git a/src/ethernet/CMakeLists.txt b/src/ethernet/CMakeLists.txt index 221523a787..192e8ca6ee 100644 --- a/src/ethernet/CMakeLists.txt +++ b/src/ethernet/CMakeLists.txt @@ -73,14 +73,17 @@ if(WIN32) endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") add_definitions(-DELPP_WINSOCK2) - + set(WINLIB Ws2_32.lib) endif() set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) -target_link_libraries(${PROJECT_NAME} - PRIVATE ${WINLIB} realsense2 realsense2-compression utilities +# We initialize ELPP ourselves -- no need to do it elsewhere (see rs-gl.cpp) +target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) + +target_link_libraries(${PROJECT_NAME} + PRIVATE ${WINLIB} realsense2 realsense2-compression ) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Library) @@ -89,7 +92,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${REALSENSE_VERSION_STR # set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) WRITE_BASIC_CONFIG_VERSION_FILE("${CMAKE_CURRENT_BINARY_DIR}/realsense2-netConfigVersion.cmake" - VERSION ${REALSENSE_VERSION_STRING} + VERSION ${REALSENSE_VERSION_STRING} COMPATIBILITY AnyNewerVersion ) diff --git a/src/gl/CMakeLists.txt b/src/gl/CMakeLists.txt index a6cd8e17b7..0908d41484 100644 --- a/src/gl/CMakeLists.txt +++ b/src/gl/CMakeLists.txt @@ -88,6 +88,9 @@ configure_package_config_file(../../CMake/realsense2-glConfig.cmake.in realsense configure_file(../../config/librealsense-gl.pc.in ../../config/realsense2-gl.pc @ONLY) +# We initialize ELPP ourselves -- no need to do it elsewhere (see rs-gl.cpp) +target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) + target_link_libraries( ${PROJECT_NAME} PRIVATE ${DEPENDENCIES} diff --git a/third-party/utilities/py/CMakeLists.txt b/third-party/utilities/py/CMakeLists.txt index f7c03659cd..3cf77ce6a3 100644 --- a/third-party/utilities/py/CMakeLists.txt +++ b/third-party/utilities/py/CMakeLists.txt @@ -23,8 +23,6 @@ set_target_properties( ${PROJECT_NAME} PROJECT_LABEL utilities-py ) -include("../include/utilities/easylogging/shared-init.cmake") - install( TARGETS ${PROJECT_NAME} EXPORT pyrealsense2Targets diff --git a/third-party/utilities/py/pyrsutils.cpp b/third-party/utilities/py/pyrsutils.cpp index 577fad18a6..f6f334c9bf 100644 --- a/third-party/utilities/py/pyrsutils.cpp +++ b/third-party/utilities/py/pyrsutils.cpp @@ -9,41 +9,19 @@ #define SNAME "pyrsutils" -#ifndef BUILD_SHARED_LIBS // shared-init takes care of the else -INITIALIZE_EASYLOGGINGPP -#endif - - PYBIND11_MODULE(NAME, m) { m.doc() = R"pbdoc( RealSense Utilities Python Bindings )pbdoc"; m.attr( "__version__" ) = "0.1"; // RS2_API_VERSION_STR; - // Configure the same logger as librealsense, and default to only errors by default... - el::Configurations defaultConf; - defaultConf.setToDefault(); - defaultConf.setGlobally( el::ConfigurationType::ToStandardOutput, "false" ); - defaultConf.set( el::Level::Error, el::ConfigurationType::ToStandardOutput, "true" ); - defaultConf.setGlobally( el::ConfigurationType::Format, "-%levshort- %datetime{%H:%m:%s.%g} %msg (%fbase:%line [%thread])" ); - el::Loggers::reconfigureLogger( "librealsense", defaultConf ); + utilities::configure_elpp_logger(); - m.def( - "debug", - []( bool enable, std::string const & nested ) { - el::Logger * logger = el::Loggers::getLogger( "librealsense" ); - auto configs = logger->configurations(); - configs->set( el::Level::Warning, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" ); - configs->set( el::Level::Info, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" ); - configs->set( el::Level::Debug, el::ConfigurationType::ToStandardOutput, enable ? "true" : "false" ); - std::string format = "-%levshort- %datetime{%H:%m:%s.%g} %msg (%fbase:%line [%thread])"; - if( ! nested.empty() ) - format = '[' + nested + "] " + format; - configs->setGlobally( el::ConfigurationType::Format, format ); - logger->reconfigure(); - }, - py::arg( "enable" ), - py::arg( "nested-string" ) = "" ); + m.def( "debug", + &utilities::configure_elpp_logger, + py::arg( "enable" ), + py::arg( "nested-string" ) = "", + py::arg( "logger" ) = LIBREALSENSE_ELPP_ID ); m.def( "split", &utilities::string::split ); } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 37a9d914db..9a7622c9fb 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # View the makefile commands during build #set(CMAKE_VERBOSE_MAKEFILE on) -list(APPEND DEPENDENCIES realsense2 utilities) +list(APPEND DEPENDENCIES realsense2) if(BUILD_TOOLS) add_subdirectory(convert) diff --git a/tools/depth-quality/CMakeLists.txt b/tools/depth-quality/CMakeLists.txt index dcc6ad3ce1..6ac0e7aaa5 100644 --- a/tools/depth-quality/CMakeLists.txt +++ b/tools/depth-quality/CMakeLists.txt @@ -17,8 +17,6 @@ find_package(Threads REQUIRED) include_directories(${CMAKE_BINARY_DIR}) -include("${REPO_ROOT}/third-party/utilities/include/utilities/easylogging/shared-init.cmake") - include(../../common/CMakeLists.txt) SET(DELAYED diff --git a/tools/realsense-viewer/CMakeLists.txt b/tools/realsense-viewer/CMakeLists.txt index cedb2aceef..737317125f 100644 --- a/tools/realsense-viewer/CMakeLists.txt +++ b/tools/realsense-viewer/CMakeLists.txt @@ -16,8 +16,6 @@ find_package(Threads REQUIRED) include_directories(${CMAKE_BINARY_DIR}) -include("${REPO_ROOT}/third-party/utilities/include/utilities/easylogging/shared-init.cmake") - include(../../common/CMakeLists.txt) if(BUILD_GRAPHICAL_EXAMPLES) diff --git a/tools/rs-server/CMakeLists.txt b/tools/rs-server/CMakeLists.txt index cf9d942f64..3835590219 100644 --- a/tools/rs-server/CMakeLists.txt +++ b/tools/rs-server/CMakeLists.txt @@ -43,22 +43,25 @@ else() ../../include/librealsense2 ../../third-party/tclap/include ../../third-party/easyloggingpp/src - ${LIVE}/groupsock/include - ${LIVE}/liveMedia/include - ${LIVE}/UsageEnvironment/include - ${LIVE}/BasicUsageEnvironment/include + ${LIVE}/groupsock/include + ${LIVE}/liveMedia/include + ${LIVE}/UsageEnvironment/include + ${LIVE}/BasicUsageEnvironment/include ) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) set(DEPENDENCIES ${DEPENDENCIES} realsense2 Threads::Threads realsense2-compression ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES}) - + target_link_libraries(${PROJECT_NAME} ${DEPENDENCIES}) - + set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "Tools") target_compile_definitions(${PROJECT_NAME} PUBLIC RESPONSE_BUFFER_SIZE=100000) + # We initialize ELPP ourselves -- no need to do it elsewhere (see src/ipDeviceCommon/RsUsageEnvironment.cpp) + target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) + install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt index 4f95917951..bb674c6354 100644 --- a/unit-tests/CMakeLists.txt +++ b/unit-tests/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1.0) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -set(DEPENDENCIES realsense2 utilities) +set(DEPENDENCIES realsense2) find_package (Python3 COMPONENTS Interpreter Development) if (NOT ${BUILD_EASYLOGGINGPP}) diff --git a/unit-tests/unit-test-config.py b/unit-tests/unit-test-config.py index ef3cf5263c..ad902020ec 100644 --- a/unit-tests/unit-test-config.py +++ b/unit-tests/unit-test-config.py @@ -99,8 +99,6 @@ def generate_cmake( builddir, testdir, testname, filelist, custom_main ): set_target_properties( ''' + testname + ''' PROPERTIES FOLDER "Unit-Tests/''' + os.path.dirname( testdir ) + '''" ) -include( "${REPO_ROOT}/third-party/utilities/include/utilities/easylogging/shared-init.cmake" ) - # Add the repo root directory (so includes into src/ will be specific: ) target_include_directories(''' + testname + ''' PRIVATE ''' + root + ''') diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index 445785f365..473d3033e9 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.1.0) project(RealsenseWrappers) -set(DEPENDENCIES realsense2 utilities) +set(DEPENDENCIES realsense2) if (BUILD_PYTHON_BINDINGS OR BUILD_PYTHON_DOCS) if (NOT INTERNET_CONNECTION) diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index 3ce7d991c0..bd9013a475 100644 --- a/wrappers/python/CMakeLists.txt +++ b/wrappers/python/CMakeLists.txt @@ -141,6 +141,10 @@ set_target_properties( pybackend2 ) target_include_directories(pybackend2 PRIVATE ${CMAKE_SOURCE_DIR}/include) +# Since we're not dependent on realsense2 but rather include all its sources, we have to make +# sure we do not initialize ELPP again: +target_compile_definitions( pybackend2 PRIVATE NO_ELPP_INIT ) + if(${FORCE_RSUSB_BACKEND}) if(APPLE) target_include_directories(pybackend2 PRIVATE ${CMAKE_SOURCE_DIR}/third-party/hidapi/) From 2bd25438d31713fe65434406245f3e6e17f37570 Mon Sep 17 00:00:00 2001 From: Eran Date: Tue, 29 Nov 2022 10:41:27 +0200 Subject: [PATCH 5/6] fixed some warnings --- src/ds5/ds5-options.h | 2 +- src/fw-update/fw-update-device-interface.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ds5/ds5-options.h b/src/ds5/ds5-options.h index fe60bfbb96..e8b133021a 100644 --- a/src/ds5/ds5-options.h +++ b/src/ds5/ds5-options.h @@ -242,7 +242,7 @@ namespace librealsense virtual float query() const override; virtual option_range get_range() const override; virtual bool is_enabled() const override { return true; } - virtual bool is_read_only() const { return _sensor && _sensor->is_opened(); } + virtual bool is_read_only() const override { return _sensor && _sensor->is_opened(); } const char* get_description() const override; void enable_recording(std::function record_action) override diff --git a/src/fw-update/fw-update-device-interface.h b/src/fw-update/fw-update-device-interface.h index f3f7d424c5..046daa2e09 100644 --- a/src/fw-update/fw-update-device-interface.h +++ b/src/fw-update/fw-update-device-interface.h @@ -17,7 +17,7 @@ namespace librealsense { auto version_offset = offsetof(platform::dfu_header, bcdDevice); if (fw_image.size() < (version_offset + sizeof(size_t))) - throw std::runtime_error("Firmware binary image might be corrupted - size is only: " + fw_image.size()); + throw std::runtime_error("Firmware binary image might be corrupted - size is only: " + std::to_string( fw_image.size() )); auto version = fw_image.data() + version_offset; uint8_t major = *(version + 3); From 103b7b4249997725d6c714927e196366107a6271 Mon Sep 17 00:00:00 2001 From: Eran Date: Wed, 30 Nov 2022 12:10:39 +0200 Subject: [PATCH 6/6] revert NO_ELPP_INIT -> using_easylogging() instead --- CMakeLists.txt | 7 ---- src/ethernet/CMakeLists.txt | 3 -- src/gl/CMakeLists.txt | 3 -- third-party/utilities/CMakeLists.txt | 43 +++++++++++++++++++++---- third-party/utilities/py/CMakeLists.txt | 2 ++ tools/depth-quality/CMakeLists.txt | 2 ++ tools/realsense-viewer/CMakeLists.txt | 2 ++ tools/rs-server/CMakeLists.txt | 3 -- unit-tests/unit-test-config.py | 2 ++ wrappers/python/CMakeLists.txt | 4 --- 10 files changed, 44 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 067deac9d0..92335940f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,13 +66,6 @@ include(third-party/CMakeLists.txt) include(common/utilities/CMakeLists.txt) target_link_libraries( ${LRS_TARGET} PUBLIC utilities ) -# librealsense does its own INITIALIZE_EASYLOGGINGPP and moving it to utilities won't work (static code -# initialization order gets fubar - see src/log.cpp). So disable any automatic initialization for us: -target_compile_definitions( ${LRS_TARGET} PRIVATE NO_ELPP_INIT ) -if( NOT BUILD_SHARED_LIBS ) - # Static linkage will use our ELPP so no need to initialize in any target, either: - target_compile_definitions( ${LRS_TARGET} INTERFACE NO_ELPP_INIT ) -endif() # configure the project according to OS specific requirments # macro definition located at "CMake/_config.cmake" diff --git a/src/ethernet/CMakeLists.txt b/src/ethernet/CMakeLists.txt index 192e8ca6ee..74c052ed48 100644 --- a/src/ethernet/CMakeLists.txt +++ b/src/ethernet/CMakeLists.txt @@ -79,9 +79,6 @@ endif() set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) -# We initialize ELPP ourselves -- no need to do it elsewhere (see rs-gl.cpp) -target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) - target_link_libraries(${PROJECT_NAME} PRIVATE ${WINLIB} realsense2 realsense2-compression ) diff --git a/src/gl/CMakeLists.txt b/src/gl/CMakeLists.txt index 0908d41484..a6cd8e17b7 100644 --- a/src/gl/CMakeLists.txt +++ b/src/gl/CMakeLists.txt @@ -88,9 +88,6 @@ configure_package_config_file(../../CMake/realsense2-glConfig.cmake.in realsense configure_file(../../config/librealsense-gl.pc.in ../../config/realsense2-gl.pc @ONLY) -# We initialize ELPP ourselves -- no need to do it elsewhere (see rs-gl.cpp) -target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) - target_link_libraries( ${PROJECT_NAME} PRIVATE ${DEPENDENCIES} diff --git a/third-party/utilities/CMakeLists.txt b/third-party/utilities/CMakeLists.txt index 33e96b9aa7..03e4efe901 100644 --- a/third-party/utilities/CMakeLists.txt +++ b/third-party/utilities/CMakeLists.txt @@ -41,13 +41,6 @@ file(GLOB_RECURSE UTILITIES_SOURCE_FILES if( BUILD_EASYLOGGINGPP ) target_sources( ${PROJECT_NAME} PRIVATE "${REPO_ROOT}/third-party/easyloggingpp/src/easylogging++.cc" ) - # EasyLogging++ initialization needs to happen in any client of ours, or else - # they will not have a working instance. This .cpp file will be automatically - # added to any dependent target, but the initialization can be disabled with - # NO_ELPP_INIT in the target makefile, e.g.: - # target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) - target_sources( ${PROJECT_NAME} - PUBLIC $ ) endif() target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_SOURCE_FILES} ) source_group( @@ -56,6 +49,42 @@ source_group( FILES ${UTILITIES_SOURCE_FILES} ) +# EasyLogging++ uses global variables that need to be declared somewhere. It therefore +# introduces a macro, INITIALIZE_EASYLOGGINGPP, that needs to be inserted in the code. +# If a client of ours wants to use the easylogging macros, they must do this, or they +# can use this macro in their CMake project file: +# +macro( _using_easyloggingpp include_dir ) + # + # using_easyloggingpp( [SHARED | STATIC] ) + # [SHARED] only initialize when BUILD_SHARED_LIBS is ON + # [STATIC] only initialize when BUILD_SHARED_LIBS is OFF + # + # Projects that depend on realsense2 (and want to use ELPP themselves) need [SHARED] + # because realsense2 always includes the initialization. + # + function( using_easyloggingpp target_name ) + set( func_ARGN ARGN ) # otherwise we get the outside macro's ARGN + cmake_parse_arguments( ARG "SHARED;STATIC" "" "" ${${func_ARGN}} ) + if( ARG_STATIC AND ARG_SHARED ) + message( FATAL_ERROR "Can't be both STATIC and SHARED" ) + elseif( ARG_SHARED ) + if( NOT BUILD_SHARED_LIBS ) + return() + endif() + elseif( ARG_STATIC ) + if( BUILD_SHARED_LIBS ) + return() + endif() + endif() + + target_sources( ${target_name} + PRIVATE "${include_dir}/easylogging/elpp-init.cpp" ) + endfunction() +endmacro() +_using_easyloggingpp( ${UTILITIES_INCLUDE_DIR} ) + + # Install ----------------------------------------------------------------------------------- # install( TARGETS ${PROJECT_NAME} diff --git a/third-party/utilities/py/CMakeLists.txt b/third-party/utilities/py/CMakeLists.txt index 3cf77ce6a3..969598f847 100644 --- a/third-party/utilities/py/CMakeLists.txt +++ b/third-party/utilities/py/CMakeLists.txt @@ -23,6 +23,8 @@ set_target_properties( ${PROJECT_NAME} PROJECT_LABEL utilities-py ) +using_easyloggingpp( ${PROJECT_NAME} ) + install( TARGETS ${PROJECT_NAME} EXPORT pyrealsense2Targets diff --git a/tools/depth-quality/CMakeLists.txt b/tools/depth-quality/CMakeLists.txt index 6ac0e7aaa5..08b03234fb 100644 --- a/tools/depth-quality/CMakeLists.txt +++ b/tools/depth-quality/CMakeLists.txt @@ -17,6 +17,8 @@ find_package(Threads REQUIRED) include_directories(${CMAKE_BINARY_DIR}) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) + include(../../common/CMakeLists.txt) SET(DELAYED diff --git a/tools/realsense-viewer/CMakeLists.txt b/tools/realsense-viewer/CMakeLists.txt index 737317125f..ab5a41dc83 100644 --- a/tools/realsense-viewer/CMakeLists.txt +++ b/tools/realsense-viewer/CMakeLists.txt @@ -16,6 +16,8 @@ find_package(Threads REQUIRED) include_directories(${CMAKE_BINARY_DIR}) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) + include(../../common/CMakeLists.txt) if(BUILD_GRAPHICAL_EXAMPLES) diff --git a/tools/rs-server/CMakeLists.txt b/tools/rs-server/CMakeLists.txt index 3835590219..ab8331e68a 100644 --- a/tools/rs-server/CMakeLists.txt +++ b/tools/rs-server/CMakeLists.txt @@ -59,9 +59,6 @@ else() target_compile_definitions(${PROJECT_NAME} PUBLIC RESPONSE_BUFFER_SIZE=100000) - # We initialize ELPP ourselves -- no need to do it elsewhere (see src/ipDeviceCommon/RsUsageEnvironment.cpp) - target_compile_definitions( ${PROJECT_NAME} PRIVATE NO_ELPP_INIT ) - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/unit-tests/unit-test-config.py b/unit-tests/unit-test-config.py index ad902020ec..c54ece4be2 100644 --- a/unit-tests/unit-test-config.py +++ b/unit-tests/unit-test-config.py @@ -99,6 +99,8 @@ def generate_cmake( builddir, testdir, testname, filelist, custom_main ): set_target_properties( ''' + testname + ''' PROPERTIES FOLDER "Unit-Tests/''' + os.path.dirname( testdir ) + '''" ) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) + # Add the repo root directory (so includes into src/ will be specific: ) target_include_directories(''' + testname + ''' PRIVATE ''' + root + ''') diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index bd9013a475..3ce7d991c0 100644 --- a/wrappers/python/CMakeLists.txt +++ b/wrappers/python/CMakeLists.txt @@ -141,10 +141,6 @@ set_target_properties( pybackend2 ) target_include_directories(pybackend2 PRIVATE ${CMAKE_SOURCE_DIR}/include) -# Since we're not dependent on realsense2 but rather include all its sources, we have to make -# sure we do not initialize ELPP again: -target_compile_definitions( pybackend2 PRIVATE NO_ELPP_INIT ) - if(${FORCE_RSUSB_BACKEND}) if(APPLE) target_include_directories(pybackend2 PRIVATE ${CMAKE_SOURCE_DIR}/third-party/hidapi/)