Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realsense2-gl cmake amendments #3930

Merged
merged 3 commits into from
May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMake/external_libusb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ExternalProject_Add(
GIT_TAG "2a7372db54094a406a755f0b8548b614ba8c78ec" # "v1.0.22" + Mac get_device_list hang fix

UPDATE_COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/third-party/libusb/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/third-party/libusb/CMakeLists.txt
${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb/CMakeLists.txt
PATCH_COMMAND ""

Expand Down
9 changes: 9 additions & 0 deletions CMake/global_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ macro(global_set_flags)
add_definitions(-DELPP_THREAD_SAFE)
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)

if (BUILD_GLSL_EXTENSIONS)
set(LRS_GL_TARGET realsense2-gl)
set(LRS_GL_LIB_NAME ${LRS_GL_TARGET})
endif()

if (ENABLE_ZERO_COPY)
add_definitions(-DZERO_COPY)
endif()
Expand Down Expand Up @@ -58,6 +63,10 @@ macro(global_set_flags)
include(CMake/cuda_config.cmake)
endif()

if(BUILD_PYTHON_BINDINGS)
include(libusb_config)
endif()

add_definitions(-D${BACKEND} -DUNICODE)
endmacro()

Expand Down
4 changes: 2 additions & 2 deletions CMake/install_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/realsense2ConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

install(CODE "execute_process(COMMAND ldconfig)")

# Set library pkgconfig file for facilitating 3rd party integration
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/config/realsense2.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)

install(CODE "execute_process(COMMAND ldconfig)")
2 changes: 1 addition & 1 deletion CMake/libusb_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (NOT TARGET usb)
target_include_directories(usb INTERFACE ${LIBUSB_INC})
target_link_libraries(usb INTERFACE ${LIBUSB_LIB})
else()
include(${CMAKE_SOURCE_DIR}/CMake/external_libusb.cmake)
include(CMake/external_libusb.cmake)
endif()
install(TARGETS usb EXPORT realsense2Targets)
endif()
3 changes: 2 additions & 1 deletion CMake/lrs_options.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option(ENABLE_CCACHE "Build with ccache." ON)
option(BUILD_WITH_CUDA "Enable CUDA" OFF)
option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples and tools." ON)
option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples and tools. Implies BUILD_GLSL_EXTENSIONS" ON)
option(BUILD_GLSL_EXTENSIONS "Build GLSL extensions API" ON)
option(BUILD_WITH_OPENMP "Use OpenMP" OFF)
option(ENABLE_ZERO_COPY "Enable zero copy functionality" OFF)
option(BUILD_WITH_TM2 "Build with support for Intel TM2 tracking device" ON)
Expand Down
12 changes: 12 additions & 0 deletions CMake/realsense2-glConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@

set(realsense2-gl_VERSION_MAJOR "@REALSENSE_VERSION_MAJOR@")
set(realsense2-gl_VERSION_MINOR "@REALSENSE_VERSION_MINOR@")
set(realsense2-gl_VERSION_PATCH "@REALSENSE_VERSION_PATCH@")

set(realsense2-gl_VERSION ${realsense2-gl_VERSION_MAJOR}.${realsense2-gl_VERSION_MINOR}.${realsense2-gl_VERSION_PATCH})

