Skip to content

Commit

Permalink
Merge pull request IntelRealSense#39 from IntelRealSense/development
Browse files Browse the repository at this point in the history
Merge from intelrealsense/librealsense/Development
  • Loading branch information
abernste authored Nov 21, 2018
2 parents 9f76354 + 0fc8499 commit ec2ab3c
Show file tree
Hide file tree
Showing 134 changed files with 4,069 additions and 3,154 deletions.
102 changes: 50 additions & 52 deletions CMake/Findlibtm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,82 @@
# Set root directory of libtm as ENVIRONMENT VARIABLE: LIBTM_DIR
# Then use with find_package(libtm) in your project


#add windows/linux SUFFIX for libraries
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
endif()

#try to search for the LIBTM_DIR enviroment VARIABLE
set(LIBTM_DIR
"$ENV{LIBTM_DIR}"
CACHE
PATH
"Root directory to search for LIBTM")
"$ENV{LIBTM_DIR}"
CACHE
PATH
"Root directory to search for LIBTM")

# Look for the header file.
find_path(LIBTM_INCLUDE_DIR
NAMES
TrackingManager.h
HINTS
"${LIBTM_DIR}/../libtm/include"
)
NAMES
TrackingManager.h
HINTS
"${LIBTM_DIR}/../libtm/include"
)

# Look for the library.
find_library(LIBTM_LIBRARY
NAMES
tm
HINTS
"${LIBTM_DIR}/bin/Release"
)
NAMES
tm
HINTS
"${LIBTM_DIR}/bin/Release"
)
# Look for the library debug flavor.
find_library(LIBTM_LIBRARY_DEBUG
NAMES
tm
HINTS
"${LIBTM_DIR}/bin/Debug"
)
NAMES
tm
HINTS
"${LIBTM_DIR}/bin/Debug"
)

# Look for the library.
# Look for the library.
find_library(INFRA_LIBRARY
NAMES
infra
HINTS
"${LIBTM_DIR}/bin/Release"
)
NAMES
infra
HINTS
"${LIBTM_DIR}/bin/Release"
)
# Look for the library debug flavor.
find_library(INFRA_LIBRARY_DEBUG
NAMES
infra
HINTS
"${LIBTM_DIR}/bin/Debug"
)

NAMES
infra
HINTS
"${LIBTM_DIR}/bin/Debug"
)

# handle the LIBTM and REQUIRED arguments and set LIBTM_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBTM
DEFAULT_MSG
LIBTM_LIBRARY
LIBTM_LIBRARY_DEBUG
LIBTM_INCLUDE_DIR)
DEFAULT_MSG
LIBTM_LIBRARY
LIBTM_LIBRARY_DEBUG
LIBTM_INCLUDE_DIR)

if (LIBTM_FOUND AND NOT TARGET libtm)
message(STATUS "LIBTM_INCLUDE_DIR: ${LIBTM_INCLUDE_DIR} LIBTM_LIBRARY: ${LIBTM_LIBRARY} INFRA_LIBRARY : ${INFRA_LIBRARY}")
add_library(libtm INTERFACE)
set_property(TARGET libtm PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LIBTM_INCLUDE_DIR})
target_include_directories(libtm INTERFACE ${LIBTM_INCLUDE_DIR})
target_link_libraries(libtm INTERFACE optimized ${LIBTM_LIBRARY} ${INFRA_LIBRARY} debug ${LIBTM_LIBRARY_DEBUG} ${INFRA_LIBRARY_DEBUG})
if (WIN32)
#set target architeture variable
message(STATUS "LIBTM_INCLUDE_DIR: ${LIBTM_INCLUDE_DIR} LIBTM_LIBRARY: ${LIBTM_LIBRARY} INFRA_LIBRARY : ${INFRA_LIBRARY}")
add_library(libtm INTERFACE)
set_property(TARGET libtm PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LIBTM_INCLUDE_DIR})
target_include_directories(libtm INTERFACE ${LIBTM_INCLUDE_DIR})
target_link_libraries(libtm INTERFACE optimized ${LIBTM_LIBRARY} ${INFRA_LIBRARY} debug ${LIBTM_LIBRARY_DEBUG} ${INFRA_LIBRARY_DEBUG})
if (WIN32)
#set target architeture variable
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TARGET_ARCH x64)
set(TARGET_ARCH x64)
else()
set(TARGET_ARCH win32)
set(TARGET_ARCH win32)
endif()
# Force-link to libusb on Windows
target_link_libraries(libtm INTERFACE ${LIBTM_DIR}/../3rdparty/win/libusb/bin/${TARGET_ARCH}/libusb-1.0.lib)
endif()
mark_as_advanced(LIBTM_DIR LIBTM_LIBRARY LIBTM_INCLUDE_DIR)
# Force-link to libusb on Windows
target_link_libraries(libtm INTERFACE ${LIBTM_DIR}/../3rdparty/win/libusb/bin/${TARGET_ARCH}/libusb-1.0.lib)
endif()
mark_as_advanced(LIBTM_DIR LIBTM_LIBRARY LIBTM_INCLUDE_DIR)
endif()
30 changes: 30 additions & 0 deletions CMake/android_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
message(STATUS "Setting Android configurations")
message(STATUS "Prepare RealSense SDK for Android OS (${ANDROID_NDK_ABI_NAME})")

