Skip to content

Commit

Permalink
Reintroduce compat with cxx98
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jan 31, 2024
1 parent daee7a5 commit 94ad7d6
Show file tree
Hide file tree
Showing 226 changed files with 7,501 additions and 6,234 deletions.
58 changes: 0 additions & 58 deletions 3rdparty/apriltag/common/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ either expressed or implied, of the Regents of The University of Michigan.
#include "string_util.h"
#include "zarray.h"

// fix va_copy missing with msvc11 Visual 2012
#ifdef _MSC_VER
#define my_va_copy(dest, src) (dest = src)
#endif

struct string_buffer
{
char *s;
Expand All @@ -50,59 +45,6 @@ struct string_buffer

#define MIN_PRINTF_ALLOC 16

char *sprintf_alloc(const char *fmt, ...)
{
assert(fmt != NULL);

va_list args;

va_start(args,fmt);
char *buf = vsprintf_alloc(fmt, args);
va_end(args);

return buf;
}

char *vsprintf_alloc(const char *fmt, va_list orig_args)
{
assert(fmt != NULL);

int size = MIN_PRINTF_ALLOC;
char *buf = (char *)malloc(size * sizeof(char));

int returnsize;
va_list args;

#ifdef _MSC_VER
my_va_copy(args, orig_args);
#else
va_copy(args, orig_args);
#endif
returnsize = vsnprintf(buf, size, fmt, args);
va_end(args);

// it was successful
if (returnsize < size) {
return buf;
}

// otherwise, we should try again
free(buf);
size = returnsize + 1;
buf = (char *)malloc(size * sizeof(char));

#ifdef _MSC_VER
my_va_copy(args, orig_args);
#else
va_copy(args, orig_args);
#endif
returnsize = vsnprintf(buf, size, fmt, args);
va_end(args);

assert(returnsize <= size);
return buf;
}

char *_str_concat_private(const char *first, ...)
{
size_t len = 0;
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/simdlib/Simd/SimdBaseCustomFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace Simd
{
for (size_t i = 0; i < size; i++) {
int diff = img1[i] - img2[i] + 128;
imgDiff[i] = static_cast<unsigned char>(std::max(std::min(diff, 255), 0));
imgDiff[i] = static_cast<unsigned char>(std::max<int>(std::min<int>(diff, 255), 0));
}
}

Expand Down
4 changes: 4 additions & 0 deletions 3rdparty/tinyexr/tinyexr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7385,7 +7385,11 @@ static size_t SaveEXRNPartImageToMemory(const EXRImage* exr_images,
{
size_t len = 0;
if ((len = strlen(exr_headers[i]->name)) > 0) {
#if TINYEXR_HAS_CXX11
partnames.emplace(exr_headers[i]->name);
#else
partnames.insert(std::string(exr_headers[i]->name));
#endif
if (partnames.size() != i + 1) {
SetErrorMessage("'name' attributes must be unique for a multi-part file", err);
return 0;
Expand Down
103 changes: 69 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,19 +622,7 @@ VP_OPTION(USE_ZBAR ZBAR "" "Include zbar support" "" O
VP_OPTION(USE_DMTX DMTX "" "Include dmtx support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_PCL PCL QUIET "Include Point Cloud Library support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_TENSORRT TensorRT "" "Include TensorRT support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_NLOHMANN_JSON nlohmann_json QUIET "Include nlohmann json support" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98))

# ----------------------------------------------------------------------------
# Handle cxx standard depending on specific 3rd parties. Should be before module parsing and VISP3rdParty.cmake include
# ----------------------------------------------------------------------------
# if c++ standard is not at leat c++17, force 3rd parties that require at least c++17 to OFF
if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_17)
if(USE_MAVSDK)
message(WARNING "mavsdk 3rd party was detected and needs at least c++17 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable MAVSDK usage turning USE_MAVSDK=OFF.")
unset(USE_MAVSDK)
set(USE_MAVSDK OFF CACHE BOOL "Include mavsdk support for mavlink compatible devices" FORCE)
endif()
endif()
VP_OPTION(USE_NLOHMANN_JSON nlohmann_json QUIET "Include nlohmann json support" "" ON)

# Upgrade c++ standard to 14 for pcl 1.9.1.99 that enables by default c++ 14 standard
if(USE_PCL)
Expand All @@ -648,27 +636,49 @@ if(USE_PCL)
# 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)
endif()

# ----------------------------------------------------------------------------
# Handle cxx standard depending on specific 3rd parties. Should be before module parsing and VISP3rdParty.cmake include
# ----------------------------------------------------------------------------
# if c++ standard is not at leat c++17, force 3rd parties that require at least c++17 to OFF
if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_17)
if(USE_MAVSDK)
message(WARNING "mavsdk 3rd party was detected and needs at least c++17 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable MAVSDK usage turning USE_MAVSDK=OFF.")
unset(USE_MAVSDK)
set(USE_MAVSDK OFF CACHE BOOL "Include mavsdk support for mavlink compatible devices" FORCE)
endif()
endif()

if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_14)
if(USE_FTIITSDK)
message(WARNING "IIT force-torque SDK 3rd party was detected and needs at least c++14 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable IIT force-torque usage turning USE_OPENCV=OFF.")
unset(USE_FTIITSDK)
set(USE_FTIITSDK OFF CACHE BOOL "Include IIT force-torque SDK support" FORCE)
endif()
if(USE_PCL AND (PCL_VERSION VERSION_GREATER 1.9.1))
# pcl > 1.9.1 requires c++14
# if c++14 option is OFF, force to c++14
if((VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_14) AND CXX14_STANDARD_FOUND)
message(WARNING "pcl ${PCL_VERSION} 3rd party was detected and needs c++14 compiler flags that is turned off. Thus to enable pcl usage we turn USE_CXX_STANDARD=14.")
set(USE_CXX_STANDARD "14" CACHE STRING "cxx standard" FORCE) # Update cmake-gui option
unset(CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_14}) # for vpConfig.h
endif()
message(WARNING "pcl 3rd party was detected and needs at least c++14 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable pcl usage turning USE_PCL=OFF.")
unset(USE_PCL)
set(USE_PCL OFF CACHE BOOL "Include pcl support" FORCE)
endif()
endif()

# Upgrade c++ standard to 14 for IIT force-torque SDK that needs at least c++ 14 standard
if(USE_FTIITSDK)
if((VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_14) AND CXX14_STANDARD_FOUND)
message(WARNING "IIT force-torque SDK 3rd party was detected and needs c++14 compiler flags that is turned off. Thus to enable IIT SDK usage we turn USE_CXX_STANDARD=14.")
set(USE_CXX_STANDARD "14" CACHE STRING "cxx standard" FORCE) # Update cmake-gui option
unset(CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(VISP_CXX_STANDARD ${VISP_CXX_STANDARD_14}) # for vpConfig.h
if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_11)
if(USE_OPENCV)
message(WARNING "OpenCV 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable OpenCV usage turning USE_OPENCV=OFF.")
unset(USE_OPENCV)
set(USE_OPENCV OFF CACHE BOOL "Include OpenCV support" FORCE)
endif()
if(USE_NLOHMANN_JSON)
message(WARNING "nlohmann json 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable nlohmann json usage turning USE_NLOHMANN_JSON=OFF.")
unset(USE_NLOHMANN_JSON)
set(USE_NLOHMANN_JSON OFF CACHE BOOL "Include nlohmann json support" FORCE)
endif()
if(USE_REALSENSE2)
message(WARNING "librealsense2 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable realsense2 usage turning USE_REALSENSE2=OFF.")
unset(USE_REALSENSE2)
set(USE_REALSENSE2 OFF CACHE BOOL "Include librealsense2 support" FORCE)
endif()
endif()

Expand All @@ -682,17 +692,41 @@ VP_OPTION(WITH_APRILTAG_BIG_FAMILY "" "" "Build AprilTag big family (41h12,
VP_OPTION(WITH_ATIDAQ "" "" "Build atidaq-c as built-in library" "" ON IF USE_COMEDI AND NOT WINRT)
VP_OPTION(WITH_CLIPPER "" "" "Build clipper as built-in library" "" ON IF USE_OPENCV)
VP_OPTION(WITH_LAPACK "" "" "Build lapack as built-in library" "" ON IF NOT USE_LAPACK)
VP_OPTION(WITH_QBDEVICE "" "" "Build qbdevice-api as built-in library" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND (NOT WINRT) AND (NOT IOS))
VP_OPTION(WITH_TAKKTILE2 "" "" "Build Right Hand takktile2 driver as built-in library" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND (NOT WIN32) AND (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_CATCH2 "" "" "Use catch2" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98))
VP_OPTION(WITH_QBDEVICE "" "" "Build qbdevice-api as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS))
VP_OPTION(WITH_TAKKTILE2 "" "" "Build Right Hand takktile2 driver as built-in library" "" ON IF (NOT WIN32) AND (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_CATCH2 "" "" "Use catch2 built-in library" "" ON)
VP_OPTION(WITH_POLOLU "" "" "Build rapa pololu as built-in library" "" ON IF (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))
VP_OPTION(WITH_PUGIXML "" "" "Use pugixml built-in third-party" "" ON)
VP_OPTION(WITH_SIMDLIB "" "" "Use simdlib built-in third-party" "" ON)
VP_OPTION(WITH_STBIMAGE "" "" "Use std_image built-in third-party" "" ON)
VP_OPTION(WITH_TINYEXR "" "" "Use tinyexr built-in third-party" "" ON)

if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_11)
if(WITH_CATCH2)
message(WARNING "catch2 3rd party needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable catch2 usage turning WITH_CATCH2=OFF.")
unset(WITH_CATCH2)
set(WITH_CATCH2 OFF CACHE BOOL "Use catch2 built-in library" FORCE)
endif()
if(WITH_POLOLU)
message(WARNING "pololu 3rd party needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable pololu usage turning WITH_POLOLU=OFF.")
unset(WITH_POLOLU)
set(WITH_POLOLU OFF CACHE BOOL "Build rapa pololu as built-in library" FORCE)
endif()
if(WITH_QBDEVICE)
message(WARNING "qbdevice-api 3rd party needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable qbdevice usage turning WITH_QBDEVICE=OFF.")
unset(WITH_QBDEVICE)
set(WITH_QBDEVICE OFF CACHE BOOL "Build rapa pololu as built-in library" FORCE)
endif()
if(WITH_TAKKTILE2)
message(WARNING "Right Hand takktile2 3rd party needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable takktile2 usage turning WITH_TAKKTILE2=OFF.")
unset(WITH_TAKKTILE2)
set(WITH_TAKKTILE2 OFF CACHE BOOL "Build rapa pololu as built-in library" FORCE)
endif()
endif()

# ----------------------------------------------------------------------------
# Check for specific functions. Should be after cxx standard detection in VISPDetectCXXStandard.cmake and potential modification depending on pcl, realsense2, libfranka
# Check for specific functions. Should be after cxx standard detection in VISPDetectCXXStandard.cmake and
# potential modification depending on pcl, realsense2, libfranka
# ----------------------------------------------------------------------------
VP_CHECK_PACKAGE(IsNaN)
VP_CHECK_PACKAGE(IsInf)
Expand Down Expand Up @@ -1027,6 +1061,7 @@ VP_SET(VISP_HAVE_DC1394_FIND_CAMERAS TRUE IF (USE_DC1394 AND DC1394_FIND_CAM
VP_SET(VISP_HAVE_D3D9 TRUE IF USE_DIRECT3D) # for header vpConfig.h
VP_SET(VISP_HAVE_GTK TRUE IF USE_GTK2) # for header vpConfig.h
VP_SET(VISP_HAVE_XRANDR TRUE IF XRANDR) # for header vpConfig.h
VP_SET(VISP_HAVE_NULLPTR TRUE IF HAVE_NULLPTR) # for header vpConfig.h

# Check if libfreenect dependencies (ie libusb-1.0 and threads) are available
if(USE_LIBFREENECT AND USE_LIBUSB_1 AND USE_THREADS)
Expand Down
17 changes: 17 additions & 0 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,23 @@
# define VISP_HAVE_DATASET_VERSION ${VISP_HAVE_DATASET_VERSION}
#endif

// Defined if nullptr is available
#cmakedefine VISP_HAVE_NULLPTR

// Emulate nullptr when not available when cxx98 is enabled
#if (!defined(VISP_HAVE_NULLPTR)) && (__cplusplus == 199711L)
#include <visp3/core/vpNullptrEmulated.h>
#endif

// Macro to be able to add override keyword
#ifndef vp_override
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600)
#define vp_override override
#else
#define vp_override
#endif
#endif

// Handle portable symbol export.
// Defining manually which symbol should be exported is required
// under Windows whether MinGW or MSVC is used.
Expand Down
2 changes: 1 addition & 1 deletion example/device/framegrabber/getRealSense2Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <iostream>
#include <visp3/sensor/vpRealSense2.h>

#if defined(VISP_HAVE_REALSENSE2)
#if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)

int main()
{
Expand Down
3 changes: 2 additions & 1 deletion example/device/framegrabber/grabRealSense2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpTime.h>

#if defined(VISP_HAVE_REALSENSE2) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
#if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) \
&& (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))

#ifdef VISP_HAVE_PCL
#include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion example/device/framegrabber/grabRealSense2_T265.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <visp3/gui/vpDisplayX.h>
#include <visp3/sensor/vpRealSense2.h>

#if defined(VISP_HAVE_REALSENSE2) && \
#if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)&& \
(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/device/framegrabber/readRealSenseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <visp3/core/vpConfig.h>

#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
#include <condition_variable>
#include <fstream>
#include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion example/device/framegrabber/saveRealSenseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <iostream>

#include <visp3/core/vpConfig.h>
#if (defined(VISP_HAVE_REALSENSE) || defined(VISP_HAVE_REALSENSE2)) && \
#if (defined(VISP_HAVE_REALSENSE) || defined(VISP_HAVE_REALSENSE2)) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_PUGIXML)

#include <condition_variable>
Expand Down
10 changes: 9 additions & 1 deletion example/math/quadprog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <iostream>
#include <visp3/core/vpConfig.h>

#if defined(VISP_HAVE_LAPACK)
#if defined(VISP_HAVE_LAPACK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)

#include <visp3/core/vpQuadProg.h>
#include <visp3/core/vpTime.h>
Expand Down Expand Up @@ -177,6 +177,14 @@ int main(int argc, char **argv)
#endif
return EXIT_SUCCESS;
}
#elif !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
int main()
{
std::cout << "You did not build ViSP with c++11 or higher compiler flag" << std::endl;
std::cout << "Tip:" << std::endl;
std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#else
int main()
{
Expand Down
10 changes: 9 additions & 1 deletion example/math/quadprog_eq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <iostream>
#include <visp3/core/vpConfig.h>

#if defined(VISP_HAVE_LAPACK)
#if defined(VISP_HAVE_LAPACK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)

#include "qp_plot.h"
#include <visp3/core/vpQuadProg.h>
Expand Down Expand Up @@ -204,6 +204,14 @@ int main(int argc, char **argv)
}
#endif
}
#elif !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
int main()
{
std::cout << "You did not build ViSP with c++11 or higher compiler flag" << std::endl;
std::cout << "Tip:" << std::endl;
std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#else
int main()
{
Expand Down
Loading

0 comments on commit 94ad7d6

Please sign in to comment.