azure-core
1.7.0-beta.1
inc
azure
core
dll_import_export.hpp
Go to the documentation of this file.
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
// SPDX-License-Identifier: MIT
3
9
// Everything below applies to Windows builds when building the SDK library as DLL.
10
// We use CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which does most of the job for us, but static data
11
// members do still need to be declared as __declspec(dllimport) for the client code. (See
12
// https://cmake.org/cmake/help/v3.13/prop_tgt/WINDOWS_DLLEXPORT_ALL_SYMBOLS.html)
13
// The way it works is this: each library has its own AZ_xxx_DLLEXPORT macro, which is used as
14
// prefix for public(*) static variables(**), this way: class Class { public:
15
// AZ_xxx_DLLEXPORT static bool IsSomething;
16
// }
17
// And also each cmake file adds a corresponding build definition:
18
// add_compile_build_definitions(AZ_xxx_BEING_BUILT), so it IS defined at the moment the specific
19
// library (xxx) is being built, and is not defined at all other times. The AZ_xxx_DLLEXPORT macro
20
// makes the static variable to be prefixed with dllexport attribute at a time when the (xxx) is
21
// being built, and all other code (other libraries, customer code) see it as dllimport attribute,
22
// when they include the header and consume the static variable from the (xxx) library.
23
// For that reason, each library should have its own AZ_xxx_DLLEXPORT macro: when we build (yyy)
24
// library which consumes (xxx) library, (xxx)'s symbols are dllimport, while, from (yyy)'s point of
25
// view, (yyy)'s symbols are dllexport. Do not reuse dll_import_export.hpp file from other
26
// libraries, do not reuse AZ_xxx_DLLEXPORT, AZ_xxx_BEING_BUILT, AZ_xxx_DLL, or
27
// AZ_xxx_BUILT_AS_DLL names.
28
//
29
// CMakeLists.txt (via az_vcpkg_export()) makes sure that during the SDK build on Windows when SDK
30
// is being built as a DLL, AZ_xxx_DLL is defined. It is also being propagated to any code that
31
// consumes Azure SDK code via CMake, i.e. anything in the build tree of the Azure SDK when building
32
// the entire SDK, OR if a customer code consumes SDK via fetchcontent. In case that the SDK is
33
// being distributed as a package, i.e. vcpkg, the install step (defined in az_vcpkg_export()) will
34
// take care of patching the installed header to carry the knowledge that the library was built as
35
// DLL (and if it was built as both static and dynamic library, there will be no collision because
36
// each installation has its own header installation directory).
37
// (/*(at)AZ_xxx_DLL_INSTALLED_AS_PACKAGE(at)*/ will be replaced with "/**/ + 1 /**/") if the SDK
38
// library was built as Windows DLL. CMakeLists.txt snippet to achieve all this is the following
39
// (***):
40
//
41
// if(WIN32 AND BUILD_SHARED_LIBS)
42
// add_compile_definitions(AZ_xxx_BEING_BUILT)
43
// target_compile_definitions(azure-xxx PUBLIC AZ_xxx_DLL)
44
//
45
// set(AZ_xxx_DLL_INSTALLED_AS_PACKAGE "*/ + 1 /*")
46
// configure_file(
47
// "${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/xxx/dll_import_export.hpp"
48
// "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/azure/xxx/dll_import_export.hpp"
49
// @ONLY)
50
// unset(AZ_xxx_DLL_INSTALLED_AS_PACKAGE)
51
// endif()
52
//
53
// And if the SDK is being consumed using the neither option from the above (neither cmake
54
// fetchcontent nor a package, but some custom build process that is unknown to us, yet uncapable of
55
// handling AZ_xxx_BUILT_AS_DLL correctly), there is always an option for th consumer to define
56
// AZ_xxx_DLL manually.
57
// --
58
// (*) - could be private, but if a public inline class member function uses it, it is effectively
59
// public and the export attribute should be used.
60
// (**) - mutable or immutable (const) static variables. But not constexprs. Constexprs don't need
61
// the export attribute.
62
// (***) - note that we condition on WIN32 (i.e. all Windows including UWP, per CMake definition),
63
// and not on MSVC. That's because dllimport/dllexport is potentially needed on Windows platform
64
// regardless of the compiler used, but GCC or Clang have different syntax for that. We don't handle
65
// other compilers on Windows currentlty, but later we may add support (see "#if defined(_MSC_VER)"
66
// below).
67
68
#pragma once
69
76
#if defined(AZ_CORE_DLL) || (0
/*@AZ_CORE_DLL_INSTALLED_AS_PACKAGE@*/
)
77
#define AZ_CORE_BUILT_AS_DLL 1
78
#else
79
#define AZ_CORE_BUILT_AS_DLL 0
80
#endif
81
82
#if AZ_CORE_BUILT_AS_DLL
83
#if defined(_MSC_VER)
84
#if defined(AZ_CORE_BEING_BUILT)
85
#define AZ_CORE_DLLEXPORT __declspec(dllexport)
86
#else // !defined(AZ_CORE_BEING_BUILT)
87
#define AZ_CORE_DLLEXPORT __declspec(dllimport)
88
#endif // AZ_CORE_BEING_BUILT
89
#else // !defined(_MSC_VER)
90
#define AZ_CORE_DLLEXPORT
91
#endif // _MSC_VER
92
#else // !AZ_CORE_BUILT_AS_DLL
93
#define AZ_CORE_DLLEXPORT
94
#endif // AZ_CORE_BUILT_AS_DLL
95
96
#undef AZ_CORE_BUILT_AS_DLL
97
101
namespace
Azure
{
102
106
namespace
Core {
107
111
namespace
Credentials {
112
}
113
117
namespace
Cryptography {
118
}
119
123
namespace
Diagnostics {
124
}
125
129
namespace
Http {
130
134
namespace
Policies {
135
}
136
}
// namespace Http
137
141
namespace
IO {
142
}
143
}
// namespace Core
144
}
// namespace Azure
Azure
Azure SDK abstractions.
Definition:
azure_assert.hpp:55
Generated by
1.8.18