Skip to content

Commit

Permalink
Add GLSL extensions CMake flag
Browse files Browse the repository at this point in the history
Define realsense2-gl install/distribution targets
Add realsense2-gl packaging and distribution config
Make BUILD_GRAPHICAL_EXAMPLES dependent on GLSL_EXTENSIONS flag

Change-Id: I153131a2554857a3c25b7ab92258aad593056d76
  • Loading branch information
ev-mp committed May 19, 2019
1 parent b8e5fae commit 5ca4b68
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 38 deletions.
5 changes: 5 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
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)")
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()
6 changes: 4 additions & 2 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,7 +74,7 @@ if (BUILD_WITH_TM2)
add_tm2()
endif()

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

Expand Down
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)

0 comments on commit 5ca4b68

Please sign in to comment.