Skip to content

Commit

Permalink
Merge pull request #1323 from fspindle/feat_cxx98_come_back
Browse files Browse the repository at this point in the history
Introduce again cxx98 support
  • Loading branch information
fspindle authored Feb 2, 2024
2 parents 628daab + 6e4c53e commit fdcb114
Show file tree
Hide file tree
Showing 249 changed files with 7,843 additions and 6,329 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
18 changes: 0 additions & 18 deletions 3rdparty/apriltag/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ struct string_feeder
int line, col;
};

/**
* Similar to sprintf(), except that it will malloc() enough space for the
* formatted string which it returns. It is the caller's responsibility to call
* free() on the returned string when it is no longer needed.
*/
char *sprintf_alloc(const char *fmt, ...)
#ifndef _MSC_VER
__attribute__ ((format (printf, 1, 2)))
#endif
;

/**
* Similar to vsprintf(), except that it will malloc() enough space for the
* formatted string which it returns. It is the caller's responsibility to call
* free() on the returned string when it is no longer needed.
*/
char *vsprintf_alloc(const char *fmt, va_list args);

/**
* Concatenates 1 or more strings together and returns the result, which will be a
* newly allocated string which it is the caller's responsibility to free.
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
12 changes: 6 additions & 6 deletions 3rdparty/simdlib/Simd/SimdRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ namespace Simd
{
count += 1;
sum += value;
min = std::min(min, value);
max = std::max(max, value);
min = std::min<int64_t>(min, value);
max = std::max<int64_t>(max, value);
}

SIMD_INLINE int64_t Mean() const
Expand Down Expand Up @@ -201,7 +201,7 @@ namespace Simd
{
size_t M; size_t N; size_t K; const float * alpha; const float * A; size_t lda; const float * B; size_t ldb; const float * beta; float * C; size_t ldc;
SIMD_INLINE GemmArgs(size_t M_, size_t N_, size_t K_, const float * alpha_, const float * A_, size_t lda_, const float * B_, size_t ldb_, const float * beta_, float * C_, size_t ldc_)
:M(M_), N(N_), K(K_), alpha(alpha_), A(A_), lda(lda_), B(B_), ldb(ldb_), beta(beta_), ldc(ldc_), C(C_)
:M(M_), N(N_), K(K_), alpha(alpha_), A(A_), lda(lda_), B(B_), ldb(ldb_), beta(beta_), ldc(ldc_), C(C_)
{}
};

Expand Down Expand Up @@ -287,8 +287,8 @@ namespace Simd
ss << "GemmCb [" << args.M << ", " << args.N << ", " << args.K << "]";
return ss.str();
}
#endif
#endif

SIMD_INLINE GemmKernelType Type() const { return _type; }

SIMD_INLINE size_t BufferSize(size_t M, size_t N, size_t K) const
Expand All @@ -310,7 +310,7 @@ namespace Simd
};
typedef std::vector<GemmCbFunc> GemmCbFuncs;

SIMD_INLINE GemmCbFuncs InitGemmCbFuncs(GemmCbFunc::BufferSizePtr bufferSize, GemmCbFunc::ReorderBPtr reorderB, GemmCbFunc::RunPtr run,
SIMD_INLINE GemmCbFuncs InitGemmCbFuncs(GemmCbFunc::BufferSizePtr bufferSize, GemmCbFunc::ReorderBPtr reorderB, GemmCbFunc::RunPtr run,
const String & name, GemmKernelType begin, GemmKernelType end)
{
GemmCbFuncs funcs;
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
125 changes: 90 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ if(NOT USE_THREADS)
endif()
endif()

VP_OPTION(USE_XML2 XML2 "" "Include xml support" "" ON IF NOT WINRT)
VP_OPTION(USE_XML2 XML2 "" "Include libxml2 support" "" ON IF NOT WINRT)
if(CMAKE_TOOLCHAIN_FILE)
# Find opencv2.framework for ios and naoqi
VP_OPTION(USE_OPENCV "MyOpenCV" QUIET "Include OpenCV support" "OpenCV_DIR;OpenCV_FOUND;OPENCV_FOUND" ON)
Expand All @@ -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)

# ----------------------------------------------------------------------------
# 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,69 @@ 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()
if(USE_XML2)
message(WARNING "libxml2 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable libxml2 usage turning USE_XML2=OFF.")
unset(USE_XML2)
set(USE_XML2 OFF CACHE BOOL "Include libxml2 support" FORCE)
endif()
if(USE_QUALISYS)
message(WARNING "Qualisys SDK 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable qualisys usage turning USE_QUALISYS=OFF.")
unset(USE_QUALISYS)
set(USE_QUALISYS OFF CACHE BOOL "Include Qualisys SDK support" FORCE)
endif()
if(USE_BICLOPS)
message(WARNING "Biclops SDK 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable biclops usage turning USE_BICLOPS=OFF.")
unset(USE_BICLOPS)
set(USE_BICLOPS OFF CACHE BOOL "Include biclops support" FORCE)
endif()
if(USE_ARSDK)
message(WARNING "Parrot ARSDK 3rd party was detected and needs at least c++11 standard compiler flag while you have set c++${USE_CXX_STANDARD}. Thus we disable ARSDK usage turning USE_ARSDK=OFF.")
unset(USE_ARSDK)
set(USE_ARSDK OFF CACHE BOOL "Include Parrot ARSDK support" FORCE)
endif()
endif()

Expand All @@ -682,17 +712,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 +1081,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
4 changes: 4 additions & 0 deletions apps/calibration/visp-compute-hand-eye-calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ int main(int argc, const char *argv[])
std::string name_we = vpIoTools::createFilePath(vpIoTools::getParent(opt_eMc_file), vpIoTools::getNameWE(opt_eMc_file)) + ".txt";
std::cout << std::endl << "Save transformation matrix eMc as an homogeneous matrix in: " << name_we << std::endl;

#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
std::ofstream file_eMc(name_we);
#else
std::ofstream file_eMc(name_we.c_str());
#endif

eMc.save(file_eMc);

Expand Down
4 changes: 4 additions & 0 deletions cmake/AddExtraCompilationFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ elseif(MSVC)
endif()
endif()

if((NOT VISP_HAVE_NULLPTR) AND (VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_98) AND (NOT MSVC))
add_extra_compiler_option("-Wno-c++11-compat")
endif()

# Note here ViSPDetectPlatform.cmake should be called before this file to set ARM var
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) AND ARM)
# Here to disable warnings due to gcc bug introduced in gcc 7 on arm.
Expand Down
Loading

0 comments on commit fdcb114

Please sign in to comment.