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

C++14 #11105

Merged
merged 6 commits into from
Jan 9, 2023
Merged

C++14 #11105

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/cuda_config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
info("Building with CUDA requires CMake v3.8+")
cmake_minimum_required(VERSION 3.8.0)
project(librealsense2 LANGUAGES CXX C CUDA)
enable_language( CUDA )

find_package(CUDA REQUIRED)

Expand Down
3 changes: 1 addition & 2 deletions CMake/global_config.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_CXX_STANDARD 11)

# View the makefile commands during build
#set(CMAKE_VERBOSE_MAKEFILE on)

Expand All @@ -18,7 +18,6 @@ if(ENABLE_CCACHE)
endif()

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

add_definitions(-DELPP_THREAD_SAFE)
Expand Down
21 changes: 14 additions & 7 deletions CMake/lrs_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ endmacro()

macro(config_cxx_flags)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
if(MSVC OR MSVC_IDE)
check_cxx_compiler_flag(/std:c++14 SUPPORTS_CXX14)
else()
check_cxx_compiler_flag(-std=c++14 SUPPORTS_CXX14)
endif()
if( NOT SUPPORTS_CXX14 )
message(FATAL_ERROR "Project '${PROJECT_NAME}' requires C++14 or higher")
endif()
if( NOT CMAKE_CXX_STANDARD )
set( CMAKE_CXX_STANDARD 14 )
endif()
# We require that the current project (e.g., librealsense) use C++14. However, projects using
# the library don't need to be C++14 -- they can use C++11. Hence this is PRIVATE and not PUBLIC:
target_compile_features( ${PROJECT_NAME} PRIVATE cxx_std_${CMAKE_CXX_STANDARD} )
#set( CMAKE_CUDA_STANDARD ${LRS_CXX_STANDARD} )
endmacro()

macro(config_crt)
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)
project(librealsense2 LANGUAGES CXX C)

set( LRS_TARGET realsense2 )
project( ${LRS_TARGET} LANGUAGES CXX C )

# Allow librealsense2 and all of the nested project to include the main repo folder
set(REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down Expand Up @@ -30,9 +32,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
# include librealsense general configuration
include(CMake/global_config.cmake)


config_cxx_flags()

# include os specific macros
# macro definition located at "CMake/global_config.cmake"
include(CMake/include_os.cmake)
Expand All @@ -51,6 +50,8 @@ else()
add_library(${LRS_TARGET} STATIC "")
endif()

config_cxx_flags()

# set library version
set_target_properties(${LRS_TARGET} PROPERTIES VERSION ${REALSENSE_VERSION_STRING} SOVERSION "${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}")

Expand Down
10 changes: 1 addition & 9 deletions examples/ar-advanced/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ project(RealsenseExamplesAR_Advanced)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-ar-advanced rs-ar-advanced.cpp ../example.hpp)
set_property(TARGET rs-ar-advanced PROPERTY CXX_STANDARD 11)
target_include_directories(rs-ar-advanced PUBLIC ../../examples)
target_link_libraries(rs-ar-advanced ${DEPENDENCIES})
set_target_properties (rs-ar-advanced PROPERTIES FOLDER Examples)
Expand Down
10 changes: 1 addition & 9 deletions examples/ar-basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ project(RealsenseExamplesAR)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-ar-basic rs-ar-basic.cpp ../example.hpp)
set_property(TARGET rs-ar-basic PROPERTY CXX_STANDARD 11)
target_include_directories(rs-ar-basic PUBLIC ../)
target_link_libraries(rs-ar-basic ${DEPENDENCIES})
set_target_properties (rs-ar-basic PROPERTIES FOLDER Examples)
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Find librealsense installation, this feature is currently available only for Lin
find_package(realsense2 REQUIRED)
```

Enable C++ 11 standard in the application
Enable C++11 standard in the application
```
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
Expand Down
10 changes: 1 addition & 9 deletions examples/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ project(RealsenseExamplesGL)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE)
#pointcloud
add_executable(rs-gl rs-gl.cpp ../example.hpp)
set_property(TARGET rs-gl PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-gl ${DEPENDENCIES} realsense2-gl)
include_directories(../)
set_target_properties (rs-gl PROPERTIES FOLDER Examples)
Expand Down
10 changes: 1 addition & 9 deletions examples/pose-and-image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ project(RealsenseExamplesPoseAndImage)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(BUILD_EXAMPLES)
add_executable(rs-pose-and-image rs-pose-and-image.cpp)
set_property(TARGET rs-pose-and-image PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-pose-and-image ${DEPENDENCIES})
include_directories(../../examples)
set_target_properties (rs-pose-and-image PROPERTIES FOLDER Examples)
Expand Down
2 changes: 1 addition & 1 deletion src/compression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include_directories(

#Disabled due to CMake 3.5.1 compatibility
#target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)

add_dependencies(${PROJECT_NAME}
libjpeg-turbo
Expand Down
2 changes: 1 addition & 1 deletion src/ethernet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if(WIN32)
set(WINLIB Ws2_32.lib)
endif()

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved

target_link_libraries(${PROJECT_NAME}
PUBLIC ${WINLIB} realsense2 realsense2-compression
Expand Down
13 changes: 2 additions & 11 deletions tools/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ project(RealsenseToolsBenchmark)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-benchmark rs-benchmark.cpp ../../third-party/glad/glad.c)
set_property(TARGET rs-benchmark PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-benchmark ${DEPENDENCIES} realsense2-gl)
include_directories(../../third-party/tclap/include ../../third-party/glad ../../examples)
set_target_properties (rs-benchmark PROPERTIES
Expand All @@ -34,4 +25,4 @@ if(BUILD_GRAPHICAL_EXAMPLES)
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
)
endif()
endif()
2 changes: 1 addition & 1 deletion tools/embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(RealsenseToolsEmbed)
# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

add_executable(rs-embed
add_executable(rs-embed
rs-embed.cpp
${LZ4_DIR}/lz4.h
${LZ4_DIR}/lz4.c
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/LRS_jetson_compile_pipeline.stats
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
warnings 8
warnings 7

2 changes: 1 addition & 1 deletion unit-tests/LRS_linux_compile_pipeline.stats
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
warnings 7
warnings 6

2 changes: 1 addition & 1 deletion wrappers/open3d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.12.0)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD 11)

if(POLICY CMP0091)
# https://stackoverflow.com/a/56490614
Expand Down