Skip to content

Commit

Permalink
Merge pull request #1271 from fspindle/fix_cxx17
Browse files Browse the repository at this point in the history
Improve cxx17 standard detection
  • Loading branch information
fspindle authored Nov 15, 2023
2 parents a2ddf0c + d6aebe3 commit c44db1a
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos-ustk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-11, macos-12]
os: [macos-12]

steps:
# https://github.com/marketplace/actions/cancel-workflow-action
Expand All @@ -34,7 +34,7 @@ jobs:
run: system_profiler SPSoftwareDataType

- name: Install dependencies
run: brew install libpng libjpeg libdc1394 opencv pcl librealsense zbar vtk fftw armadillo nlohmann-json
run: brew install libpng libjpeg-turbo libdc1394 opencv pcl librealsense zbar pkg-config nlohmann-json

- name: Clone visp-images
env:
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-11, macos-12]
os: [macos-12]

steps:
# https://github.com/marketplace/actions/cancel-workflow-action
Expand All @@ -34,7 +34,7 @@ jobs:
run: system_profiler SPSoftwareDataType

- name: Install dependencies
run: brew install libpng libjpeg libdc1394 opencv pcl librealsense zbar pkg-config nlohmann-json
run: brew install libpng libjpeg-turbo libdc1394 opencv pcl librealsense zbar pkg-config nlohmann-json

- name: Install java dependencies
run: |
Expand Down Expand Up @@ -87,18 +87,7 @@ jobs:
make -j$(sysctl -n hw.logicalcpu)
- name: ViSP as 3rdparty with visp.pc and pkg-config
if: matrix.os != 'macOS-10.15'
run: |
# With macOS 10.15 there is the following build error:
# /Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9:
# error: no member named 'signbit' in the global namespace
# using ::signbit;
# also reported here https://stackoverflow.com/questions/58313047/cannot-compile-r-packages-with-c-code-after-updating-to-macos-catalina
# As suggested adding -isysroot build flag in VISPGenerateConfigScript.cmake around line 149 with
# execute_process(COMMAND xcrun --show-sdk-path
# OUTPUT_VARIABLE SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
# list(APPEND _cxx_flags "-isysroot ${SDK_PATH}")
# doesn't fix the build issue. That's why here the test is only done for macOS 11.0
cd ${HOME}/visp_sample
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/tmp/usr/local/lib/pkgconfig
pkg-config --cflags visp
Expand All @@ -107,7 +96,6 @@ jobs:
make -j$(sysctl -n hw.logicalcpu) -f Makefile.visp.pc clean
- name: ViSP as 3rdparty with visp-config
if: matrix.os != 'macos-10.15'
run: |
cd ${HOME}/visp_sample
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/tmp/usr/local/lib/pkgconfig
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/ubuntu-dep-src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ jobs:
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd)/install
cat ViSP-third-party.txt
- name: Compile
- name: Build visp-config script
working-directory: build
run: |
make -j$(nproc) developer_scripts
./bin/visp-config --cflags
./bin/visp-config --libs
- name: Build and install ViSP
working-directory: build
run: |
make -j$(nproc) install
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ endif()

