iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompilerUtil.H
Go to the documentation of this file.
1 /*! @file
2  @author Shane Grant <wgrant@usc.edu>
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_CORE_UTIL_COMPILERUTILS_H
37 #define INCLUDE_NRT_CORE_UTIL_COMPILERUTILS_H
38 
39 #include <boost/preprocessor/stringize.hpp>
40 #include <boost/preprocessor/if.hpp>
41 
42 /*! \defgroup compilerutil Miscellaneous preprocessor utilities related to controlling compilation
43  \ingroup util */
44 
45 // Get the compiler name: (see http://stackoverflow.com/questions/19204792/c-if-elif-endif-dont-seem-to-work for why we
46 // use 2 variables; NRT_COMPILER_NAME is used for macro expansion with the name, NRT_COMPILER used for #if testing):
47 #define NRT_COMPILER_GCC 1
48 #define NRT_COMPILER_CLANG 2
49 #define NRT_COMPILER_OTHER 3
50 
51 #if defined __clang__
52 #define NRT_COMPILER NRT_COMPILER_CLANG
53 #define NRT_COMPILER_NAME clang
54 #elif defined __GNUC__
55 #define NRT_COMPILER NRT_COMPILER_GCC
56 #define NRT_COMPILER_NAME GCC
57 #else
58 #define NRT_COMPILER NRT_COMPILER_OTHER
59 #define NRT_COMPILER_NAME other
60 #endif
61 
62 // The following only works with gcc:
63 #if NRT_COMPILER == NRT_COMPILER_GCC
64 
65 #define NRT_PRAGMA(x) _Pragma(BOOST_PP_STRINGIZE(NRT_COMPILER_NAME x))
66 
67 /*! @def NRT_BEGIN_UNCHECKED_INCLUDES
68  A series of preprocessor directives that turns off specific warnings as
69  errors until the matching NRT_END_UNCHECKED_INCLUDES. This is useful for
70  libraries that are written with code that won't compile under -Wall.
71 
72  Must be followed by a matching NRT_END_UNCHECKED_INCLUDES
73  @ingroup compilerutil */
74 #define NRT_BEGIN_UNCHECKED_INCLUDES NRT_PRAGMA(diagnostic push) \
75  NRT_PRAGMA(diagnostic ignored "-Wpragmas") \
76  NRT_PRAGMA(diagnostic ignored "-Wunknown-pragmas") \
77  NRT_PRAGMA(diagnostic ignored "-Wunused-local-typedefs") \
78  NRT_PRAGMA(diagnostic ignored "-Wattributes") \
79  NRT_PRAGMA(diagnostic ignored "-Wconstant-conversion") \
80  NRT_PRAGMA(diagnostic ignored "-Wenum-compare") \
81  NRT_PRAGMA(diagnostic ignored "-Wunused-but-set-variable") \
82  NRT_PRAGMA(diagnostic ignored "-Wreorder") \
83  NRT_PRAGMA(diagnostic ignored "-Wall")
84 
85 /*! @def NRT_END_UNCHECKED_INCLUDES
86  Turns back on all warnings that were in effect prior to an NRT_BEGIN_UNCHECKED_INCLUDES.
87  @ingroup compilerutil */
88 #define NRT_END_UNCHECKED_INCLUDES NRT_PRAGMA(diagnostic pop)
89 
90 #else // NRT_COMPILER_NAME == GCC
91 #define NRT_BEGIN_UNCHECKED_INCLUDES
92 #define NRT_END_UNCHECKED_INCLUDES
93 #endif
94 
95 #endif // INCLUDE_NRT_CORE_UTIL_COMPILERUTILS_H