1/****************************************************************************
2 *
3 * config/public-macros.h
4 *
5 * Define a set of compiler macros used in public FreeType headers.
6 *
7 * Copyright (C) 2020-2023 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18 /*
19 * The definitions in this file are used by the public FreeType headers
20 * and thus should be considered part of the public API.
21 *
22 * Other compiler-specific macro definitions that are not exposed by the
23 * FreeType API should go into
24 * `include/freetype/internal/compiler-macros.h` instead.
25 */
26#ifndef FREETYPE_CONFIG_PUBLIC_MACROS_H_
27#define FREETYPE_CONFIG_PUBLIC_MACROS_H_
28
29 /*
30 * `FT_BEGIN_HEADER` and `FT_END_HEADER` might have already been defined
31 * by `freetype/config/ftheader.h`, but we don't want to include this
32 * header here, so redefine the macros here only when needed. Their
33 * definition is very stable, so keeping them in sync with the ones in the
34 * header should not be a maintenance issue.
35 */
36#ifndef FT_BEGIN_HEADER
37#ifdef __cplusplus
38#define FT_BEGIN_HEADER extern "C" {
39#else
40#define FT_BEGIN_HEADER /* empty */
41#endif
42#endif /* FT_BEGIN_HEADER */
43
44#ifndef FT_END_HEADER
45#ifdef __cplusplus
46#define FT_END_HEADER }
47#else
48#define FT_END_HEADER /* empty */
49#endif
50#endif /* FT_END_HEADER */
51
52
53FT_BEGIN_HEADER
54
55 /*
56 * Mark a function declaration as public. This ensures it will be
57 * properly exported to client code. Place this before a function
58 * declaration.
59 *
60 * NOTE: This macro should be considered an internal implementation
61 * detail, and not part of the FreeType API. It is only defined here
62 * because it is needed by `FT_EXPORT`.
63 */
64
65 /* Visual C, mingw */
66#if defined( _WIN32 )
67
68#if defined( FT2_BUILD_LIBRARY ) && defined( DLL_EXPORT )
69#define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllexport )
70#elif defined( DLL_IMPORT )
71#define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllimport )
72#endif
73
74 /* gcc, clang */
75#elif ( defined( __GNUC__ ) && __GNUC__ >= 4 ) || defined( __clang__ )
76#define FT_PUBLIC_FUNCTION_ATTRIBUTE \
77 __attribute__(( visibility( "default" ) ))
78
79 /* Sun */
80#elif defined( __SUNPRO_C ) && __SUNPRO_C >= 0x550
81#define FT_PUBLIC_FUNCTION_ATTRIBUTE __global
82#endif
83
84
85#ifndef FT_PUBLIC_FUNCTION_ATTRIBUTE
86#define FT_PUBLIC_FUNCTION_ATTRIBUTE /* empty */
87#endif
88
89
90 /*
91 * Define a public FreeType API function. This ensures it is properly
92 * exported or imported at build time. The macro parameter is the
93 * function's return type as in:
94 *
95 * FT_EXPORT( FT_Bool )
96 * FT_Object_Method( FT_Object obj,
97 * ... );
98 *
99 * NOTE: This requires that all `FT_EXPORT` uses are inside
100 * `FT_BEGIN_HEADER ... FT_END_HEADER` blocks. This guarantees that the
101 * functions are exported with C linkage, even when the header is included
102 * by a C++ source file.
103 */
104#define FT_EXPORT( x ) FT_PUBLIC_FUNCTION_ATTRIBUTE extern x
105
106
107 /*
108 * `FT_UNUSED` indicates that a given parameter is not used -- this is
109 * only used to get rid of unpleasant compiler warnings.
110 *
111 * Technically, this was not meant to be part of the public API, but some
112 * third-party code depends on it.
113 */
114#ifndef FT_UNUSED
115#define FT_UNUSED( arg ) ( (arg) = (arg) )
116#endif
117
118
119 /*
120 * Support for casts in both C and C++.
121 */
122#ifdef __cplusplus
123#define FT_STATIC_CAST( type, var ) static_cast<type>(var)
124#define FT_REINTERPRET_CAST( type, var ) reinterpret_cast<type>(var)
125
126#define FT_STATIC_BYTE_CAST( type, var ) \
127 static_cast<type>( static_cast<unsigned char>( var ) )
128#else
129#define FT_STATIC_CAST( type, var ) (type)(var)
130#define FT_REINTERPRET_CAST( type, var ) (type)(var)
131
132#define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var)
133#endif
134
135
136FT_END_HEADER
137
138#endif /* FREETYPE_CONFIG_PUBLIC_MACROS_H_ */
139