# Upgrade c++ standard to 14 for pcl 1.9.1.99 that enables by default c++ 14 standard
if(USE_PCL)
# PCL is used in modules gui, sensor and mbt.
# In these modules we cannot directly use PCL_INCLUDE_DIRS and PCL_LIBRARIES using:
# list(APPEND opt_incs ${PCL_INCLUDE_DIRS})
# list(APPEND opt_libs ${PCL_LIBRARIES})
# Using PCL_LIBRARIES works to build visp libraries, embedded examples, demos, tests and tutorials thanks to the
# components. But when examples, demos, tests and tutorials are build outside ViSP workspace as independent projects
# that are using ViSP as 3rd-party we lead to build issues due to VTK headers and libraries that are not found.
# That's why here, we are using vp_find_pcl() macro that will set PCL_DEPS_INCLUDE_DIRS and PCL_DEPS_LIBRARIES
# that contains also VTK material location.
vp_find_pcl(PCL_LIBRARIES PCL_DEPS_INCLUDE_DIRS PCL_DEPS_LIBRARIES)
if(PCL_VERSION VERSION_GREATER 1.9.1)
# pcl > 1.9.1 requires c++14
# if c++14 option is OFF, force to c++14
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ViSP 3.x.x (Version in development)
https://visp-doc.inria.fr/doxygen/visp-daily/tutorial-tracking-mb-generic-rgbd-Blender.html
- Bug fixed
. [#1251] Bug in vpDisplay::displayFrame()
. [#1270] Build issue around std::clamp and optional header which are not found with cxx17
standard enabled
----------------------------------------------
ViSP 3.6.0 (released September 22, 2023)
- Contributors:
Expand Down
38 changes: 38 additions & 0 deletions cmake/PCLTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,40 @@
#
#############################################################################

# Remove BUILD_INTERFACE from __include_dirs
# IN/OUT: __include_dirs
#
# If __include_dirs contains "$<BUILD_INTERFACE:/home/VTK/install/include/vtk-9.3>" as input,
# it will be filtered as output to /home/VTK/install/include/vtk-9.3
macro(vp_filter_build_interface __include_dirs)
if(${__include_dirs})
set(__include_dirs_filtered)
foreach(inc_ ${${__include_dirs}})
string(REGEX REPLACE "\\$<BUILD_INTERFACE:" "" inc_ ${inc_})
string(REGEX REPLACE ">" "" inc_ ${inc_})
list(APPEND __include_dirs_filtered ${inc_})
endforeach()

set(${__include_dirs} ${__include_dirs_filtered})
endif()
endmacro()

# Find pcl libraries and dependencies
# IN: pcl_libraries
# OUT: pcl_deps_include_dirs
# OUT: pcl_deps_libraries
#
# PCL_LIBRARIES contains VTK 3rd party such as vtkalglib and not /usr/local/Cellar/vtk/6.3.0/lib/libvtkalglib-6.3.1.dylib
# full path as requested to use ViSP as 3rd party. This is the case for all VTK libraries that are PCL dependencies.
# The build of ViSP works with PCL_LIBRARIES since in that case thanks to vtkalglib properties, CMake
# is able to find the real name and location of the libraries.
# But when ViSP is used as a 3rd party where it should import PCL libraries, it doesn't work with
# PCL_LIBRARIES and especially with VTK_LIBRARIES.
# The solution here is to get the full location of VTK_LIBRARIES libraries thanks to the properties and link
# with these names.
# An other way could be to include PCLConfig.cmake, but in that case, visp-config and visp.pc
# will be not able to give the names of PCL libraries when used without CMake.
#
macro(vp_find_pcl pcl_libraries pcl_deps_include_dirs pcl_deps_libraries)
foreach(lib_ ${${pcl_libraries}})
mark_as_advanced(${lib_}_LOCATION)
Expand Down Expand Up @@ -97,6 +127,10 @@ macro(vp_find_pcl pcl_libraries pcl_deps_include_dirs pcl_deps_libraries)
endforeach()
vp_list_unique(PCL_VTK_IMPORTED_LIBS)
vp_list_unique(PCL_VTK_IMPORTED_INCS)

# Filter "$<BUILD_INTERFACE:/home/VTK/install/include/vtk-9.3>" into /home/VTK/install/include/vtk-9.3
vp_filter_build_interface(PCL_VTK_IMPORTED_INCS)

list(APPEND ${pcl_deps_include_dirs} ${PCL_VTK_IMPORTED_INCS})

# Filter "\$<LINK_ONLY:vtkCommonMath>;\$<LINK_ONLY:opengl32>;\$<LINK_ONLY:glu32>" into "vtkCommonMath;opengl32;glu32"
Expand Down Expand Up @@ -159,6 +193,10 @@ macro(vp_find_pcl pcl_libraries pcl_deps_include_dirs pcl_deps_libraries)
endforeach()
vp_list_unique(PCL_VTK_IMPORTED_LIBS)
vp_list_unique(PCL_VTK_IMPORTED_INCS)

# Filter "$<BUILD_INTERFACE:/home/VTK/install/include/vtk-9.3>" into /home/VTK/install/include/vtk-9.3
vp_filter_build_interface(PCL_VTK_IMPORTED_INCS)

list(APPEND ${pcl_deps_include_dirs} ${PCL_VTK_IMPORTED_INCS})

while(PCL_VTK_IMPORTED_LIBS)
Expand Down
73 changes: 45 additions & 28 deletions cmake/VISPDetectCXXStandard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@ if(DEFINED USE_CXX_STANDARD)
if(USE_CXX_STANDARD STREQUAL "11")
set(CMAKE_CXX_STANDARD 11)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_11})
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_STD_CXX11_FLAG)
set(CXX11_CXX_FLAGS "-std=c++11" CACHE STRING "C++ compiler flags for C++11 support")
mark_as_advanced(HAVE_STD_CXX11_FLAG)
endif()
elseif(USE_CXX_STANDARD STREQUAL "14")
set(CMAKE_CXX_STANDARD 14)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_14})
vp_check_compiler_flag(CXX "-std=c++14" HAVE_STD_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_STD_CXX14_FLAG)
set(CXX14_CXX_FLAGS "-std=c++14" CACHE STRING "C++ compiler flags for C++14 support")
mark_as_advanced(HAVE_STD_CXX14_FLAG)
endif()
elseif(USE_CXX_STANDARD STREQUAL "17")
set(CMAKE_CXX_STANDARD 17)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_17})
vp_check_compiler_flag(CXX "-std=c++17" HAVE_STD_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_STD_CXX17_FLAG)
set(CXX17_CXX_FLAGS "-std=c++17" CACHE STRING "C++ compiler flags for C++17 support")
mark_as_advanced(HAVE_STD_CXX17_FLAG)
endif()
endif()

