Skip to content

Commit 155a366

Browse files
authored
Merge pull request microsoft#92 from wravery/master
Use explicit DLL exports on Windows
2 parents b560cba + 4fe8a81 commit 155a366

File tree

12 files changed

+257
-132
lines changed

12 files changed

+257
-132
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33

44
cmake_minimum_required(VERSION 3.8.2)
5-
project(cppgraphqlgen VERSION 3.0.0)
5+
project(cppgraphqlgen VERSION 3.2.0)
66

77
set(CMAKE_CXX_STANDARD 17)
88

@@ -12,11 +12,6 @@ set(GRAPHQL_INSTALL_CMAKE_DIR lib/cmake CACHE PATH "CMake config files install d
1212

1313
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
1414

15-
if(WIN32 AND BUILD_SHARED_LIBS)
16-
# Let CMake figure out the exports for the SHARED library (DLL) on Windows.
17-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
18-
endif()
19-
2015
function(add_bigobj_flag target)
2116
if(MSVC)
2217
# MSVC requires the /bigobj flag if the number of sections gets too big.

include/graphqlservice/GraphQLParse.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#ifndef GRAPHQLPARSE_H
77
#define GRAPHQLPARSE_H
88

9+
#ifdef GRAPHQL_DLLEXPORTS
10+
#ifdef IMPL_GRAPHQLPEG_DLL
11+
#define GRAPHQLPEG_EXPORT __declspec(dllexport)
12+
#else // !IMPL_GRAPHQLPEG_DLL
13+
#define GRAPHQLPEG_EXPORT __declspec(dllimport)
14+
#endif // !IMPL_GRAPHQLPEG_DLL
15+
#else // !GRAPHQL_DLLEXPORTS
16+
#define GRAPHQLPEG_EXPORT
17+
#endif // !GRAPHQL_DLLEXPORTS
18+
919
#include <memory>
1020
#include <string_view>
1121

@@ -22,12 +32,12 @@ struct ast
2232
bool validated = false;
2333
};
2434

25-
ast parseString(std::string_view input);
26-
ast parseFile(std::string_view filename);
35+
GRAPHQLPEG_EXPORT ast parseString(std::string_view input);
36+
GRAPHQLPEG_EXPORT ast parseFile(std::string_view filename);
2737

2838
} /* namespace peg */
2939

30-
peg::ast operator "" _graphql(const char* text, size_t size);
40+
GRAPHQLPEG_EXPORT peg::ast operator "" _graphql(const char* text, size_t size);
3141

3242
} /* namespace graphql */
3343

include/graphqlservice/GraphQLResponse.h

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#ifndef GRAPHQLRESPONSE_H
77
#define GRAPHQLRESPONSE_H
88