macro(os_set_flags)
unset(WIN32)
unset(UNIX)
unset(APPLE)
set(BUILD_WITH_TM2 OFF)
set(BUILD_WITH_OPENMP OFF)
set(FORCE_LIBUVC ON)
set(BUILD_GRAPHICAL_EXAMPLES OFF)
set(ANDROID_STL "c++_static")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -pedantic -g -D_BSD_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pedantic -g -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch -Wno-multichar")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
set(BACKEND RS2_USE_V4L2_BACKEND)
include(CMake/external_libusb.cmake)
set(LIBUSB1_LIBRARIES ${LIBUSB1_LIBRARIES} log)
endmacro()

macro(os_target_config)
if(BUILD_SHARED_LIBS)
find_library(log-lib log)
target_link_libraries(${LRS_TARGET} PRIVATE log)
endif()

add_dependencies(${LRS_TARGET} libusb)
target_link_libraries(${LRS_TARGET} PRIVATE ${LIBUSB1_LIBRARIES})
endmacro()
22 changes: 22 additions & 0 deletions CMake/apple_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
message(STATUS "Setting Apple configurations")

macro(os_set_flags)
set(FORCE_LIBUVC ON)
set(BUILD_WITH_TM2 OFF)

add_definitions(-DUSE_SYSTEM_LIBUSB)
endmacro()

macro(os_target_config)
pkg_search_module(LIBUSB1 REQUIRED libusb-1.0)
if(LIBUSB1_FOUND)
include_directories(SYSTEM ${LIBUSB1_INCLUDE_DIRS})
link_directories(${LIBUSB1_LIBRARY_DIRS})
list(APPEND librealsense_PKG_DEPS "libusb-1.0")
else()
message( FATAL_ERROR "Failed to find libusb-1.0" )
endif(LIBUSB1_FOUND)

target_include_directories(${LRS_TARGET} PRIVATE ${LIBUSB1_INCLUDE_DIRS})
target_link_libraries(${LRS_TARGET} PRIVATE ${LIBUSB1_LIBRARIES})
endmacro()
15 changes: 15 additions & 0 deletions CMake/cuda_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
info("Building with CUDA requires CMake v3.8+")
cmake_minimum_required(VERSION 3.8.0)
project(librealsense2 LANGUAGES CXX C CUDA)

find_package(CUDA REQUIRED)

include_directories(${CUDA_INCLUDE_DIRS})
SET(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})
SET(LIBS ${LIBS} ${ALL_CUDA_LIBS})

message(STATUS "CUDA_LIBRARIES: ${CUDA_INCLUDE_DIRS} ${ALL_CUDA_LIBS}")

set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(CUDA_SEPARABLE_COMPILATION ON)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}; -O3 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_62,code=sm_62;")
29 changes: 29 additions & 0 deletions CMake/external_libusb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
message(STATUS "Use external libusb")
include(ExternalProject)