set(CMAKE_CXX_EXTENSIONS OFF) # use -std=c++11 instead of -std=gnu++11
Expand All @@ -30,19 +45,43 @@ else()
# That's why we check more in depth for cxx_override that is not available with g++ 4.6.3
list (FIND CMAKE_CXX11_COMPILE_FEATURES "cxx_override" _index)
if (${_index} GREATER -1)
set(CXX11_STANDARD_FOUND ON CACHE STRING "cxx11 standard")
mark_as_advanced(CXX11_STANDARD_FOUND)
# Setting CMAKE_CXX_STANDARD doesn't affect check_cxx_source_compiles() used to detect isnan() in FindIsNaN.cmake
# or erfc() in FindErfc.cmake.
# That's why we have the following lines that are used to set cxx flags corresponding to the c++ standard
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_STD_CXX11_FLAG)
set(CXX11_CXX_FLAGS "-std=c++11" CACHE STRING "C++ compiler flags for C++11 support")
set(CXX11_STANDARD_FOUND ON CACHE STRING "cxx11 standard")
mark_as_advanced(CXX11_STANDARD_FOUND)
mark_as_advanced(CXX11_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX11_FLAG)
endif()
endif()
endif()

if(CMAKE_CXX14_COMPILE_FEATURES)
set(CXX14_STANDARD_FOUND ON CACHE STRING "cxx14 standard")
mark_as_advanced(CXX14_STANDARD_FOUND)
# Additionnal check in case of c++14 is incomplete and also needed to set CXX14_CXX_FLAGS
vp_check_compiler_flag(CXX "-std=c++14" HAVE_STD_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_STD_CXX14_FLAG)
set(CXX14_CXX_FLAGS "-std=c++14" CACHE STRING "C++ compiler flags for C++14 support")
set(CXX14_STANDARD_FOUND ON CACHE STRING "cxx14 standard")
mark_as_advanced(CXX14_STANDARD_FOUND)
mark_as_advanced(CXX14_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX14_FLAG)
endif()
endif()

