Config.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ///
  2. /// \file Pothos/Config.hpp
  3. ///
  4. /// Common macro definitions for library API export.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2021 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. // http://gcc.gnu.org/wiki/Visibility
  12. // Generic helper definitions for shared library support
  13. #if defined _WIN32 || defined __CYGWIN__
  14. #define POTHOS_HELPER_DLL_IMPORT __declspec(dllimport)
  15. #define POTHOS_HELPER_DLL_EXPORT __declspec(dllexport)
  16. #define POTHOS_HELPER_DLL_LOCAL
  17. #else
  18. #if __GNUC__ >= 4
  19. #define POTHOS_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
  20. #define POTHOS_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
  21. #define POTHOS_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
  22. #else
  23. #define POTHOS_HELPER_DLL_IMPORT
  24. #define POTHOS_HELPER_DLL_EXPORT
  25. #define POTHOS_HELPER_DLL_LOCAL
  26. #endif
  27. #endif
  28. // Now we use the generic helper definitions above to define POTHOS_API and POTHOS_LOCAL.
  29. // POTHOS_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build)
  30. // POTHOS_LOCAL is used for non-api symbols.
  31. #define POTHOS_DLL //always building a DLL
  32. #ifdef POTHOS_DLL // defined if POTHOS is compiled as a DLL
  33. #ifdef POTHOS_DLL_EXPORTS // defined if we are building the POTHOS DLL (instead of using it)
  34. #define POTHOS_API POTHOS_HELPER_DLL_EXPORT
  35. #define POTHOS_EXTERN
  36. #else
  37. #define POTHOS_API POTHOS_HELPER_DLL_IMPORT
  38. #define POTHOS_EXTERN extern
  39. #endif // POTHOS_DLL_EXPORTS
  40. #define POTHOS_LOCAL POTHOS_HELPER_DLL_LOCAL
  41. #else // POTHOS_DLL is not defined: this means POTHOS is a static lib.
  42. #define POTHOS_API
  43. #define POTHOS_LOCAL
  44. #define POTHOS_EXTERN
  45. #endif // POTHOS_DLL
  46. // Explicit template specialization can be exported on gnu platforms
  47. // Required on apple clang for consistent type ids in archive system
  48. #if defined _WIN32 || defined __CYGWIN__
  49. #define POTHOS_TEMPLATE_API
  50. #elif __GNUC__ >= 4
  51. #define POTHOS_TEMPLATE_API POTHOS_API
  52. #else
  53. #define POTHOS_TEMPLATE_API
  54. #endif
  55. #ifdef _MSC_VER
  56. #ifndef _USE_MATH_DEFINES
  57. #define _USE_MATH_DEFINES //math.h M_* constants
  58. #endif //_USE_MATH_DEFINES
  59. #endif //_MSC_VER
  60. //deprecated macro for causing warnings on old calls
  61. #ifdef __has_cpp_attribute
  62. # if __has_cpp_attribute(deprecated)
  63. # define POTHOS_DEPRECATED(msg) [[deprecated(msg)]]
  64. # endif
  65. #endif
  66. //fall-back compiler specific support for deprecated
  67. #ifndef POTHOS_DEPRECATED
  68. # if defined(__GNUC__)
  69. # define POTHOS_DEPRECATED(msg) __attribute__((deprecated(msg)))
  70. # elif defined(_MSC_VER)
  71. # define POTHOS_DEPRECATED(msg) __declspec(deprecated(msg))
  72. # else
  73. # pragma message("WARNING: You need to implement DEPRECATED for this compiler")
  74. # define POTHOS_DEPRECATED(msg)
  75. # endif
  76. #endif
  77. /*!
  78. * The function tuple emits a string name + function pointer tuple.
  79. * This macro simplifies specifying a function name more than once
  80. * for API calls that take a string name and function pointer.
  81. *
  82. * Example:
  83. * To simplify this->register("foo", &MyNamespace::MyClass::foo),
  84. * this->register(POTHOS_FCN_TUPLE(MyNamespace::MyClass, foo));
  85. *
  86. * \param classPath the colon separated namespace and class name
  87. * \param functionName the name of a function within the specified classPath
  88. */
  89. #define POTHOS_FCN_TUPLE(classPath, functionName) \
  90. #functionName, &classPath::functionName
  91. #include <ciso646>