ExternalProject_Add(
libusb

GIT_REPOSITORY "https://github.com/libusb/libusb.git"
GIT_TAG "master"

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

SOURCE_DIR "third-party/libusb/"
CMAKE_ARGS -DCMAKE_CXX_STANDARD_LIBRARIES=${CMAKE_CXX_STANDARD_LIBRARIES}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/libusb_install
TEST_COMMAND ""
)

set(LIBUSB1_LIBRARY_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libusb_install/lib)
link_directories(${LIBUSB1_LIBRARY_DIRS})

set(LIBUSB1_LIBRARIES usb)
#set(LIBUSB_LOCAL_INCLUDE_PATH third-party/libusb)

set(USE_EXTERNAL_USB ON)
set(LIBUSB_LOCAL_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb)
92 changes: 92 additions & 0 deletions CMake/global_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# View the makefile commands during build
#set(CMAKE_VERBOSE_MAKEFILE on)

include(GNUInstallDirs)
# include librealsense helper macros
include(CMake/lrs_macros.cmake)
include(CMake/version_config.cmake)
include(CMake/lrs_options.cmake)

if(ENABLE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()

macro(global_set_flags)
set(LRS_TARGET realsense2)
set(LRS_LIB_NAME ${LRS_TARGET})

add_definitions(-DELPP_THREAD_SAFE)
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)

if (ENABLE_ZERO_COPY)
add_definitions(-DZERO_COPY)
endif()

if (BUILD_EASYLOGGINGPP)
add_definitions(-DBUILD_EASYLOGGINGPP)
endif()

if(TRACE_API)
add_definitions(-DTRACE_API)
endif()

if(HWM_OVER_XU)
add_definitions(-DHWM_OVER_XU)
endif()

if (ENFORCE_METADATA)
add_definitions(-DENFORCE_METADATA)
endif()

if (BUILD_WITH_CUDA)
add_definitions(-DRS2_USE_CUDA)
endif()

if(FORCE_LIBUVC)
set(BACKEND RS2_USE_LIBUVC_BACKEND)
message( WARNING "Using libuvc!" )
endif()

if (BUILD_WITH_CUDA)
include(CMake/cuda_config.cmake)
endif()

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

macro(global_target_config)
target_link_libraries(${LRS_TARGET} PRIVATE realsense-file ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})

include_directories(${LRS_TARGET} src)

set_target_properties (${LRS_TARGET} PROPERTIES FOLDER Library)

target_include_directories(${LRS_TARGET}
PRIVATE
${ROSBAG_HEADER_DIRS}
${BOOST_INCLUDE_PATH}
${LZ4_INCLUDE_PATH}
${LIBUSB_LOCAL_INCLUDE_PATH}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${USB_INCLUDE_DIRS}
)
endmacro()

macro(add_tm2)
message(STATUS "Building with TM2")
add_subdirectory(third-party/libtm)
if(USE_EXTERNAL_USB)
add_dependencies(tm libusb)
endif()
target_compile_definitions(${LRS_TARGET} PRIVATE WITH_TRACKING=1 BUILD_STATIC=1)
target_link_libraries(${LRS_TARGET} PRIVATE tm ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})
target_include_directories(${LRS_TARGET} PRIVATE third-party/libtm/libtm/include)
endmacro()
11 changes: 11 additions & 0 deletions CMake/include_os.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (WIN32)
include(CMake/windows_config.cmake)
endif()

if(UNIX)
include(CMake/unix_config.cmake)
endif()

if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
include(CMake/android_config.cmake)
endif()
51 changes: 51 additions & 0 deletions CMake/install_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Set CMAKE_INSTALL_* if not defined
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${LRS_TARGET}")

add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

include(CMakePackageConfigHelpers)

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/realsense2ConfigVersion.cmake"
VERSION ${REALSENSE_VERSION_STRING} COMPATIBILITY AnyNewerVersion)

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

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
configure_file(config/librealsense.pc.in config/realsense2.pc @ONLY)

install(TARGETS ${LRS_TARGET}
EXPORT realsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/librealsense2"
)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/librealsense2
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT realsense2Targets
FILE realsense2Targets.cmake
NAMESPACE ${LRS_TARGET}::
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/realsense2Config.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

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"
)
Loading

0 comments on commit ec2ab3c

Please sign in to comment.