cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 Johns Hopkins University (JHU), All Rights
9  Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 
19 */
20 
21 #pragma once
22 
23 #ifndef _cmnPortability_h
24 #define _cmnPortability_h
25 
26 
27 #include <cisstConfig.h>
28 #include <cisstCommon/cmnExport.h>
29 
39 #define CISST_UNDEFINED 0
40 
41 
53 #define CISST_WINDOWS 1
54 #define CISST_LINUX 2
55 #define CISST_RTLINUX 3
56 #define CISST_IRIX 4
57 #define CISST_SOLARIS 5
58 #define CISST_LINUX_RTAI 6
59 #define CISST_CYGWIN 7
60 #define CISST_DARWIN 8
61 #define CISST_QNX 9
62 #define CISST_LINUX_XENOMAI 10
63 
64 
76 #define CISST_GCC 1
77 #define CISST_VCPP6 2
78 #define CISST_DOTNET7 3
79 #define CISST_SGI_CC 4
80 #define CISST_SUN_CC 5
81 #define CISST_INTEL_CC 6
82 #define CISST_DOTNET2003 7
83 #define CISST_DOTNET2005 8
84 #define CISST_DOTNET2008 9
85 #define CISST_DOTNET2010 10
86 #define CISST_DOTNET2012 11
87 #define CISST_DOTNET2013 12
88 #define CISST_CLANG 13
89 
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
97 
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  #ifdef 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 == 1200)
173  #define CISST_COMPILER CISST_VCPP6
174  #elif (_MSC_VER == 1300)
175  #define CISST_COMPILER CISST_DOTNET7
176  #elif (_MSC_VER == 1310)
177  #define CISST_COMPILER CISST_DOTNET2003
178  #elif (_MSC_VER == 1400)
179  #define CISST_COMPILER CISST_DOTNET2005
180  #elif (_MSC_VER == 1500)
181  #define CISST_COMPILER CISST_DOTNET2008
182  #elif (_MSC_VER == 1600)
183  #define CISST_COMPILER CISST_DOTNET2010
184  #elif (_MSC_VER == 1700)
185  #define CISST_COMPILER CISST_DOTNET2012
186  #elif (_MSC_VER >= 1800)
187  #define CISST_COMPILER CISST_DOTNET2013
188  #endif
189  #endif
190 
191 #endif // _WIN32
192 
193 
194 // Intel compiler
195 #if defined(__INTEL_COMPILER)
196  #define CISST_COMPILER CISST_INTEL_CC
197  #if defined (__linux__) // linux
198  #define CISST_OS CISST_LINUX
199  #endif // linux
200  #if CISST_HAS_LINUX_RTAI // overwrite if RTAI
201  #undef CISST_OS
202  #define CISST_OS CISST_LINUX_RTAI
203  #endif // linux RTAI
204  #if CISST_HAS_LINUX_XENOMAI // overwrite if Xenomai
205  #undef CISST_OS
206  #define CISST_OS CISST_LINUX_XENOMAI
207  #endif // linux Xenomai
208  #ifndef CISST_OS // windows at last
209  #define CISST_OS CISST_WINDOWS
210  #endif // windows
211 #endif // __INTEL_COMPILER
212 
213 
214 // Make sure that both OS and compilers are set
215 #ifndef CISST_COMPILER
216  #define CISST_COMPILER CISST_UNDEFINED
217 #endif
218 
219 #ifndef CISST_OS
220  #define CISST_OS CISST_UNDEFINED
221 #endif
222 
223 // We define unifying macros for the two Windows environments:
224 // Windows and Cygwin
225 #if (CISST_OS == CISST_WINDOWS) || (CISST_OS == CISST_CYGWIN)
226 // CISST_OS_IS_WINDOWS is set to 1 for Windows and Cygwin,
227 // and set to zero otherwise
228 # define CISST_OS_IS_WINDOWS 1
229 // Define WIN32 as 1 for any case (Cygwin is not entirely compatible
230 // otherwise).
231 # ifndef WIN32
232 # define WIN32 1
233 # else
234 # undef WIN32
235 # define WIN32 1
236 # endif
237 #else
238 // CISST_OS_IS_WINDOWS is set to 1 for Windows and Cygwin,
239 // and set to zero otherwise
240 # define CISST_OS_IS_WINDOWS 0
241 #endif
242 
243 
244 // Define CISST_DATA_MODEL, i.e. either CISST_LLP64 (Windows) or CISST_LP64 (Unix, most of them). Also use ILP32.
245 #if (CISST_COMPILER == CISST_GCC)
246  #ifdef _LP64
247  #define CISST_DATA_MODEL CISST_LP64
248  #else
249  #ifdef _LLP64
250  #define CISST_DATA_MODEL CISST_LLP64
251  #else
252  // default for now, might have to refine for cygwin?
253  #define CISST_DATA_MODEL CISST_ILP32
254  #endif
255  #endif
256 #endif // CISST_COMPILER == CISST_GCC
257 
258 #if (CISST_COMPILER == CISST_CLANG)
259  #if defined(__LP64__) && __LP64__
260  #define CISST_DATA_MODEL CISST_LP64
261  #endif // __LP64__
262 #endif // CISST_COMPILER == CISST_CLANG
263 
264 #ifdef CISST_COMPILER_IS_MSVC
265  #ifdef CISST_COMPILER_IS_MSVC_64
266  #define CISST_DATA_MODEL CISST_LLP64
267  #else
268  #define CISST_DATA_MODEL CISST_ILP32
269  #endif
270 #endif // CISST_COMPILER_IS_MSVC
271 
272 #ifndef CISST_DATA_MODEL
273  #define CISST_DATA_MODEL CISST_UNDEFINED
274 #endif
275 
276 
277 
278 #endif // DOXYGEN end of doxygen section to skip
279 
280 
304 #if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
305 #define CISST_DEPRECATED __attribute__ ((deprecated))
306 #else
307  #ifdef CISST_COMPILER_IS_MSVC
308  #define CISST_DEPRECATED __declspec(deprecated)
309  #else
310  #define CISST_DEPRECATED
311  #endif
312 #endif
313 
314 
322 #ifdef CISST_COMPILER_IS_MSVC
323  #pragma warning(disable: 4290 4251 4786)
324  #ifndef _CRT_NONSTDC_NO_DEPRECATE
325  #define _CRT_NONSTDC_NO_DEPRECATE
326  #endif
327  #ifndef _CRT_SECURE_NO_DEPRECATE
328  #define _CRT_SECURE_NO_DEPRECATE
329  #endif
330  #ifndef _SCL_SECURE_NO_DEPRECATE
331  #define _SCL_SECURE_NO_DEPRECATE
332  #endif
333 #endif
334 
335 
336 // Arrays of string providing a human readable description of the OSs and
337 // compilers. The system header "string" is included now, i.e. after all
338 // the flags have been defined (MS Compilers warnings for example)
339 #include <string>
340 #ifndef DOXYGEN
341 extern CISST_EXPORT const std::string cmnOperatingSystemsStrings[];
342 extern CISST_EXPORT const std::string cmnCompilersStrings[];
343 #endif // DOXYGEN
344 
345 
346 
347 #include <math.h>
348 
351 #if CISST_OS_IS_WINDOWS
352 
353 #ifndef NOMINMAX
354  #define NOMINMAX
355 #endif
356 
357 #ifdef max
358 #undef max
359 #endif
360 
361 #ifdef min
362 #undef min
363 #endif
364 
365 #endif
366 
367 
383 #ifdef CISST_COMPILER_IS_MSVC
384  #include <float.h>
385  #define CMN_ISNAN(x) (_isnan(x) != 0)
386 #else
387  #if (CISST_OS == CISST_DARWIN)
388  #ifndef isnan
389  extern "C" int isnan (double);
390  #endif
391  #endif
392  #define CMN_ISNAN(x) isnan(x)
393 #endif
394 
395 
411 bool CISST_EXPORT cmnIsFinite(const float & value);
412 bool CISST_EXPORT cmnIsFinite(const double & value);
413 
414 // for backward compatibility
415 #define CMN_ISFINITE(x) cmnIsFinite(x)
416 
446 #if (CISST_COMPILER == CISST_DOTNET7)
447 #define CISST_DECLARE_TEMPLATE_FUNCTION_SPECIALIZATION template
448 #define CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION
449 #else
450 #define CISST_DECLARE_TEMPLATE_FUNCTION_SPECIALIZATION template<>
451 #define CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION template<>
452 #endif
453 
454 
476 #if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
477 #define CMN_UNUSED(argument) MARKED_AS_UNUSED ## argument __attribute__((unused))
478 #else
479 #define CMN_UNUSED(argument) MARKED_AS_UNUSED ## argument
480 #endif
481 
482 
483 
504 #if (CISST_COMPILER == CISST_DOTNET7) || (CISST_COMPILER == CISST_DOTNET2003) || (CISST_COMPILER == CISST_DOTNET2005)
505 #define CMN_DEFAULT_TEMPLATED_CONSTRUCTOR(type) type::type()
506 #else
507 #define CMN_DEFAULT_TEMPLATED_CONSTRUCTOR(type) type()
508 #endif
509 
510 
514 #if (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_CLANG)
515  // gcc 4.5 and above will support this, for lower versions there is a warning about the pragma itself
516  #define CMN_DO_PRAGMA(x) _Pragma (#x)
517  #define CMN_COMPILATION_WARNING(warningMessage) CMN_DO_PRAGMA(warning("Warning: " #warningMessage))
518 #else
519  #ifdef CISST_COMPILER_IS_MSVC
520  #define CMN_COMPILATION_WARNING(warningMessage) __pragma(message("Warning: " ## warningMessage))
521  #endif
522 #endif
523 
524 
525 
526 
527 #ifndef DOXYGEN
528 
529 // No __FUNCTION__ for g++ version < 2.6 __FUNCDNAME__ Valid only
530 // within a function and returns the decorated name of the enclosing
531 // function (as a string). __FUNCDNAME__ is not expanded if you use
532 // the /EP or /P compiler option. __FUNCSIG__ Valid only within a
533 // function and returns the signature of the enclosing function (as a
534 // string). __FUNCSIG__ is not expanded if you use the /EP or /P
535 // compiler option. __FUNCTION__ Valid only within a function and
536 // returns the undecorated name of the enclosing function (as a
537 // string). __FUNCTION__ is not expanded if you use the /EP or /P
538 // compiler option.
539 
540 
541 // Visual C++
542 #ifdef CISST_COMPILER_IS_MSVC
543  #ifdef __FUNCSIG__
544  #define CMN_PRETTY_FUNCTION __FUNCSIG__
545  #else
546  #warning "With Visual Studio, you need /EP or /P to have __FUNCSIG__"
547  #endif
548 
549 // GNU CC and Intel CC
550 #elif (CISST_COMPILER == CISST_GCC) || (CISST_COMPILER == CISST_INTEL_CC) || (CISST_COMPILER == CISST_CLANG)
551  #define CMN_PRETTY_FUNCTION __PRETTY_FUNCTION__
552 
553 // Otherwise
554 #else
555 // For SWIG pre-processor, no need to issue a warning
556  #ifndef SWIG
557  #warning "Visual C++, GNU C++ and Intel CC are supported so far"
558  #endif
559 #endif
560 
561 // Set a default value
562 #ifndef CMN_PRETTY_FUNCTION
563  #define CMN_PRETTY_FUNCTION ""
564 #endif
565 
566 #endif // DOXYGEN
567 
568 
569 #endif // _cmnPortability_h
570 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Macros to export the symbols of cisstCommon (in a Dll).
bool CISST_EXPORT cmnIsFinite(const float &value)
Detect a finite number.
CISST_EXPORT const std::string cmnCompilersStrings[]
CISST_EXPORT const std::string cmnOperatingSystemsStrings[]