1// Copyright (c) ONNX Project Contributors.
2// Licensed under the MIT license.
3
4#ifndef ONNX_ONNX_PB_H
5#define ONNX_ONNX_PB_H
6
7// Defines ONNX_EXPORT and ONNX_IMPORT. On Windows, this corresponds to
8// different declarations (dllexport and dllimport). On Linux/Mac, it just
9// resolves to the same "default visibility" setting.
10#if defined(_MSC_VER)
11#if defined(ONNX_BUILD_SHARED_LIBS) || defined(ONNX_BUILD_MAIN_LIB)
12#define ONNX_EXPORT __declspec(dllexport)
13#define ONNX_IMPORT __declspec(dllimport)
14#else
15#define ONNX_EXPORT
16#define ONNX_IMPORT
17#endif
18#else
19#if defined(__GNUC__)
20#define ONNX_EXPORT __attribute__((__visibility__("default")))
21#else
22#define ONNX_EXPORT
23#endif
24#define ONNX_IMPORT ONNX_EXPORT
25#endif
26
27// ONNX_API is a macro that, depends on whether you are building the
28// main ONNX library or not, resolves to either ONNX_EXPORT or
29// ONNX_IMPORT.
30//
31// This is used in e.g. ONNX's protobuf files: when building the main library,
32// it is defined as ONNX_EXPORT to fix a Windows global-variable-in-dll
33// issue, and for anyone dependent on ONNX it will be defined as
34// ONNX_IMPORT. ONNX_BUILD_MAIN_LIB can also be set when being built
35// statically if ONNX is being linked into a shared library that wants
36// to export the ONNX APIs and classes.
37//
38// More details on Windows dllimport / dllexport can be found at
39// https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx
40//
41// This solution is similar to
42// https://github.com/pytorch/pytorch/blob/master/caffe2/core/common.h
43#if defined(ONNX_BUILD_SHARED_LIBS) || defined(ONNX_BUILD_MAIN_LIB)
44#define ONNX_API ONNX_EXPORT
45#else
46#define ONNX_API ONNX_IMPORT
47#endif
48
49#ifdef ONNX_ML
50#include "onnx/onnx-ml.pb.h"
51#else
52#include "onnx/onnx.pb.h"
53#endif
54
55#endif // ! ONNX_ONNX_PB_H
56