1 /* Copyright 2017-2021 PaGMO development team 2 3 This file is part of the PaGMO library. 4 5 The PaGMO library is free software; you can redistribute it and/or modify 6 it under the terms of either: 7 8 * the GNU Lesser General Public License as published by the Free 9 Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 or 13 14 * the GNU General Public License as published by the Free Software 15 Foundation; either version 3 of the License, or (at your option) any 16 later version. 17 18 or both in parallel, as here. 19 20 The PaGMO library is distributed in the hope that it will be useful, but 21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23 for more details. 24 25 You should have received copies of the GNU General Public License and the 26 GNU Lesser General Public License along with the PaGMO library. If not, 27 see https://www.gnu.org/licenses/. */ 28 29 #ifndef PAGMO_DETAIL_VISIBILITY_HPP 30 #define PAGMO_DETAIL_VISIBILITY_HPP 31 32 #include <pagmo/config.hpp> 33 34 // The visibility setup makes sense only for shared 35 // library builds. 36 #if defined(PAGMO_STATIC_BUILD) 37 38 #define PAGMO_DLL_PUBLIC 39 #define PAGMO_DLL_LOCAL 40 #define PAGMO_DLL_PUBLIC_INLINE_CLASS 41 42 #else 43 44 // Convenience macros for setting the visibility of entities 45 // when building/using the shared library. Mostly inspired by: 46 // https://gcc.gnu.org/wiki/Visibility 47 // We check first for Windows, where we assume every compiler 48 // knows dllexport/dllimport. On other platforms, we use the GCC-like 49 // syntax for GCC, clang and ICC. Otherwise, we leave the definitions 50 // empty. 51 #if defined(_WIN32) || defined(__CYGWIN__) 52 53 #if defined(pagmo_EXPORTS) 54 55 #define PAGMO_DLL_PUBLIC __declspec(dllexport) 56 57 #else 58 59 #define PAGMO_DLL_PUBLIC __declspec(dllimport) 60 61 #endif 62 63 #define PAGMO_DLL_LOCAL 64 65 #elif defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) 66 67 #define PAGMO_DLL_PUBLIC __attribute__((visibility("default"))) 68 #define PAGMO_DLL_LOCAL __attribute__((visibility("hidden"))) 69 70 #else 71 72 #define PAGMO_DLL_PUBLIC 73 #define PAGMO_DLL_LOCAL 74 75 #endif 76 77 // NOTE: it seems like on Windows using dllimport/dllexport on inline classes 78 // is generally not helpful (and potentially harmful), apart from special use cases: 79 // https://stackoverflow.com/questions/8876279/c-inline-functions-with-dllimport-dllexport 80 // https://stackoverflow.com/questions/24511376/how-to-dllexport-a-class-derived-from-stdruntime-error 81 // https://devblogs.microsoft.com/oldnewthing/20140109-00/?p=2123 82 // Setting the visibility attribute on GCC-like compilers for inline classes, however, seems to be ok. 83 // Thus, we use a specialised definition for marking "public"ly visible inline classes. 84 #if defined(_WIN32) || defined(__CYGWIN__) 85 86 #define PAGMO_DLL_PUBLIC_INLINE_CLASS 87 88 #else 89 90 #define PAGMO_DLL_PUBLIC_INLINE_CLASS PAGMO_DLL_PUBLIC 91 92 #endif 93 94 #endif 95 96 #endif 97