xmlwrapp
Lightweight C++ XML parsing library
Loading...
Searching...
No Matches
export.h
1/*
2 * Copyright (C) 2010 Vaclav Slavik <vslavik@gmail.com>
3 * All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * 3. Neither the name of the Author nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#ifndef _xmlwrapp_export_h_
34#define _xmlwrapp_export_h_
35
36#if defined(_WIN32)
37 // Note that DLL_EXPORT is predefined by libtool when building the DLLs,
38 // but when using them, XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL must be
39 // predefined by the application.
40 #if defined(DLL_EXPORT)
41 #if defined(XMLWRAPP_BUILD)
42 #define XMLWRAPP_API __declspec(dllexport)
43 #endif
44
45 #if defined(XSLTWRAPP_BUILD)
46 #define XSLTWRAPP_API __declspec(dllexport)
47 #endif
48 #endif
49
50 #if defined(XMLWRAPP_USE_DLL)
51 #define XMLWRAPP_API __declspec(dllimport)
52 #endif
53
54 #if defined(XSLTWRAPP_USE_DLL)
55 #define XSLTWRAPP_API __declspec(dllimport)
56 #endif
57#elif defined(HAVE_VISIBILITY)
58 #define XMLWRAPP_API __attribute__ ((visibility("default")))
59 #define XSLTWRAPP_API __attribute__ ((visibility("default")))
60#endif
61
62#ifndef XMLWRAPP_API
63 #define XMLWRAPP_API
64#endif
65
66#ifndef XSLTWRAPP_API
67 #define XSLTWRAPP_API
68#endif
69
70// Special case of classes having only inline functions: they don't need to be
71// DLL-exported when using MSVS and, if they derive from any standard classes,
72// exporting them just results in annoying warnings, but they do have to have
73// public visibility when using clang/libc++ under macOS as otherwise their
74// type info would be different in the application and the library, resulting
75// in fatal problems, such as inability to catch the exceptions thrown by the
76// library.
77//
78// So define a special macro which must be used for such classes only.
79#if defined(_WIN32)
80 #define XMLWRAPP_INLINE_API
81#else
82 #define XMLWRAPP_INLINE_API XMLWRAPP_API
83#endif
84
85#if defined(__clang__)
86 #if defined(__has_extension) && __has_extension(attribute_deprecated_with_message)
87 #define XMLWRAPP_DEPRECATED(msg) __attribute__((deprecated(msg)))
88 #else
89 #define XMLWRAPP_DEPRECATED(msg) __attribute__((deprecated))
90 #endif
91#elif defined(__GNUC__)
92 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
93 #define XMLWRAPP_DEPRECATED(msg) __attribute__((deprecated(msg)))
94 #else
95 #define XMLWRAPP_DEPRECATED(msg) __attribute__((deprecated))
96 #endif
97#elif defined(_MSC_VER)
98 #if _MSC_VER >= 1400
99 #define XMLWRAPP_DEPRECATED(msg) __declspec(deprecated("deprecated: " msg))
100 #elif _MSC_VER >= 1300
101 #define XMLWRAPP_DEPRECATED(msg) __declspec(deprecated)
102 #else
103 #define XMLWRAPP_DEPRECATED(msg)
104 #endif
105#else
106 #define XMLWRAPP_DEPRECATED(msg)
107#endif
108
109// Define a macro allowing to disable MSVC warning about using non-DLL-exported
110// classes (typically from the standard library itself) as members of the
111// DLL-exported classes because this not a problem as long as both the main
112// application and the DLL use the same (or at least ABI-compatible) CRT
113// version, which should always be the case in practice.
114//
115// The first macro should be used before declaring such members in the classes
116// using XMLWRAPP_API declaration and the second one after declaring them to
117// restore the default warning level.
118//
119// Both macros do nothing for non-MSVC compilers.
120#if defined(_MSC_VER)
121 #define XMLWRAPP_MSVC_SUPPRESS_DLL_MEMBER_WARN \
122 __pragma( warning(push) ) \
123 __pragma( warning(disable:4251) ) /* Class needs to have dll-interface to be used by clients of class */
124 #define XMLWRAPP_MSVC_RESTORE_DLL_MEMBER_WARN \
125 __pragma( warning(pop) )
126#else
127 #define XMLWRAPP_MSVC_SUPPRESS_DLL_MEMBER_WARN
128 #define XMLWRAPP_MSVC_RESTORE_DLL_MEMBER_WARN
129#endif
130
131#endif // _xmlwrapp_export_h_