Skip to content

Commit

Permalink
revert NO_ELPP_INIT -> using_easylogging() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Dec 6, 2022
1 parent 2bd2543 commit 103b7b4
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 27 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/<OS>_config.cmake"
Expand Down
3 changes: 0 additions & 3 deletions src/ethernet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
3 changes: 0 additions & 3 deletions src/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
43 changes: 36 additions & 7 deletions third-party/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${UTILITIES_INCLUDE_DIR}/easylogging/elpp-init.cpp> )
endif()
target_sources( ${PROJECT_NAME} PRIVATE ${UTILITIES_SOURCE_FILES} )
source_group(
Expand All @@ -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( <project-name> [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}
Expand Down
2 changes: 2 additions & 0 deletions third-party/utilities/py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ set_target_properties( ${PROJECT_NAME}
PROJECT_LABEL utilities-py
)

using_easyloggingpp( ${PROJECT_NAME} )

install(
TARGETS ${PROJECT_NAME}
EXPORT pyrealsense2Targets
Expand Down
2 changes: 2 additions & 0 deletions tools/depth-quality/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ find_package(Threads REQUIRED)

include_directories(${CMAKE_BINARY_DIR})

using_easyloggingpp( ${PROJECT_NAME} SHARED )

include(../../common/CMakeLists.txt)

SET(DELAYED
Expand Down
2 changes: 2 additions & 0 deletions tools/realsense-viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions tools/rs-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/unit-test-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <src/...>)
target_include_directories(''' + testname + ''' PRIVATE ''' + root + ''')
Expand Down
4 changes: 0 additions & 4 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down

0 comments on commit 103b7b4

Please sign in to comment.