opennurbs_system_compiler.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2014 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 /*
18 ////////////////////////////////////////////////////////////////
19 //
20 // Determines what compiler is being used.
21 //
22 ////////////////////////////////////////////////////////////////
23 */
24 
25 
26 #if !defined(OPENNURBS_SYSTEM_COMPILER_INC_)
27 #define OPENNURBS_SYSTEM_COMPILER_INC_
28 
29 #if !defined(_GNU_SOURCE)
30 #define _GNU_SOURCE
31 #endif
32 
33 /*
34 ////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////
37 //
38 // BEGIN - ON_COMPILER_* defines
39 //
40 // ON_COMPILER_* specifies the C/C++ compiler used.
41 // At most one the ON_COMPILER_* should be defined.
42 //
43 */
44 
45 
46 /*
47 // Compilers that require special declaration of callback functions
48 // will change ON_CALLBACK_CDECL accordingly.
49 */
50 #define ON_CALLBACK_CDECL
51 
52 /*
53 // Compilers that require special declaration of callback functions
54 // will change ON_CALLBACK_CDECL accordingly.
55 */
56 #define ON_VARGS_FUNC_CDECL
57 
58 
59 /*
60 // Compilers that do not support the C++ 11 noexcept keyword
61 // or similar will change ON_NOEXCEPT accordingly.
62 */
63 #define ON_NOEXCEPT noexcept
64 
65 /*
66 // Compilers that do not support the C++ 11 rvalue refs
67 // will change ON_HAS_RVALUEREF accordingly.
68 */
69 #define ON_HAS_RVALUEREF
70 
71 #if defined (_MSC_VER)
72 /*
73 ////////////////////////////////////////////////////////////
74 ////////////////////////////////////////////////////////////
75 //
76 // ON_COMPILER_MSC
77 //
78 */
79 
80 #define ON_COMPILER_MSC
81 
82 /*
83 // Usage example - disables warning number 1234 - see CL docs for details
84 #pragma ON_PRAGMA_WARNING_PUSH
85 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(1234)
86 ...
87 #pragma ON_PRAGMA_WARNING_POP
88 */
89 #define ON_PRAGMA_WARNING_PUSH warning( push )
90 #define ON_PRAGMA_WARNING_POP warning( pop )
91 #define ON_PRAGMA_WARNING_DISABLE_MSC(ON_PRAGMA_WARNING_DISABLE_param) warning( disable : ON_PRAGMA_WARNING_DISABLE_param ) // Microsoft CL warning disable
92 
93 // Opennurbs warning level is /Wall
94 // Microsoft, Freetype, and other external header files issue warnings we can't do anything about
95 #define ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE warning( push, 1 )
96 #define ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE warning( pop )
97 
98 #if !defined(_CRT_SECURE_NO_DEPRECATE)
99 #define _CRT_SECURE_NO_DEPRECATE
100 /*
101 // Visual Studio 2005 issues a C4996 warning for lots of
102 // standard C runtime functions that take string pointers.
103 // The _CRT_SECURE_NO_DEPRECATE suppresses these warnings.
104 // TODO - clean up our code and remove do not define _CRT_SECURE_NO_DEPRECATE
105 */
106 #endif
107 
108 /*
109 // Microsoft's Visual C/C++ requires functions that use vargs
110 // to be declared with __cdecl
111 // Since this code must also compile with non-Micorosoft compilers,
112 // the ON_VARGS_FUNC_CDECL macro is used to insert __cdecl when needed.
113 */
114 #undef ON_VARGS_FUNC_CDECL
115 #define ON_VARGS_FUNC_CDECL __cdecl
116 
117 /*
118 // Microsoft's Visual C/C++ requires some callback functions
119 // to be declared with __cdecl
120 // Since this code must also compile with non-Micorosoft compilers,
121 // the ON_VARGS_FUNC_CDECL macro is used to insert __cdecl when needed.
122 */
123 #undef ON_CALLBACK_CDECL
124 #define ON_CALLBACK_CDECL __cdecl
125 
126 #if _MSC_VER < 1700
127 #undef ON_HAS_RVALUEREF
128 #endif
129 
130 #if _MSC_VER >= 1700 && _MSC_VER < 1900
131 
132 // VC 2012 and 2013 does not support the C++11 noexcept specifier.
133 // Appending throw() indicates the function does not throw
134 // exceptions. Using throw() is not 100% equivalent to
135 // noexcept because you cannot use a bool parameter
136 // and hence cannot do things like
137 // class MyClass : public MyOtherClass
138 // {
139 // void MyClass() noexcept(std::is_nothrow_default_constructible<MyOtherClass>::value)
140 // void MyClass(const MyClass& ) noexcept(std::is_nothrow_copy_constructible<MyOtherClass>::value)
141 // };
142 #undef ON_NOEXCEPT
143 #define ON_NOEXCEPT throw()
144 #endif
145 
146 #if _MSC_VER >= 1300
147 #define ON_COMPILER_MSC1300
148 #if _MSC_VER >= 1400
149 /* Using at least Visual C++ 8.0 (2005) */
150 #define ON_COMPILER_MSC1400
151 #if _MSC_VER >= 1600
152 /* Using at least Visual C++ 10.0 (2010) */
153 #define ON_COMPILER_MSC1600
154 #if _MSC_VER >= 1700
155 /* Using at least Visual C++ 11.0 (2012) */
156 #define ON_COMPILER_MSC1700
157 #if _MSC_VER >= 1800
158 /* Using at least Visual C++ 12.0 (2013) */
159 #define ON_COMPILER_MSC1800
160 #if _MSC_VER >= 1900
161 /* Using at least Visual C++ 14.0 (2015) */
162 #define ON_COMPILER_MSC1900
163 
164 #if !defined(OPENNURBS_WALL) && !defined(ON_COMPILING_OPENNURBS)
165 /*
166 // TEMPORARY C4456 SUPRESSION Feb 17 2016 - WILL BE REMOVED ASAP
167 // Rhino code is still too dirty to leave 4456 on.
168 */
169 // Supress Warning C4456 declaration of '...' hides previous local declaration ...
170 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4456)
171 #endif
172 
173 // C4100 '...': unreferenced formal parameter ...
174 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4100)
175 
176 // C4061 enumerator '...' in switch of enum '...' is not explicitly handled by a case label
177 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4061)
178 
179 // C4062 enumerator '...' in switch of enum '...' is not handled
180 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4062)
181 
182 // C4711 function '...' selected for inline expansion
183 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4711)
184 
185 // C4820 '...' bytes padding added after construct '...'
186 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4820)
187 
188 /////////////////////////////////////////////////////////////////////////////////////
189 //
190 // Dale Lear April 2017.
191 // The Visual Stuido 2017 default is to disable warnings 4263, 4264, 4265, 4266
192 //
193 // These are the warnings that help detect abuse of virtual functions and failed attempts
194 // to override virtual functions.
195 //
196 // I've enable them for all Rhino core projects.
197 // "#pragma warning(default:xxxx): is the way to enable warning xxxx.
198 //
199 
200 // 'function' : member function does not override any base class virtual member function
201 // A class function definition has the same name as a virtual function in a base
202 // class but not the same number or type of arguments. This effectively hides the
203 // virtual function in the base class.
204 #pragma warning(default:4263)
205 
206 // 'virtual_function' : no override available for virtual member function from base 'class'; function is hidden
207 #pragma warning(default:4264)
208 
209 // 'class' : class has virtual functions, but destructor is not virtual
210 // When a class has virtual functions but a nonvirtual destructor, objects
211 // of the type might not be destroyed properly when the class is destroyed
212 // through a base class pointer.
213 // NOTE WELL: Occasionally there are good reasons to have a non-virtual destructor.
214 // See Guideline #4 in http://www.gotw.ca/publications/mill18.htm for a nice description of the details.
215 // However, those case are generally rare and this warning can explicitly be disabled for those rare
216 // cases.
217 #pragma warning(default:4265)
218 
219 #if defined(OPENNURBS_WALL)
220 // The 4266 warning is enabled only when OPENNURBS_WALL is defined.
221 //
222 // In the case of Rhino, this warning is not useful.
223 // It is reasonable to override some but not all base class virtual functions
224 // that have the same name.
225 // For example, almost every class derived from CRhinoObject overrides
226 // virtual ON_BoundingBox BoundingBox() const;
227 // but most do not override
228 // virtual ON_BoundingBox BoundingBox( const class CRhinoViewport* pViewport ) const;
229 
230 // 'function' : no override available for virtual member function from base 'type'; function is hidden
231 // A derived class did not override all overloads of a virtual function.
232 #pragma warning(default:4266)
233 #endif
234 
235 //
236 /////////////////////////////////////////////////////////////////////////////////////
237 
238 #define ON_CLANG_CONSTRUCTOR_BUG
239 
240 
241 #endif
242 #endif
243 #endif
244 #endif
245 #endif
246 #endif
247 
248 #define ON_SIZEOF_WCHAR_T 2
249 
250 #elif defined(__clang__) | defined(ON_COMPILER_CLANG)
251 /*
252 ////////////////////////////////////////////////////////////
253 ////////////////////////////////////////////////////////////
254 //
255 // ON_COMPILER_CLANG
256 //
257 */
258 
259 /*
260 // The __clang__ test must come before the gnu tests because Apple's clang
261 // uncoditionally defines __GNUC__
262 */
263 #if !defined(ON_COMPILER_CLANG)
264 #define ON_COMPILER_CLANG
265 #endif
266 
267 /*
268 // Usage example - disables CLang warning xyz - See CLang docs for warning options
269 #pragma ON_PRAGMA_WARNING_PUSH
270 #pragma ON_PRAGMA_WARNING_DISABLE_CLANG("-Wxyz")
271 ...
272 #pragma ON_PRAGMA_WARNING_POP
273 */
274 #define ON_PRAGMA_WARNING_PUSH clang diagnostic push // Apple CLang warning state push
275 #define ON_PRAGMA_WARNING_POP clang diagnostic pop // Apple CLang warning state pop
276 #define ON_PRAGMA_WARNING_DISABLE_CLANG(ON_PRAGMA_WARNING_DISABLE_param) clang diagnostic ignored ON_PRAGMA_WARNING_DISABLE_param // Apple CLang warning disable
277 
278 // clang has a bug that is fails to correctly construct statc const objects
279 // in the following case
280 //
281 // // header file
282 // class Blah
283 // {
284 // public:
285 // Blah() = default;
286 // ~Blah() = default;
287 // Blah(const Blah&) = default;
288 // Blah& operator=(const Blah&) = default;
289 //
290 // static const Blah Zero;
291 //
292 // int m_i = 0;
293 // };
294 //
295 // ...
296 //
297 // // cpp file
298 // const Blah Blah::Zero; // correct C++ 11, Apple's clang fails as of February, 2015
299 // const Blah Blah::Zero( Blah() ); // clang fails to use copy constructor
300 // const Blah Blah::Zero = Blah(); // clang can handle this
301 //
302 // When this bug is fixed, delete this define and the places
303 // in the code that use it.
304 #define ON_CLANG_CONSTRUCTOR_BUG
305 
306 #if defined(__has_feature) && __has_feature(cxx_noexcept)
307 #undef ON_NOEXCEPT
308 #define ON_NOEXCEPT noexcept
309 #endif
310 
311 #if defined(__has_extension) && __has_extension(cxx_rvalue_references) && !defined(ON_HAS_RVALUEREF)
312 #define ON_HAS_RVALUEREF
313 #elif defined(ON_HAS_RVALUEREF)
314 #undef ON_HAS_RVALUEREF
315 #endif
316 
317 #elif defined( ON_COMPILER_ANDROIDNDK )
318 /*
319 ////////////////////////////////////////////////////////////
320 ////////////////////////////////////////////////////////////
321 //
322 // ON_COMPILER_ANDROIDNDK
323 //
324 */
325 
326 /*
327 // McNeel defines ON_COMPILER_ANDROIDNDK in makefiles
328 */
329 
330 #if defined(__GNUC__) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 7))
331 // C++11 noexcept and Rvalue references are in gcc 4.7 and later
332 #undef ON_NOEXCEPT
333 #define ON_NOEXCEPT noexcept
334 #if !defined(ON_HAS_RVALUEREF)
335 #define ON_HAS_RVALUEREF
336 #endif
337 
338 #else
339 #undef ON_HAS_RVALUEREF
340 #undef ON_NOEXCEPT
341 
342 #endif
343 
344 // You may need to define __GXX_EXPERIMENTAL_CXX0X__ to get
345 // C++11 std::shared_ptr to work as you expect when using
346 // the Android NDK gcc 4.7. See
347 // http://stackoverflow.com/questions/14532057/smart-pointers-not-working-with-android-ndk-r8
348 // for more details.
349 //
350 //#define __GXX_EXPERIMENTAL_CXX0X__
351 
352 #elif defined(__GNUG_) || defined(__GNUG__) || defined(__GNUC_) || defined(__GNUC__) || defined(_GNU_SOURCE) || defined(__GNU_SOURCE)
353 /*
354 ////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////
356 //
357 // ON_COMPILER_GNU
358 //
359 */
360 
361 #define ON_COMPILER_GNU
362 #if !defined(_GNU_SOURCE)
363 #define _GNU_SOURCE
364 #endif
365 
366 /*
367 // Usage example - disables gcc warning xyz - See Gnu gcc docs for warning options
368 #pragma ON_PRAGMA_WARNING_PUSH
369 #pragma ON_PRAGMA_WARNING_DISABLE_CLANG("-Wxyx")
370 ...
371 #pragma ON_PRAGMA_WARNING_POP
372 */
373 #define ON_PRAGMA_WARNING_PUSH GCC diagnostic push // Gnu gcc warning state push
374 #define ON_PRAGMA_WARNING_POP GCC diagnostic pop // Gnu gcc warning state pop
375 #define ON_PRAGMA_WARNING_DISABLE_GNU(ON_PRAGMA_WARNING_DISABLE_param) GCC diagnostic ignored ON_PRAGMA_WARNING_DISABLE_param // Apple CLang warning disable
376 
377 
378 #if defined(__GNUC__) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 7))
379 // C++11 noexcept and Rvalue references are in gcc 4.7 and later
380 #undef ON_NOEXCEPT
381 #define ON_NOEXCEPT noexcept
382 #if !defined(ON_HAS_RVALUEREF)
383 #define ON_HAS_RVALUEREF
384 #endif
385 
386 #else
387 #undef ON_HAS_RVALUEREF
388 #undef ON_NOEXCEPT
389 
390 #endif
391 
392 
393 #elif defined(__BORLANDC__)
394 /*
395 ////////////////////////////////////////////////////////////
396 ////////////////////////////////////////////////////////////
397 //
398 // ON_COMPILER_BORLANDC
399 //
400 */
401 #define ON_COMPILER_BORLANDC
402 
403 #endif
404 
405 
406 #if defined(ON_CLANG_CONSTRUCTOR_BUG)
407 // Clang as implemented by Apple has a bug and is unable to use
408 // a default constructor to initialize const statics.
409 // The Clang error message is
410 //
411 // ...: error: default initialization of an object of const type 'const ...' without a user-provided default constructor
412 //
413 // The ON_CLANG_CONSTRUCTOR_BUG_INIT function is used to replace the call to a default constructor with call
414 // to the copy constructor (which can be default).
415 //
416 // Example"
417 //
418 // class MyClass
419 // {
420 // public:
421 // MyClass() = default;
422 // ~MyClass() = default;
423 // MyClass(const MyClass&) = default;
424 // MyClass& operator=(const MyClass&) = default;
425 //
426 // int m_i = 0;
427 // };
428 // ...
429 // const MyClass c1; // fails with clang, works with gcc, Microsoft CL, ...
430 // const MyClass c2 ON_CLANG_CONSTRUCTOR_BUG_INIT(MyClass); // works with clang, gcc, Microsoft CL, ...
431 //
432 #define ON_CLANG_CONSTRUCTOR_BUG_INIT(ctor) = ctor()
433 #else
434 #define ON_CLANG_CONSTRUCTOR_BUG_INIT(ctor)
435 #endif
436 
437 /*
438 These defines will be set to something more appropriate when
439 opennurbs_system_compiler detects the compiler and platform.
440 */
441 #if !defined(ON_PRAGMA_WARNING_PUSH) && !defined(ON_PRAGMA_WARNING_POP)
442 #define ON_PRAGMA_WARNING_PUSH
443 #define ON_PRAGMA_WARNING_POP
444 #elif !defined(ON_PRAGMA_WARNING_PUSH) || !defined(ON_PRAGMA_WARNING_POP)
445 #error mistake in the compiler specific define setup above
446 #endif
447 
448 #if !defined(ON_PRAGMA_WARNING_DISABLE_MSC)
449 #define ON_PRAGMA_WARNING_DISABLE_MSC(ON_PRAGMA_WARNING_DISABLE_param)
450 #endif
451 
452 #if !defined(ON_PRAGMA_WARNING_DISABLE_CLANG)
453 #define ON_PRAGMA_WARNING_DISABLE_CLANG(ON_PRAGMA_WARNING_DISABLE_param)
454 #endif
455 
456 #if !defined(ON_PRAGMA_WARNING_DISABLE_GNU)
457 #define ON_PRAGMA_WARNING_DISABLE_GNU(ON_PRAGMA_WARNING_DISABLE_param)
458 #endif
459 
460 #if !defined(ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE) && !defined(ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE)
461 #define ON_PRAGMA_WARNING_BEFORE_DIRTY_INCLUDE ON_PRAGMA_WARNING_PUSH
462 #define ON_PRAGMA_WARNING_AFTER_DIRTY_INCLUDE ON_PRAGMA_WARNING_POP
463 #endif
464 
465 #endif
466 
467