if(CMAKE_CXX17_COMPILE_FEATURES)
set(CXX17_STANDARD_FOUND ON CACHE STRING "cxx17 standard")
mark_as_advanced(CXX17_STANDARD_FOUND)
# c++17 seems available, but on Fedora 25 and g++ 6.3.1 it seems incomplete where
# optional header is not found as well as std::clamp()
vp_check_compiler_flag(CXX "-std=c++17" HAVE_STD_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_STD_CXX17_FLAG)
set(CXX17_CXX_FLAGS "-std=c++17" CACHE STRING "C++ compiler flags for C++17 support")
set(CXX17_STANDARD_FOUND ON CACHE STRING "cxx17 standard")
mark_as_advanced(CXX17_STANDARD_FOUND)
mark_as_advanced(CXX17_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX17_FLAG)
endif()
endif()

# Set default c++ standard to 17, the first in the list
Expand Down Expand Up @@ -83,26 +122,4 @@ else()
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_17})
endif()
endif()

endif()

# Setting CMAKE_CXX_STANDARD doesn't affect check_cxx_source_compiles() used to detect isnan() in FindIsNaN.cmake
# or erfc() in FindErfc.cmake.
# That's why we have the following lines that are used to set cxx flags corresponding to the c++ standard
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_STD_CXX11_FLAG)
set(CXX11_CXX_FLAGS "-std=c++11" CACHE STRING "C++ compiler flags for C++11 support")
mark_as_advanced(CXX11_CXX_FLAGS)
endif()

vp_check_compiler_flag(CXX "-std=c++14" HAVE_STD_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_STD_CXX14_FLAG)
set(CXX14_CXX_FLAGS "-std=c++14" CACHE STRING "C++ compiler flags for C++14 support")
mark_as_advanced(CXX14_CXX_FLAGS)
endif()

vp_check_compiler_flag(CXX "-std=c++17" HAVE_STD_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_STD_CXX17_FLAG)
set(CXX17_CXX_FLAGS "-std=c++17" CACHE STRING "C++ compiler flags for C++17 support")
mark_as_advanced(CXX17_CXX_FLAGS)
endif()
18 changes: 2 additions & 16 deletions modules/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,8 @@ endif()

if(USE_PCL)
list(APPEND opt_incs ${PCL_INCLUDE_DIRS})

# list(APPEND opt_libs ${PCL_LIBRARIES})
# Using PCL_LIBRARIES works to build visp library, examples, demos and test thanks to the components,
# but not tutorials when they are build outside ViSP as they are stand alone CMake projects that use
# ViSP as a 3rd party.
# To be clear PCL_LIBRARIES contains VTK 3rd party such as vtkalglib and not /usr/local/Cellar/vtk/6.3.0/lib/libvtkalglib-6.3.1.dylib
# full path as requested to use ViSP as 3rd party. This is the case for all VTK libraries that are PCL dependencies.
# The build of ViSP works with PCL_LIBRARIES since in that case thanks to vtkalglib properties, CMake
# is able to find the real name and location of the libraries.
# But when ViSP is used as a 3rd party where it should import PCL libraries, it doesn't work with
# PCL_LIBRARIES and especially with VTK_LIBRARIES.
# The solution here is to get the full location of VTK_LIBRARIES libraries thanks to the properties and link
# with these names.
# An other way could be to include PCLConfig.cmake, but in that case, visp-config and visp.pc
# will be not able to give the names of PCL libraries when used without CMake.
vp_find_pcl(PCL_LIBRARIES PCL_DEPS_INCLUDE_DIRS PCL_DEPS_LIBRARIES)
# To ensure to build with VTK and other PCL 3rd parties we are not using PCL_LIBRARIES but PCL_DEPS_INCLUDE_DIRS
# and PCL_DEPS_LIBRARIES instead
list(APPEND opt_incs ${PCL_DEPS_INCLUDE_DIRS})
list(APPEND opt_libs ${PCL_DEPS_LIBRARIES})
endif()
Expand Down
18 changes: 2 additions & 16 deletions modules/sensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,8 @@ if(USE_FTIITSDK)
endif()
if(USE_PCL)
list(APPEND opt_incs ${PCL_INCLUDE_DIRS})

