blob: d78ed51baf8138cf82e93b859196a531a477f771 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -07002// Copyright 2024 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -08003// http://ceres-solver.org/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// * Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28//
29// Author: keir@google.com (Keir Mierle)
30
31#ifndef CERES_PUBLIC_INTERNAL_PORT_H_
32#define CERES_PUBLIC_INTERNAL_PORT_H_
33
Austin Schuh3de38b02024-06-25 18:25:10 -070034#include <cmath> // Necessary for __cpp_lib_math_special_functions feature test
Austin Schuh70cc9552019-01-21 19:46:48 -080035
Austin Schuh3de38b02024-06-25 18:25:10 -070036// A macro to mark a function/variable/class as deprecated.
37// We use compiler specific attributes rather than the c++
38// attribute because they do not mix well with each other.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080039#if defined(_MSC_VER)
Austin Schuh3de38b02024-06-25 18:25:10 -070040#define CERES_DEPRECATED_WITH_MSG(message) __declspec(deprecated(message))
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080041#elif defined(__GNUC__)
Austin Schuh3de38b02024-06-25 18:25:10 -070042#define CERES_DEPRECATED_WITH_MSG(message) __attribute__((deprecated(message)))
Austin Schuh70cc9552019-01-21 19:46:48 -080043#else
Austin Schuh3de38b02024-06-25 18:25:10 -070044// In the worst case fall back to c++ attribute.
45#define CERES_DEPRECATED_WITH_MSG(message) [[deprecated(message)]]
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080046#endif
47
Austin Schuh3de38b02024-06-25 18:25:10 -070048#ifndef CERES_GET_FLAG
49#define CERES_GET_FLAG(X) X
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080050#endif
51
Austin Schuh3de38b02024-06-25 18:25:10 -070052// Indicates whether C++20 is currently active
53#ifndef CERES_HAS_CPP20
54#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
55#define CERES_HAS_CPP20
56#endif // __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >=
57 // 202002L)
58#endif // !defined(CERES_HAS_CPP20)
59
60// Prevents symbols from being substituted by the corresponding macro definition
61// under the same name. For instance, min and max are defined as macros on
62// Windows (unless NOMINMAX is defined) which causes compilation errors when
63// defining or referencing symbols under the same name.
64//
65// To be robust in all cases particularly when NOMINMAX cannot be used, use this
66// macro to annotate min/max declarations/definitions. Examples:
67//
68// int max CERES_PREVENT_MACRO_SUBSTITUTION();
69// min CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
70// max CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
71//
72// NOTE: In case the symbols for which the substitution must be prevented are
73// used within another macro, the substitution must be inhibited using parens as
74//
75// (std::numerical_limits<double>::max)()
76//
77// since the helper macro will not work here. Do not use this technique in
78// general case, because it will prevent argument-dependent lookup (ADL).
79//
80#define CERES_PREVENT_MACRO_SUBSTITUTION // Yes, it's empty
81
82// CERES_DISABLE_DEPRECATED_WARNING and CERES_RESTORE_DEPRECATED_WARNING allow
83// to temporarily disable deprecation warnings
84#if defined(_MSC_VER)
85#define CERES_DISABLE_DEPRECATED_WARNING \
86 _Pragma("warning(push)") _Pragma("warning(disable : 4996)")
87#define CERES_RESTORE_DEPRECATED_WARNING _Pragma("warning(pop)")
88#else // defined(_MSC_VER)
89#define CERES_DISABLE_DEPRECATED_WARNING
90#define CERES_RESTORE_DEPRECATED_WARNING
91#endif // defined(_MSC_VER)
92
93#if defined(__cpp_lib_math_special_functions) && \
94 ((__cpp_lib_math_special_functions >= 201603L) || \
95 defined(__STDCPP_MATH_SPEC_FUNCS__) && \
96 (__STDCPP_MATH_SPEC_FUNCS__ >= 201003L))
97// If defined, indicates whether C++17 Bessel functions (of the first kind) are
98// available. Some standard library implementations, such as libc++ (Android
99// NDK, Apple, Clang) do not yet provide these functions. Implementations that
100// do not support C++17, but support ISO 29124:2010, provide the functions if
101// __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at
102// least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before
103// including any standard library headers. Standard library Bessel functions are
104// preferred over any other implementation.
105#define CERES_HAS_CPP17_BESSEL_FUNCTIONS
106#elif defined(_SVID_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
107// If defined, indicates that j0, j1, and jn from <math.h> are available.
108#define CERES_HAS_POSIX_BESSEL_FUNCTIONS
Austin Schuh70cc9552019-01-21 19:46:48 -0800109#endif
110
111#endif // CERES_PUBLIC_INTERNAL_PORT_H_