Skip to content

Use explicit DLL exports on Windows #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
project(cppgraphqlgen VERSION 3.0.0)
project(cppgraphqlgen VERSION 3.2.0)

set(CMAKE_CXX_STANDARD 17)

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

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

if(WIN32 AND BUILD_SHARED_LIBS)
# Let CMake figure out the exports for the SHARED library (DLL) on Windows.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

function(add_bigobj_flag target)
if(MSVC)
# MSVC requires the /bigobj flag if the number of sections gets too big.
Expand Down
16 changes: 13 additions & 3 deletions include/graphqlservice/GraphQLParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#ifndef GRAPHQLPARSE_H
#define GRAPHQLPARSE_H

#ifdef GRAPHQL_DLLEXPORTS
#ifdef IMPL_GRAPHQLPEG_DLL
#define GRAPHQLPEG_EXPORT __declspec(dllexport)
#else // !IMPL_GRAPHQLPEG_DLL
#define GRAPHQLPEG_EXPORT __declspec(dllimport)
#endif // !IMPL_GRAPHQLPEG_DLL
#else // !GRAPHQL_DLLEXPORTS
#define GRAPHQLPEG_EXPORT
#endif // !GRAPHQL_DLLEXPORTS

#include <memory>
#include <string_view>

Expand All @@ -22,12 +32,12 @@ struct ast
bool validated = false;
};

ast parseString(std::string_view input);
ast parseFile(std::string_view filename);
GRAPHQLPEG_EXPORT ast parseString(std::string_view input);
GRAPHQLPEG_EXPORT ast parseFile(std::string_view filename);

} /* namespace peg */

peg::ast operator "" _graphql(const char* text, size_t size);
GRAPHQLPEG_EXPORT peg::ast operator "" _graphql(const char* text, size_t size);

} /* namespace graphql */

Expand Down
80 changes: 55 additions & 25 deletions include/graphqlservice/GraphQLResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#ifndef GRAPHQLRESPONSE_H
#define GRAPHQLRESPONSE_H

#ifdef GRAPHQL_DLLEXPORTS
#ifdef IMPL_GRAPHQLRESPONSE_DLL
#define GRAPHQLRESPONSE_EXPORT __declspec(dllexport)
#else // !IMPL_GRAPHQLRESPONSE_DLL
#define GRAPHQLRESPONSE_EXPORT __declspec(dllimport)
#endif // !IMPL_GRAPHQLRESPONSE_DLL
#else // !GRAPHQL_DLLEXPORTS
#define GRAPHQLRESPONSE_EXPORT
#endif // !GRAPHQL_DLLEXPORTS