9+
#ifdef GRAPHQL_DLLEXPORTS
10+
#ifdef IMPL_GRAPHQLRESPONSE_DLL
11+
#define GRAPHQLRESPONSE_EXPORT __declspec(dllexport)
12+
#else // !IMPL_GRAPHQLRESPONSE_DLL
13+
#define GRAPHQLRESPONSE_EXPORT __declspec(dllimport)
14+
#endif // !IMPL_GRAPHQLRESPONSE_DLL
15+
#else // !GRAPHQL_DLLEXPORTS
16+
#define GRAPHQLRESPONSE_EXPORT
17+
#endif // !GRAPHQL_DLLEXPORTS
18+
919
#include <memory>
1020
#include <string>
1121
#include <vector>
@@ -102,47 +112,47 @@ struct TypedData;
102112
// Represent a discriminated union of GraphQL response value types.
103113
struct Value
104114
{
105-
Value(Type type = Type::Null);
106-
~Value();
115+
GRAPHQLRESPONSE_EXPORT Value(Type type = Type::Null);
116+
GRAPHQLRESPONSE_EXPORT ~Value();
107117

108-
explicit Value(const char* value);
109-
explicit Value(StringType&& value);
110-
explicit Value(BooleanType value);
111-
explicit Value(IntType value);
112-
explicit Value(FloatType value);
118+
GRAPHQLRESPONSE_EXPORT explicit Value(const char* value);
119+
GRAPHQLRESPONSE_EXPORT explicit Value(StringType&& value);
120+
GRAPHQLRESPONSE_EXPORT explicit Value(BooleanType value);
121+
GRAPHQLRESPONSE_EXPORT explicit Value(IntType value);
122+
GRAPHQLRESPONSE_EXPORT explicit Value(FloatType value);
113123

114-
Value(Value&& other) noexcept;
115-
explicit Value(const Value& other);
124+
GRAPHQLRESPONSE_EXPORT Value(Value&& other) noexcept;
125+
GRAPHQLRESPONSE_EXPORT explicit Value(const Value& other);
116126

117-
Value& operator=(Value&& rhs) noexcept;
118-
Value& operator=(const Value& rhs) = delete;
127+
GRAPHQLRESPONSE_EXPORT Value& operator=(Value&& rhs) noexcept;
128+
GRAPHQLRESPONSE_EXPORT Value& operator=(const Value& rhs) = delete;
119129

120130
// Comparison
121-
bool operator==(const Value& rhs) const noexcept;
122-
bool operator!=(const Value& rhs) const noexcept;
131+
GRAPHQLRESPONSE_EXPORT bool operator==(const Value& rhs) const noexcept;
132+
GRAPHQLRESPONSE_EXPORT bool operator!=(const Value& rhs) const noexcept;
123133

124134
// Check the Type
125-
Type type() const noexcept;
135+
GRAPHQLRESPONSE_EXPORT Type type() const noexcept;
126136

127137
// JSON doesn't distinguish between Type::String and Type::EnumValue, so if this value comes
128138
// from JSON and it's a string we need to track the fact that it can be interpreted as either.
129-
Value&& from_json() noexcept;
130-
bool maybe_enum() const noexcept;
139+
GRAPHQLRESPONSE_EXPORT Value&& from_json() noexcept;
140+
GRAPHQLRESPONSE_EXPORT bool maybe_enum() const noexcept;
131141

132142
// Valid for Type::Map or Type::List
133-
void reserve(size_t count);
134-
size_t size() const;
143+
GRAPHQLRESPONSE_EXPORT void reserve(size_t count);
144+
GRAPHQLRESPONSE_EXPORT size_t size() const;
135145

136146
// Valid for Type::Map
137-
void emplace_back(std::string&& name, Value&& value);
138-
MapType::const_iterator find(const std::string& name) const;
139-
MapType::const_iterator begin() const;
140-
MapType::const_iterator end() const;
141-
const Value& operator[](const std::string& name) const;
147+
GRAPHQLRESPONSE_EXPORT void emplace_back(std::string&& name, Value&& value);
148+
GRAPHQLRESPONSE_EXPORT MapType::const_iterator find(const std::string& name) const;
149+
GRAPHQLRESPONSE_EXPORT MapType::const_iterator begin() const;
150+
GRAPHQLRESPONSE_EXPORT MapType::const_iterator end() const;
151+
GRAPHQLRESPONSE_EXPORT const Value& operator[](const std::string& name) const;
142152

143153
// Valid for Type::List
144-
void emplace_back(Value&& value);
145-
const Value& operator[](size_t index) const;
154+
GRAPHQLRESPONSE_EXPORT void emplace_back(Value&& value);
155+
GRAPHQLRESPONSE_EXPORT const Value& operator[](size_t index) const;
146156

147157
// Specialized for all single-value Types.
148158
template <typename ValueType>
@@ -178,6 +188,26 @@ struct Value
178188
std::unique_ptr<TypedData> _data;
179189
};
180190

191+
#ifdef GRAPHQL_DLLEXPORTS
192+
// Export all of the specialized template methods
193+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<StringType>(StringType&& value);
194+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<BooleanType>(BooleanType value);
195+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<IntType>(IntType value);
196+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<FloatType>(FloatType value);
197+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<ScalarType>(ScalarType&& value);
198+
template <> GRAPHQLRESPONSE_EXPORT const MapType& Value::get<MapType>() const;
199+
template <> GRAPHQLRESPONSE_EXPORT const ListType& Value::get<ListType>() const;
200+
template <> GRAPHQLRESPONSE_EXPORT const StringType& Value::get<StringType>() const;
201+
template <> GRAPHQLRESPONSE_EXPORT BooleanType Value::get<BooleanType>() const;
202+
template <> GRAPHQLRESPONSE_EXPORT IntType Value::get<IntType>() const;
203+
template <> GRAPHQLRESPONSE_EXPORT FloatType Value::get<FloatType>() const;
204+
template <> GRAPHQLRESPONSE_EXPORT const ScalarType& Value::get<ScalarType>() const;
205+
template <> GRAPHQLRESPONSE_EXPORT MapType Value::release<MapType>();
206+
template <> GRAPHQLRESPONSE_EXPORT ListType Value::release<ListType>();
207+
template <> GRAPHQLRESPONSE_EXPORT StringType Value::release<StringType>();
208+
template <> GRAPHQLRESPONSE_EXPORT ScalarType Value::release<ScalarType>();
209+
#endif // GRAPHQL_DLLEXPORTS
210+
181211
} /* namespace graphql::response */
182212

183213
#endif // GRAPHQLRESPONSE_H

0 commit comments

Comments
 (0)