cisst-saw
Loading...
Searching...
No Matches
cmnPortability.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Anton Deguet
6 Created on: 2003-09-08
7
8 (C) Copyright 2003-2024 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20
21#ifndef _cmnPortability_h
22#define _cmnPortability_h
23
24
25#include <cisstConfig.h>
27
33
37#define CISST_UNDEFINED 0
38
39
42
51#define CISST_WINDOWS 1
52#define CISST_LINUX 2
53#define CISST_RTLINUX 3
54#define CISST_IRIX 4
55#define CISST_SOLARIS 5
56#define CISST_LINUX_RTAI 6
57#define CISST_CYGWIN 7
58#define CISST_DARWIN 8
59#define CISST_QNX 9
60#define CISST_LINUX_XENOMAI 10
62
65
74#define CISST_GCC 1
75#define CISST_VCPP6 2
76#define CISST_DOTNET7 3
77#define CISST_SGI_CC 4
78#define CISST_SUN_CC 5
79#define CISST_INTEL_CC 6
80#define CISST_DOTNET2003 7
81#define CISST_DOTNET2005 8
82#define CISST_DOTNET2008 9
83#define CISST_DOTNET2010 10
84#define CISST_DOTNET2012 11
85#define CISST_DOTNET2013 12
86#define CISST_CLANG 13
87#define CISST_DOTNET2015 14
88#define CISST_DOTNET2017 15
90
91
94#define CISST_ILP32 1 // Integers, Longs and Pointers are 32 bits
95#define CISST_LP64 2 // Longs and Pointers are 64 bits - Linux, MacOS 64
96#define CISST_LLP64 3 // Long Longs and Pointers are 64 bits, longs are still 32 bits - Windows
98
99
100// skip rest of tests for doxygen
101#ifndef DOXYGEN
102
103// First, see if it's gcc and then determine OS
104// (Another compiler may determine the OS differently).
105#ifdef __GNUC__ // see man gcc
106 #define CISST_COMPILER CISST_GCC
107 #if (defined(linux) || defined(__linux__)) // see cpp -dM and ctrl+d
108 #define CISST_OS CISST_LINUX
109 #endif // linux
110 #if CISST_HAS_LINUX_RTAI // overwrite if RTAI
111 #undef CISST_OS
112 #define CISST_OS CISST_LINUX_RTAI
113 #endif // linux RTAI
114 #if CISST_HAS_LINUX_XENOMAI // overwrite if Xenomai
115 #undef CISST_OS
116 #define CISST_OS CISST_LINUX_XENOMAI
117 #endif // linux Xenomai
118 #ifdef sun
119 #define CISST_OS CISST_SOLARIS
120 #endif // sun
121 #ifdef sgi
122 #define CISST_OS CISST_IRIX
123 #endif // sgi
124 #ifdef __CYGWIN__
125 #define CISST_OS CISST_CYGWIN
126 #endif // __CYGWIN__
127 #ifdef __APPLE__
128 #define CISST_OS CISST_DARWIN
129 #endif // __APPLE__
130 #ifdef __QNX__
131 #define CISST_OS CISST_QNX
132 #endif // __QNX__
133#else // __GNUC__
134 #ifdef sgi
135 #define CISST_OS CISST_IRIX
136 #ifndef __GNUC__
137 #define CISST_COMPILER CISST_SGI_CC
138 #endif
139 #endif // sgi
140 #ifdef sun
141 #define CISST_OS CISST_SOLARIS
142 #ifndef __GNUC__
143 #define CISST_COMPILER CISST_SUN_CC
144 #endif
145 #endif // sun
146#endif // __GNUC__
147
148
149// CLang compiler
150#ifdef __clang__ // clang -dM -E -x c /dev/null
151 #undef CISST_COMPILER
152 #define CISST_COMPILER CISST_CLANG
153#endif // __clang__
154
155
156// Microsoft compilers
157#ifdef _WIN32 // see msdn.microsoft.com
158// we require Windows 2000, XP or more
159#ifndef _WIN32_WINNT
160 #define _WIN32_WINNT 0x0500
161#endif
162 #define CISST_OS CISST_WINDOWS
163
164 // check compiler versions
165 #ifdef _MSC_VER
166 #define CISST_COMPILER_IS_MSVC
167
168 #ifdef _WIN64
169 #define CISST_COMPILER_IS_MSVC_64
170 #endif
171
172 #if (_MSC_VER >= 1910)
173 #define CISST_COMPILER CISST_DOTNET2017
174 #elif (_MSC_VER >= 1900)
175 #define CISST_COMPILER CISST_DOTNET2015
176 #elif (_MSC_VER >= 1800)
177 #define CISST_COMPILER CISST_DOTNET2013
178 #elif (_MSC_VER >= 1700)
179 #define CISST_COMPILER CISST_DOTNET2012
180 #elif (_MSC_VER >= 1600)
181 #define CISST_COMPILER CISST_DOTNET2010
182 #elif (_MSC_VER >= 1500)
183 #define CISST_COMPILER CISST_DOTNET2008
184 #elif (_MSC_VER >= 1400)
185 #define CISST_COMPILER CISST_DOTNET2005
186 #elif (_MSC_VER >= 1310)
187 #define CISST_COMPILER CISST_DOTNET2003
188 #elif (_MSC_VER >= 1300)
189 #define CISST_COMPILER CISST_DOTNET7
190 #elif (_MSC_VER >= 1200)
191 #define CISST_COMPILER CISST_VCPP6
192 #endif
193 #endif
194
195#endif // _WIN32
196
197
198// Intel compiler
199#if defined(__INTEL_COMPILER)
200 #define CISST_COMPILER CISST_INTEL_CC
201 #if defined (__linux__) // linux
202 #define CISST_OS CISST_LINUX
203 #endif // linux
204 #if CISST_HAS_LINUX_RTAI // overwrite if RTAI
205 #undef CISST_OS
206 #define CISST_OS CISST_LINUX_RTAI
207 #endif // linux RTAI
208 #if CISST_HAS_LINUX_XENOMAI // overwrite if Xenomai
209 #undef CISST_OS
210 #define CISST_OS CISST_LINUX_XENOMAI
211 #endif // linux Xenomai
212 #ifndef CISST_OS // windows at last
213 #define CISST_OS CISST_WINDOWS
214 #endif // windows
215#endif // __INTEL_COMPILER
216
217
218// Make sure that both OS and compilers are set
219#ifndef CISST_COMPILER
220 #define CISST_COMPILER CISST_UNDEFINED
221#endif
222
223#ifndef CISST_OS
224 #define CISST_OS CISST_UNDEFINED
225#endif
226
227// We define unifying macros for the two Windows environments:
228// Windows and Cygwin
229#if (CISST_OS == CISST_WINDOWS) || (CISST_OS == CISST_CYGWIN)
230// CISST_OS_IS_WINDOWS is set to 1 for Windows and Cygwin,
231// and set to zero otherwise
232# define CISST_OS_IS_WINDOWS 1
233// Define WIN32 as 1 for any case (Cygwin is not entirely compatible
234// otherwise).
235# ifndef WIN32
236# define WIN32 1
237# else
238# undef WIN32
239# define WIN32 1
240# endif
241#else
242// CISST_OS_IS_WINDOWS is set to 1 for Windows and Cygwin,
243// and set to zero otherwise
244# define CISST_OS_IS_WINDOWS 0
245#endif
246
247
248// Define CISST_DATA_MODEL, i.e. either CISST_LLP64 (Windows) or CISST_LP64 (Unix, most of them). Also use ILP32.
249#if (CISST_COMPILER == CISST_GCC)
250 #ifdef _LP64
251 #define CISST_DATA_MODEL CISST_LP64
252 #else
253 #ifdef _LLP64
254 #define CISST_DATA_MODEL CISST_LLP64
255 #else
256 // default for now, might have to refine for cygwin?
257 #define CISST_DATA_MODEL CISST_ILP32
258 #endif
259 #endif
260#endif // CISST_COMPILER == CISST_GCC
261
262#if (CISST_COMPILER == CISST_CLANG)
263 #if defined(__LP64__) && __LP64__
264 #define CISST_DATA_MODEL CISST_LP64
265 #endif // __LP64__
266#endif // CISST_COMPILER == CISST_CLANG
267
268#ifdef CISST_COMPILER_IS_MSVC
269 #ifdef CISST_COMPILER_IS_MSVC_64
270 #define CISST_DATA_MODEL CISST_LLP64
271 #else
272 #define CISST_DATA_MODEL CISST_ILP32
273 #endif
274#endif // CISST_COMPILER_IS_MSVC
275
276#ifndef CISST_DATA_MODEL
277 #define CISST_DATA_MODEL CISST_UNDEFINED
278#endif
279
280
281
282#endif // DOXYGEN end of doxygen section to skip
283
284
308#if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
309#define CISST_DEPRECATED __attribute__ ((deprecated))
310#else
311 #ifdef CISST_COMPILER_IS_MSVC
312 #define CISST_DEPRECATED __declspec(deprecated)
313 #else
314 #define CISST_DEPRECATED
315 #endif
316#endif
318
326#ifdef CISST_COMPILER_IS_MSVC
327 #pragma warning(disable: 4290 4251 4786)
328 #ifndef _CRT_NONSTDC_NO_DEPRECATE
329 #define _CRT_NONSTDC_NO_DEPRECATE
330 #endif
331 #ifndef _CRT_SECURE_NO_DEPRECATE
332 #define _CRT_SECURE_NO_DEPRECATE
333 #endif
334 #ifndef _SCL_SECURE_NO_DEPRECATE
335 #define _SCL_SECURE_NO_DEPRECATE
336 #endif
337#endif
338
339
340// Arrays of string providing a human readable description of the OSs and
341// compilers. The system header "string" is included now, i.e. after all
342// the flags have been defined (MS Compilers warnings for example)
343#include <string>
344#ifndef DOXYGEN
345extern CISST_EXPORT const std::string cmnOperatingSystemsStrings[];
346extern CISST_EXPORT const std::string cmnCompilersStrings[];
347#endif // DOXYGEN
348
349
350#ifndef CISST_USE_CMATH
351#include <math.h>
352#else
353#include <cmath>
354#endif
357#if CISST_OS_IS_WINDOWS
358
359#ifndef NOMINMAX
360 #define NOMINMAX
361#endif
362
363#ifdef max
364#undef max
365#endif
366
367#ifdef min
368#undef min
369#endif
370
371#endif
372
373
390// we favor std::isnan
391#if CISST_HAS_STD_ISNAN
392 #include <cmath>
393 #define CMN_ISNAN(x) std::isnan(x)
394#else
395// hopefully we can removed this when we stop supporting old compilers
396 #ifdef CISST_COMPILER_IS_MSVC
397 #include <float.h>
398 #define CMN_ISNAN(x) (_isnan(x) != 0)
399 #else
400 #if (CISST_OS == CISST_DARWIN)
401 #ifndef isnan
402 extern "C" int isnan (double);
403 #endif
404 #endif
405 #ifndef CISST_USE_STD_ISNAN
406 #define CMN_ISNAN(x) isnan(x)
407 #else
408 #define CMN_ISNAN(x) std::isnan(x)
409 #endif
410 #endif
411#endif
412
413
429bool CISST_EXPORT cmnIsFinite(const float & value);
430bool CISST_EXPORT cmnIsFinite(const double & value);
431
432// for backward compatibility
433#define CMN_ISFINITE(x) cmnIsFinite(x)
434
464#if (CISST_COMPILER == CISST_DOTNET7)
465#define CISST_DECLARE_TEMPLATE_FUNCTION_SPECIALIZATION template
466#define CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION
467#else
468#define CISST_DECLARE_TEMPLATE_FUNCTION_SPECIALIZATION template<>
469#define CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION template<>
470#endif
471
472
494#if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
495#define CMN_UNUSED(argument) MARKED_AS_UNUSED ## argument __attribute__((unused))
496#else
497#define CMN_UNUSED(argument)
498#endif
499
500
501
522#if (CISST_COMPILER == CISST_DOTNET7) || (CISST_COMPILER == CISST_DOTNET2003) || (CISST_COMPILER == CISST_DOTNET2005)
523#define CMN_DEFAULT_TEMPLATED_CONSTRUCTOR(type) type::type()
524#else
525#define CMN_DEFAULT_TEMPLATED_CONSTRUCTOR(type) type()
526#endif
527
528
532#if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
533 // gcc 4.5 and above will support this, for lower versions there is a warning about the pragma itself
534 #define CMN_DO_PRAGMA(x) _Pragma (#x)
535 #define CMN_COMPILATION_WARNING(warningMessage) CMN_DO_PRAGMA(warning("Warning: " #warningMessage))
536#else
537 #ifdef CISST_COMPILER_IS_MSVC
538 #define CMN_COMPILATION_WARNING(warningMessage) __pragma(message("Warning: " ## warningMessage))
539 #endif
540#endif
541
542
549#undef CISST_THROW
550#ifndef SWIG
551 #ifdef __cplusplus
552 #if (__cplusplus > 199711L)
553 #define CISST_THROW(exceptionParameter)
554 #endif
555 #endif
556#endif
557
558#ifndef CISST_THROW
559 #define CISST_THROW(exceptionParameter) throw (exceptionParameter)
560#endif
561
562
565#ifdef SWIG_VERSION
566 #if SWIG_VERSION < 0x040100
567 #define override
568 #endif
569#endif
570
571
572#ifndef DOXYGEN
573
574// No __FUNCTION__ for g++ version < 2.6 __FUNCDNAME__ Valid only
575// within a function and returns the decorated name of the enclosing
576// function (as a string). __FUNCDNAME__ is not expanded if you use
577// the /EP or /P compiler option. __FUNCSIG__ Valid only within a
578// function and returns the signature of the enclosing function (as a
579// string). __FUNCSIG__ is not expanded if you use the /EP or /P
580// compiler option. __FUNCTION__ Valid only within a function and
581// returns the undecorated name of the enclosing function (as a
582// string). __FUNCTION__ is not expanded if you use the /EP or /P
583// compiler option.
584
585
586// Visual C++
587#ifdef CISST_COMPILER_IS_MSVC
588 #ifdef __FUNCSIG__
589 #define CMN_PRETTY_FUNCTION __FUNCSIG__
590 #else
591 #warning "With Visual Studio, you need /EP or /P to have __FUNCSIG__"
592 #endif
593
594// GNU CC and Intel CC
595#elif (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_INTEL_CC) || (CISST_COMPILER == CISST_CLANG)
596 #define CMN_PRETTY_FUNCTION __PRETTY_FUNCTION__
597
598// Otherwise
599#else
600// For SWIG pre-processor, no need to issue a warning
601 #ifndef SWIG
602 #warning "Visual C++, GNU C++ and Intel CC are supported so far"
603 #endif
604#endif
605
606// Set a default value
607#ifndef CMN_PRETTY_FUNCTION
608 #define CMN_PRETTY_FUNCTION ""
609#endif
610
611#endif // DOXYGEN
612
613
614#endif // _cmnPortability_h
Macros to export the symbols of cisstCommon (in a Dll).
#define CISST_EXPORT
Definition cmnExportMacros.h:50
CISST_EXPORT const std::string cmnCompilersStrings[]
CISST_EXPORT const std::string cmnOperatingSystemsStrings[]
bool CISST_EXPORT cmnIsFinite(const float &value)
Detect a finite number.