set_and_check(realsense2-gl_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

include("${CMAKE_CURRENT_LIST_DIR}/realsense2-glTargets.cmake")
set(realsense2-gl_LIBRARY realsense2-gl::realsense2-gl)
3 changes: 3 additions & 0 deletions CMake/version_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ assign_version_property(MINOR)
assign_version_property(PATCH)
set(REALSENSE_VERSION_STRING ${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}.${REALSENSE_VERSION_PATCH})
infoValue(REALSENSE_VERSION_STRING)
if (BUILD_GLSL_EXTENSIONS)
set(REALSENSE-GL_VERSION_STRING ${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}.${REALSENSE_VERSION_PATCH})
endif()
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ option(BUILD_CV_KINFU_EXAMPLE "Build OpenCV KinectFusion example" OFF)

add_subdirectory(wrappers)

if (BUILD_EXAMPLES AND BUILD_GRAPHICAL_EXAMPLES)
if (BUILD_EXAMPLES AND BUILD_GLSL_EXTENSIONS)
find_package(glfw3 3.3 QUIET)
if(NOT TARGET glfw)
message(STATUS "GLFW 3.3 not found; using internal version")
set(GLFW_INSTALL ON)
add_subdirectory(third-party/glfw)
endif()
#add_subdirectory(src/gl)
endif()

if(BUILD_EXAMPLES)
Expand All @@ -72,8 +74,9 @@ if (BUILD_WITH_TM2)
add_tm2()
endif()

if (BUILD_EXAMPLES AND BUILD_GRAPHICAL_EXAMPLES)
include(CMake/install_config.cmake)

if (BUILD_EXAMPLES AND BUILD_GLSL_EXTENSIONS)
add_subdirectory(src/gl)
endif()

include(CMake/install_config.cmake)
17 changes: 17 additions & 0 deletions config/librealsense-gl.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
#TODO: libdir=${exec_prefix}/lib@MULTI_ARCH_SUFFIX@
libdir= ${prefix}/lib/x86_64-linux-gnu

Name: realsense2-gl
Description: Intel(R) RealSense(tm) GLSL Extension Module
Version: @REALSENSE-GL_VERSION_STRING@
URL: https://github.com/IntelRealSense/librealsense
Requires.private: @LRS_LIB_NAME@
Libs: -L${libdir} -l@LRS_LIB_NAME@
Libs.private: @LRS_PKG_LIBS@
Cflags: -I${includedir}

#TODO check -Wl -Bdynamic
#Libs: -L${libdir} -Wl,-Bdynamic -lrealsense
82 changes: 65 additions & 17 deletions src/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ set(REALSENSE_GL_CPP
${LZ4_DIR}/lz4.c
)

#set(DEPENDENCIES realsense2 ${OPENGL_LIBRARIES} glfw)
#replaced with
include(${CMAKE_SOURCE_DIR}/CMake/opengl_config.cmake)

if (${BUILD_SHARED_LIBS} AND ${BUILD_EASYLOGGINGPP})
list(APPEND REALSENSE_GL_CPP ../../third-party/easyloggingpp/src/easylogging++.cc)
endif()
Expand All @@ -45,29 +49,73 @@ source_group("API" FILES
../../include/librealsense2-gl/rs_processing_gl.hpp
realsense-gl.def)

add_library(${PROJECT_NAME} ${REALSENSE_GL_CPP})
include_directories(${LZ4_DIR})

find_package(OpenGL)
if(NOT OPENGL_FOUND)
message(FATAL_ERROR "\n\n OpenGL package is missing!\n\n")
endif()
add_library(${LRS_GL_TARGET} ${REALSENSE_GL_CPP})

if(BUILD_SHARED_LIBS)
add_definitions(-DSHARED_LIBS)
endif()

set(DEPENDENCIES realsense2 ${OPENGL_LIBRARIES} glfw)
include_directories(${LZ4_DIR})

target_include_directories(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/.."
"${CMAKE_CURRENT_LIST_DIR}/../../include"
"${CMAKE_CURRENT_LIST_DIR}/../../common/gl/"
"${CMAKE_CURRENT_LIST_DIR}/../../common/"
"${CMAKE_CURRENT_LIST_DIR}/../../third-party/glad"
"${CMAKE_CURRENT_LIST_DIR}/../../third-party/glfw/include"
#TODO - replace glfw dependency with
#find_package(glfw REQUIRED)
target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/..
${CMAKE_CURRENT_LIST_DIR}/../../third-party/glad
${CMAKE_CURRENT_LIST_DIR}/../../common
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/glfw/include>
$<INSTALL_INTERFACE:/../../include>
$<INSTALL_INTERFACE:/../../third-party/glfw/include>
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Library)
target_link_libraries(${PROJECT_NAME} PRIVATE ${DEPENDENCIES})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${REALSENSE_VERSION_STRING} SOVERSION "${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}")
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/realsense2-glConfigVersion.cmake"
VERSION ${REALSENSE_VERSION_STRING} COMPATIBILITY AnyNewerVersion)

configure_package_config_file(../../CMake/realsense2-glConfig.cmake.in realsense2-glConfig.cmake
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/bin
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)

configure_file(../../config/librealsense-gl.pc.in ../../config/realsense2-gl.pc @ONLY)

target_link_libraries(${PROJECT_NAME}
PRIVATE ${DEPENDENCIES}
)

# CMake prior to 3.13 cannot install targets located in sub-directories.
#https://gitlab.kitware.com/cmake/cmake/merge_requests/2152
# Hence these targets will be invoked from the project and not the root directory
install(TARGETS ${LRS_GL_TARGET}
EXPORT realsense2-glTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/librealsense2"
)

