HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
export.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
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 are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 #pragma once
33 
34 
35 /// \file
36 /// Macros necessary for proper symbol export from dynamic libraries.
37 
38 
39 ///
40 /// On Windows, when compiling code that will end up in a DLL, symbols
41 /// must be marked as 'exported' (i.e. __declspec(dllexport)) or they
42 /// won't be visible to programs linking against the DLL.
43 ///
44 /// In addition, when compiling the application code that calls the DLL,
45 /// if a routine is marked as 'imported' (i.e. __declspec(dllimport)),
46 /// the compiler can be smart about eliminating a level of calling
47 /// indirection. But you DON'T want to use __declspec(dllimport) when
48 /// calling a function from within its own DLL (it will still compile
49 /// correctly, just not with maximal efficiency). Which is quite the
50 /// dilemma since the same header file is used by both the library and
51 /// its clients. Sheesh!
52 ///
53 /// But on Linux/OSX as well, we want to only have the DSO export the
54 /// symbols we designate as the public interface. So we link with
55 /// -fvisibility=hidden to default to hiding the symbols. See
56 /// http://gcc.gnu.org/wiki/Visibility
57 ///
58 /// We solve this awful mess by defining these macros:
59 ///
60 /// OIIO_API - used for the OpenImageIO public API. Normally, assumes
61 /// that it's being seen by a client of the library, and
62 /// therefore declare as 'imported'. But if
63 /// OpenImageIO_EXPORT is defined (as is done by CMake
64 /// when compiling the library itself), change the
65 /// declaration to 'exported'.
66 /// OIIO_EXPORT - explicitly exports a symbol that isn't part of the
67 /// public API but still needs to be visible.
68 /// OIIO_LOCAL - explicitly hides a symbol that might otherwise be
69 /// exported
70 ///
71 ///
72 
73 #if defined(_WIN32) || defined(__CYGWIN__)
74 # ifndef OIIO_STATIC_BUILD
75 # define OIIO_IMPORT __declspec(dllimport)
76 # define OIIO_EXPORT __declspec(dllexport)
77 # else
78 # define OIIO_IMPORT
79 # define OIIO_EXPORT
80 # endif
81 # define OIIO_LOCAL
82 #else
83 # define OIIO_IMPORT __attribute__((visibility("default")))
84 # define OIIO_EXPORT __attribute__((visibility("default")))
85 # define OIIO_LOCAL __attribute__((visibility("hidden")))
86 #endif
87 
88 #if defined(OpenImageIO_EXPORTS) || defined(OpenImageIO_Util_EXPORTS)
89 # define OIIO_API OIIO_EXPORT
90 #else
91 # define OIIO_API OIIO_IMPORT
92 #endif