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