install(EXPORT realsense2-glTargets
FILE realsense2-glTargets.cmake
NAMESPACE ${LRS_GL_TARGET}::
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

install(FILES "${CMAKE_BINARY_DIR}/src/gl/realsense2-glConfig.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

install(FILES "${CMAKE_BINARY_DIR}/src/gl/realsense2-glConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

# Set library pkgconfig file for facilitating 3rd party integration
install(FILES "${CMAKE_BINARY_DIR}/config/realsense2-gl.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)

set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/../cmake/realsense2")
install(CODE "execute_process(COMMAND ldconfig)")
3 changes: 2 additions & 1 deletion third-party/glfw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ endif()
# Install files other than the library
# The library is installed by src/CMakeLists.txt
#--------------------------------------------------------------------
if (GLFW_INSTALL)
# Enforce GLFW when selecting GLSL
if (GLFW_INSTALL OR BUILD_GLSL_EXTENSIONS)
install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h)

Expand Down
3 changes: 2 additions & 1 deletion third-party/glfw/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ if (MSVC)
target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

if (GLFW_INSTALL)
# Enforce GLFW when selecting GLSL
if (GLFW_INSTALL OR BUILD_GLSL_EXTENSIONS)
install(TARGETS glfw
EXPORT glfwTargets
RUNTIME DESTINATION "bin"
Expand Down
36 changes: 22 additions & 14 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright(c) 2019 Intel Corporation. All Rights Reserved.
# minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)

project(RealsenseTools)

# Save the command line compile commands in the build output
Expand All @@ -11,26 +10,35 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
#set(CMAKE_VERBOSE_MAKEFILE on)

# This parameter is meant for disabling graphical examples when building for
# save-to-disk targets.
# headless systems
option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples." ON)

set(DEPENDENCIES ${DEPENDENCIES} realsense2)

add_subdirectory(convert)
add_subdirectory(enumerate-devices)
add_subdirectory(fw-logger)
add_subdirectory(terminal)

if(BUILD_GRAPHICAL_EXAMPLES)
include(${CMAKE_SOURCE_DIR}/CMake/opengl_config.cmake)
if (NOT BUILD_GLSL_EXTENSIONS)
MESSAGE(STATUS "BUILD_GRAPHICAL_EXAMPLES explicitely depends on BUILD_GLSL_EXTENSIONS, set it ON")
SET(BUILD_GLSL_EXTENSIONS ON)
endif()
set(DEPENDENCIES ${DEPENDENCIES} realsense2-gl)
add_subdirectory(data-collect)
add_subdirectory(realsense-viewer)
add_subdirectory(depth-quality)
add_subdirectory(rosbag-inspector)
add_subdirectory(benchmark)
else()
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
find_library(log-lib log)
set(DEPENDENCIES realsense2 log)
else()
set(DEPENDENCIES realsense2)
add_dependencies(RealsenseTools log)
set(DEPENDENCIES ${DEPENDENCIES} log)
#else()
# set(DEPENDENCIES realsense2)
endif()
endif()

add_subdirectory(terminal)
add_subdirectory(fw-logger)
add_subdirectory(enumerate-devices)
add_subdirectory(realsense-viewer)
add_subdirectory(data-collect)
add_subdirectory(depth-quality)
add_subdirectory(rosbag-inspector)
add_subdirectory(convert)
add_subdirectory(benchmark)
12 changes: 5 additions & 7 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set_target_properties(pyrealsense2 PROPERTIES VERSION
${REALSENSE_VERSION_STRING} SOVERSION "${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}")
set_target_properties(pyrealsense2 PROPERTIES FOLDER Wrappers/python)
install(TARGETS pyrealsense2 EXPORT realsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Expand All @@ -32,7 +32,7 @@ set(RAW_RS
../../third-party/easyloggingpp/src/easylogging++.h
../../third-party/easyloggingpp/src/easylogging++.cc
../../src/backend.h
../../src/backend.cpp
../../src/backend.cpp
)

if(UNIX)
Expand All @@ -43,7 +43,7 @@ if(UNIX)
../../src/libusb/enumerator-libusb.cpp
)
endif()

if(WIN32)
list(APPEND RAW_RS
../../src/win/win-helpers.cpp
Expand Down Expand Up @@ -91,8 +91,6 @@ endif()

pybind11_add_module(pybackend2 SHARED ${RAW_RS})

include(libusb_config)

if(USE_EXTERNAL_USB)
add_dependencies(pybackend2 libusb)
endif()
Expand All @@ -105,11 +103,11 @@ include_directories(pybackend2 ../../include)

install(TARGETS pybackend2
EXPORT realsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

if (BUILD_PYTHON_DOCS)
add_subdirectory(docs)
add_subdirectory(docs)
endif()