# list(APPEND opt_libs ${PCL_LIBRARIES})
# Using PCL_LIBRARIES works to build visp library, examples, demos and test thanks to the components,
# but not tutorials when they are build outside ViSP as they are stand alone CMake projects that use
# ViSP as a 3rd party.
# To be clear PCL_LIBRARIES contains VTK 3rd party such as vtkalglib and not /usr/local/Cellar/vtk/6.3.0/lib/libvtkalglib-6.3.1.dylib
# full path as requested to use ViSP as 3rd party. This is the case for all VTK libraries that are PCL dependencies.
# The build of ViSP works with PCL_LIBRARIES since in that case thanks to vtkalglib properties, CMake
# is able to find the real name and location of the libraries.
# But when ViSP is used as a 3rd party where it should import PCL libraries, it doesn't work with
# PCL_LIBRARIES and especially with VTK_LIBRARIES.
# The solution here is to get the full location of VTK_LIBRARIES libraries thanks to the properties and link
# with these names.
# An other way could be to include PCLConfig.cmake, but in that case, visp-config and visp.pc
# will be not able to give the names of PCL libraries when used without CMake.
vp_find_pcl(PCL_LIBRARIES PCL_DEPS_INCLUDE_DIRS PCL_DEPS_LIBRARIES)
# To ensure to build with VTK and other PCL 3rd parties we are not using PCL_LIBRARIES but PCL_DEPS_INCLUDE_DIRS
# and PCL_DEPS_LIBRARIES instead
list(APPEND opt_incs ${PCL_DEPS_INCLUDE_DIRS})
list(APPEND opt_libs ${PCL_DEPS_LIBRARIES})
endif()
Expand Down
18 changes: 2 additions & 16 deletions modules/tracker/mbt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,8 @@ endif()

if(USE_PCL)
list(APPEND opt_incs ${PCL_INCLUDE_DIRS})

# list(APPEND opt_libs ${PCL_LIBRARIES})
# Using PCL_LIBRARIES works to build visp library, examples, demos and test thanks to the components,
# but not tutorials when they are build outside ViSP as they are stand alone CMake projects that use
# ViSP as a 3rd party.
# To be clear PCL_LIBRARIES contains VTK 3rd party such as vtkalglib and not /usr/local/Cellar/vtk/6.3.0/lib/libvtkalglib-6.3.1.dylib
# full path as requested to use ViSP as 3rd party. This is the case for all VTK libraries that are PCL dependencies.
# The build of ViSP works with PCL_LIBRARIES since in that case thanks to vtkalglib properties, CMake
# is able to find the real name and location of the libraries.
# But when ViSP is used as a 3rd party where it should import PCL libraries, it doesn't work with
# PCL_LIBRARIES and especially with VTK_LIBRARIES.
# The solution here is to get the full location of VTK_LIBRARIES libraries thanks to the properties and link
# with these names.
# An other way could be to include PCLConfig.cmake, but in that case, visp-config and visp.pc
# will be not able to give the names of PCL libraries when used without CMake.
vp_find_pcl(PCL_LIBRARIES PCL_DEPS_INCLUDE_DIRS PCL_DEPS_LIBRARIES)
# To ensure to build with VTK and other PCL 3rd parties we are not using PCL_LIBRARIES but PCL_DEPS_INCLUDE_DIRS
# and PCL_DEPS_LIBRARIES instead
list(APPEND opt_incs ${PCL_DEPS_INCLUDE_DIRS})
list(APPEND opt_libs ${PCL_DEPS_LIBRARIES})
endif()
Expand Down

0 comments on commit c44db1a

Please sign in to comment.