#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -102,47 +112,47 @@ struct TypedData;
// Represent a discriminated union of GraphQL response value types.
struct Value
{
Value(Type type = Type::Null);
~Value();
GRAPHQLRESPONSE_EXPORT Value(Type type = Type::Null);
GRAPHQLRESPONSE_EXPORT ~Value();

explicit Value(const char* value);
explicit Value(StringType&& value);
explicit Value(BooleanType value);
explicit Value(IntType value);
explicit Value(FloatType value);
GRAPHQLRESPONSE_EXPORT explicit Value(const char* value);
GRAPHQLRESPONSE_EXPORT explicit Value(StringType&& value);
GRAPHQLRESPONSE_EXPORT explicit Value(BooleanType value);
GRAPHQLRESPONSE_EXPORT explicit Value(IntType value);
GRAPHQLRESPONSE_EXPORT explicit Value(FloatType value);

Value(Value&& other) noexcept;
explicit Value(const Value& other);
GRAPHQLRESPONSE_EXPORT Value(Value&& other) noexcept;
GRAPHQLRESPONSE_EXPORT explicit Value(const Value& other);

Value& operator=(Value&& rhs) noexcept;
Value& operator=(const Value& rhs) = delete;
GRAPHQLRESPONSE_EXPORT Value& operator=(Value&& rhs) noexcept;
GRAPHQLRESPONSE_EXPORT Value& operator=(const Value& rhs) = delete;

// Comparison
bool operator==(const Value& rhs) const noexcept;
bool operator!=(const Value& rhs) const noexcept;
GRAPHQLRESPONSE_EXPORT bool operator==(const Value& rhs) const noexcept;
GRAPHQLRESPONSE_EXPORT bool operator!=(const Value& rhs) const noexcept;

// Check the Type
Type type() const noexcept;
GRAPHQLRESPONSE_EXPORT Type type() const noexcept;

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

// Valid for Type::Map or Type::List
void reserve(size_t count);
size_t size() const;
GRAPHQLRESPONSE_EXPORT void reserve(size_t count);
GRAPHQLRESPONSE_EXPORT size_t size() const;

// Valid for Type::Map
void emplace_back(std::string&& name, Value&& value);
MapType::const_iterator find(const std::string& name) const;
MapType::const_iterator begin() const;
MapType::const_iterator end() const;
const Value& operator[](const std::string& name) const;
GRAPHQLRESPONSE_EXPORT void emplace_back(std::string&& name, Value&& value);
GRAPHQLRESPONSE_EXPORT MapType::const_iterator find(const std::string& name) const;
GRAPHQLRESPONSE_EXPORT MapType::const_iterator begin() const;
GRAPHQLRESPONSE_EXPORT MapType::const_iterator end() const;
GRAPHQLRESPONSE_EXPORT const Value& operator[](const std::string& name) const;

// Valid for Type::List
void emplace_back(Value&& value);
const Value& operator[](size_t index) const;
GRAPHQLRESPONSE_EXPORT void emplace_back(Value&& value);
GRAPHQLRESPONSE_EXPORT const Value& operator[](size_t index) const;

// Specialized for all single-value Types.
template <typename ValueType>
Expand Down Expand Up @@ -178,6 +188,26 @@ struct Value
std::unique_ptr<TypedData> _data;
};

#ifdef GRAPHQL_DLLEXPORTS
// Export all of the specialized template methods
template <> GRAPHQLRESPONSE_EXPORT void Value::set<StringType>(StringType&& value);
template <> GRAPHQLRESPONSE_EXPORT void Value::set<BooleanType>(BooleanType value);
template <> GRAPHQLRESPONSE_EXPORT void Value::set<IntType>(IntType value);
template <> GRAPHQLRESPONSE_EXPORT void Value::set<FloatType>(FloatType value);
template <> GRAPHQLRESPONSE_EXPORT void Value::set<ScalarType>(ScalarType&& value);
template <> GRAPHQLRESPONSE_EXPORT const MapType& Value::get<MapType>() const;
template <> GRAPHQLRESPONSE_EXPORT const ListType& Value::get<ListType>() const;
template <> GRAPHQLRESPONSE_EXPORT const StringType& Value::get<StringType>() const;
template <> GRAPHQLRESPONSE_EXPORT BooleanType Value::get<BooleanType>() const;
template <> GRAPHQLRESPONSE_EXPORT IntType Value::get<IntType>() const;
template <> GRAPHQLRESPONSE_EXPORT FloatType Value::get<FloatType>() const;
template <> GRAPHQLRESPONSE_EXPORT const ScalarType& Value::get<ScalarType>() const;
template <> GRAPHQLRESPONSE_EXPORT MapType Value::release<MapType>();
template <> GRAPHQLRESPONSE_EXPORT ListType Value::release<ListType>();
template <> GRAPHQLRESPONSE_EXPORT StringType Value::release<StringType>();
template <> GRAPHQLRESPONSE_EXPORT ScalarType Value::release<ScalarType>();
#endif // GRAPHQL_DLLEXPORTS

} /* namespace graphql::response */

#endif // GRAPHQLRESPONSE_H
Loading