YARP
Yet Another Robot Platform
api.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_CONF_API_H
11 #define YARP_CONF_API_H
12 
13 #include <yarp/conf/compiler.h>
14 #include <yarp/conf/system.h>
15 
16 /*
17 
18 The purpose of this header file is to correctly define:
19  YARP_EXPORT
20  YARP_IMPORT
21 Since YARP is composed of several libraries, we may be compiling one
22 library (and exporting its symbols) while using another (and importing
23 its symbols). The set of YARP libraries is rather open-ended so,
24 it is better not to try enumerating them here. Given that, the
25 recommended usage of this header within YARP is:
26 //
27 #include <yarp/conf/api.h>
28 #ifndef YARP_os_API
29 # ifdef YARP_os_EXPORTS
30 # define YARP_os_API YARP_EXPORT
31 # define YARP_os_EXTERN YARP_EXPORT_EXTERN
32 # else
33 # define YARP_os_API YARP_IMPORT
34 # define YARP_os_EXTERN YARP_IMPORT_EXTERN
35 # endif
36 # define YARP_os_DEPRECATED_API YARP_DEPRECATED_API
37 # define YARP_os_DEPRECATED_API_MSG(X) YARP_DEPRECATED_API_MSG(X)
38 #endif
39 
40 (replace YARP_os with CMake target name for library)
41 
42 */
43 
44 // Defined if YARP is compiled as a shared library
45 #define YARP_DLL
46 
47 // Defined if YARP is configured to apply filter out the implementation library
48 // from the ABI
49 /* #undef YARP_FILTER_impl */
50 
51 #if defined _WIN32 || defined __CYGWIN__
52 # define YARP_HELPER_DLL_IMPORT __declspec(dllimport)
53 # define YARP_HELPER_DLL_EXPORT __declspec(dllexport)
54 # define YARP_HELPER_DLL_LOCAL
55 # define YARP_HELPER_DLL_IMPORT_EXTERN extern
56 # define YARP_HELPER_DLL_EXPORT_EXTERN
57 #elif (YARP_COMPILER_IS_GNU && (__GNUC__ >= 4)) || YARP_COMPILER_IS_Clang || YARP_COMPILER_IS_AppleClang
58 # define YARP_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
59 # define YARP_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
60 # define YARP_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
61 # define YARP_HELPER_DLL_IMPORT_EXTERN
62 # define YARP_HELPER_DLL_EXPORT_EXTERN
63 #else
64 # define YARP_HELPER_DLL_IMPORT
65 # define YARP_HELPER_DLL_EXPORT
66 # define YARP_HELPER_DLL_LOCAL
67 # define YARP_HELPER_DLL_IMPORT_EXTERN
68 # define YARP_HELPER_DLL_EXPORT_EXTERN
69 #endif
70 
71 #if defined YARP_DLL
72 # define YARP_IMPORT YARP_HELPER_DLL_IMPORT
73 # define YARP_EXPORT YARP_HELPER_DLL_EXPORT
74 # define YARP_LOCAL YARP_HELPER_DLL_LOCAL
75 # define YARP_IMPORT_EXTERN YARP_HELPER_DLL_IMPORT_EXTERN
76 # define YARP_EXPORT_EXTERN YARP_HELPER_DLL_EXPORT_EXTERN
77 #else
78 # define YARP_IMPORT
79 # define YARP_EXPORT
80 # define YARP_LOCAL
81 # define YARP_IMPORT_EXTERN
82 # define YARP_EXPORT_EXTERN
83 #endif
84 
85 // YARP_DEPRECATED and YARP_DEPRECATED_MSG are defined in compiler.h, but we
86 // want warnings disabled if YARP_NO_DEPRECATED_WARNINGS is enabled
87 #if defined YARP_NO_DEPRECATED_WARNINGS
88 # undef YARP_DEPRECATED
89 # undef YARP_DEPRECATED_MSG
90 #endif
91 // If YARP_DEPRECATED and YARP_DEPRECATED_MSG are undefined, define them empty
92 #ifndef YARP_DEPRECATED
93 # define YARP_DEPRECATED
94 # define YARP_DEPRECATED_MSG(X)
95 #endif
96 
97 
98 // Position for the attribute [[deprecated]] for typedef is different compared
99 // to compiler-specific attributes
100 #if defined(YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED) && YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED
101 # define YARP_DEPRECATED_TYPEDEF YARP_DEPRECATED typedef
102 # define YARP_DEPRECATED_TYPEDEF_MSG(x) YARP_DEPRECATED_MSG(x) typedef
103 #else
104 # define YARP_DEPRECATED_TYPEDEF typedef YARP_DEPRECATED
105 # define YARP_DEPRECATED_TYPEDEF_MSG(x) typedef YARP_DEPRECATED_MSG(x)
106 #endif
107 
108 
109 // Due to a GCC bug, it is not a good idea to mix C++14 and compiler-specific attributes
110 // For this reason, only for usage with visibility macro, we define the compiler-specific attributes
111 // See https://github.com/robotology/yarp/issues/1531
112 #if defined YARP_NO_DEPRECATED_WARNINGS
113 # define YARP_DEPRECATED_COMPILER_SPECIFIC
114 # define YARP_DEPRECATED_COMPILER_SPECIFIC_MSG(x)
115 #elif YARP_COMPILER_IS_GNU || YARP_COMPILER_IS_Clang
116 # define YARP_DEPRECATED_COMPILER_SPECIFIC __attribute__((__deprecated__))
117 # define YARP_DEPRECATED_COMPILER_SPECIFIC_MSG(MSG) __attribute__((__deprecated__(MSG)))
118 #elif YARP_COMPILER_IS_MSVC
119 # define YARP_DEPRECATED_COMPILER_SPECIFIC __declspec(deprecated)
120 # define YARP_DEPRECATED_COMPILER_SPECIFIC_MSG(MSG) __declspec(deprecated(MSG))
121 #else
122 # define YARP_DEPRECATED_COMPILER_SPECIFIC
123 # define YARP_DEPRECATED_COMPILER_SPECIFIC_MSG(MSG)
124 #endif
125 
126 #ifdef YARP_NO_DEPRECATED
127 # define YARP_DEPRECATED_API YARP_DEPRECATED
128 # define YARP_DEPRECATED_API_MSG(X) YARP_DEPRECATED_MSG(X)
129 #else
130 # define YARP_DEPRECATED_API YARP_DEPRECATED_COMPILER_SPECIFIC YARP_os_API
131 # define YARP_DEPRECATED_API_MSG(X) YARP_DEPRECATED_COMPILER_SPECIFIC_MSG(X) YARP_os_API
132 #endif
133 
134 #ifdef BUILDING_YARP
135 # define YARP_DEPRECATED_INTERNAL YARP_DEPRECATED
136 # define YARP_DEPRECATED_INTERNAL_MSG(X) YARP_DEPRECATED_MSG(X)
137 #else
138 # define YARP_DEPRECATED_INTERNAL
139 # define YARP_DEPRECATED_INTERNAL_MSG(X)
140 #endif
141 
142 // YARP_NODISCARD: print a warning if the result unused
143 #if (YARP_COMPILER_IS_GNU && (__GNUC__ >= 4)) || YARP_COMPILER_IS_Clang || YARP_COMPILER_IS_AppleClang
144 # define YARP_NODISCARD __attribute__ ((warn_unused_result))
145 #elif YARP_COMPILER_IS_MSVC && (_MSC_VER >= 1700)
146 # define YARP_NODISCARD _Check_return_
147 #else
148 # define YARP_NODISCARD
149 #endif
150 
151 // YARP_NORETURN
152 #if YARP_COMPILER_CXX_ATTRIBUTES
153 # define YARP_NORETURN [[noreturn]]
154 #else
155 # define YARP_NORETURN
156 #endif
157 
158 // YARP_UNUSED: Suppress unused variable warnings
159 #define YARP_UNUSED(var) (void)var
160 
161 
162 #endif // YARP_CONF_API_H
compiler.h
system.h