From 103b7b4249997725d6c714927e196366107a6271 Mon Sep 17 00:00:00 2001 From: Eran Date: Wed, 30 Nov 2022 12:10:39 +0200 Subject: [PATCH] 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/)