Skip to content

Commit b9b2131

Browse files
committed
Support building as a shared library
On Windows, it is necessary to add some __declspec() calls to expose some symbols with different linkage types. This commit adds the makes it possible for users to easily build cucumber-cpp either as a static or dynamic library by defining either CUKE_LINKED_AS_SHARED_LIBRARY or CUKE_CREATE_SHARED_LIBRARY at build time.
1 parent da60995 commit b9b2131

13 files changed

+89
-49
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(Cucumber-Cpp)
44

55
set(CUKE_USE_STATIC_BOOST ${WIN32} CACHE BOOL "Statically link Boost (except boost::test)")
66
set(CUKE_USE_STATIC_GTEST ON CACHE BOOL "Statically link Google Test")
7+
set(CUKE_ENABLE_SHARED_LIB OFF CACHE BOOL "Generate a shared library")
78

89
set(CUKE_DISABLE_BOOST_TEST OFF CACHE BOOL "Disable boost:test")
910
set(CUKE_DISABLE_GTEST OFF CACHE BOOL "Disable Google Test framework")

include/cucumber-cpp/internal/ContextManager.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef CUKE_CONTEXTMANAGER_HPP_
22
#define CUKE_CONTEXTMANAGER_HPP_
33

4+
#include "cucumber-cpp_export.h"
5+
46
#include <vector>
57

68
#include <boost/make_shared.hpp>
@@ -16,7 +18,7 @@ namespace internal {
1618

1719
typedef std::vector<shared_ptr<void> > contexts_type;
1820

19-
class ContextManager {
21+
class CUCUMBER_CPP_EXPORT ContextManager {
2022
public:
2123
void purgeContexts();
2224
template<class T> weak_ptr<T> addContext();

include/cucumber-cpp/internal/CukeCommands.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "step/StepManager.hpp"
88
#include "hook/HookRegistrar.hpp"
99

10+
#include "cucumber-cpp_export.h"
11+
1012
#include <map>
1113
#include <string>
1214
#include <sstream>
@@ -21,7 +23,7 @@ using boost::shared_ptr;
2123
/**
2224
* Legacy class to be removed when feature #31 is complete, substituted by CukeEngineImpl.
2325
*/
24-
class CukeCommands {
26+
class CUCUMBER_CPP_EXPORT CukeCommands {
2527
public:
2628
CukeCommands();
2729
virtual ~CukeCommands();

include/cucumber-cpp/internal/CukeEngine.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef CUKE_CUKEENGINE_HPP_
22
#define CUKE_CUKEENGINE_HPP_
33

4+
#include "cucumber-cpp_export.h"
5+
46
#include <string>
57
#include <vector>
68

@@ -9,21 +11,21 @@
911
namespace cucumber {
1012
namespace internal {
1113

12-
class StepMatchArg {
14+
class CUCUMBER_CPP_EXPORT StepMatchArg {
1315
public:
1416
std::string value;
1517
int position;
1618
};
1719

18-
class StepMatch {
20+
class CUCUMBER_CPP_EXPORT StepMatch {
1921
public:
2022
std::string id;
2123
std::vector<StepMatchArg> args;
2224
std::string source;
2325
std::string regexp;
2426
};
2527

26-
class InvokeException {
28+
class CUCUMBER_CPP_EXPORT InvokeException {
2729
private:
2830
const std::string message;
2931

@@ -36,7 +38,7 @@ class InvokeException {
3638
virtual ~InvokeException() {}
3739
};
3840

39-
class InvokeFailureException : public InvokeException {
41+
class CUCUMBER_CPP_EXPORT InvokeFailureException : public InvokeException {
4042
private:
4143
const std::string exceptionType;
4244

@@ -47,7 +49,7 @@ class InvokeFailureException : public InvokeException {
4749
const std::string getExceptionType() const;
4850
};
4951

50-
class PendingStepException : public InvokeException {
52+
class CUCUMBER_CPP_EXPORT PendingStepException : public InvokeException {
5153
public:
5254
PendingStepException(const std::string & message);
5355
PendingStepException(const PendingStepException &rhs);
@@ -59,7 +61,7 @@ class PendingStepException : public InvokeException {
5961
* It uses standard types (as much as possible) to be easier to call.
6062
* Returns standard types if possible.
6163
*/
62-
class CukeEngine {
64+
class CUCUMBER_CPP_EXPORT CukeEngine {
6365
private:
6466
typedef std::vector<std::string> string_array;
6567
typedef boost::multi_array<std::string, 2> string_2d_array;

include/cucumber-cpp/internal/CukeEngineImpl.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "CukeEngine.hpp"
55
#include "CukeCommands.hpp"
66

7+
#include "cucumber-cpp_export.h"
8+
79
namespace cucumber {
810
namespace internal {
911

@@ -13,7 +15,7 @@ namespace internal {
1315
* Currently it is a wrapper around CukeCommands. It will have its own
1416
* implementation when feature #31 is complete.
1517
*/
16-
class CukeEngineImpl : public CukeEngine {
18+
class CUCUMBER_CPP_EXPORT CukeEngineImpl : public CukeEngine {
1719
private:
1820
CukeCommands cukeCommands;
1921

include/cucumber-cpp/internal/Table.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef CUKE_TABLE_HPP_
22
#define CUKE_TABLE_HPP_
33

4+
#include "cucumber-cpp_export.h"
5+
46
#include <vector>
57
#include <map>
68
#include <string>
@@ -9,7 +11,7 @@
911
namespace cucumber {
1012
namespace internal {
1113

12-
class Table {
14+
class CUCUMBER_CPP_EXPORT Table {
1315
private:
1416
typedef std::vector<std::string> basic_type;
1517
public:

include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include "ProtocolHandler.hpp"
55
#include "../../CukeEngine.hpp"
6+
7+
#include "cucumber-cpp_export.h"
8+
69
#include <boost/shared_ptr.hpp>
710

811
namespace cucumber {
@@ -14,7 +17,7 @@ namespace internal {
1417

1518
class WireResponseVisitor;
1619

17-
class WireResponse {
20+
class CUCUMBER_CPP_EXPORT WireResponse {
1821
public:
1922
WireResponse() {};
2023

@@ -23,12 +26,12 @@ class WireResponse {
2326
virtual ~WireResponse() {};
2427
};
2528

26-
class SuccessResponse : public WireResponse {
29+
class CUCUMBER_CPP_EXPORT SuccessResponse : public WireResponse {
2730
public:
2831
void accept(WireResponseVisitor& visitor) const;
2932
};
3033

31-
class FailureResponse : public WireResponse {
34+
class CUCUMBER_CPP_EXPORT FailureResponse : public WireResponse {
3235
private:
3336
const std::string message, exceptionType;
3437

@@ -41,7 +44,7 @@ class FailureResponse : public WireResponse {
4144
void accept(WireResponseVisitor& visitor) const;
4245
};
4346

44-
class PendingResponse : public WireResponse {
47+
class CUCUMBER_CPP_EXPORT PendingResponse : public WireResponse {
4548
private:
4649
const std::string message;
4750

@@ -53,7 +56,7 @@ class PendingResponse : public WireResponse {
5356
void accept(WireResponseVisitor& visitor) const;
5457
};
5558

56-
class StepMatchesResponse : public WireResponse {
59+
class CUCUMBER_CPP_EXPORT StepMatchesResponse : public WireResponse {
5760
private:
5861
const std::vector<StepMatch> matchingSteps;
5962

@@ -64,7 +67,7 @@ class StepMatchesResponse : public WireResponse {
6467
void accept(WireResponseVisitor& visitor) const;
6568
};
6669

67-
class SnippetTextResponse : public WireResponse {
70+
class CUCUMBER_CPP_EXPORT SnippetTextResponse : public WireResponse {
6871
private:
6972
const std::string stepSnippet;
7073

@@ -76,7 +79,7 @@ class SnippetTextResponse : public WireResponse {
7679
void accept(WireResponseVisitor& visitor) const;
7780
};
7881

79-
class WireResponseVisitor {
82+
class CUCUMBER_CPP_EXPORT WireResponseVisitor {
8083
public:
8184
virtual void visit(const SuccessResponse& response) = 0;
8285
virtual void visit(const FailureResponse& response) = 0;
@@ -91,7 +94,7 @@ class WireResponseVisitor {
9194
/**
9295
* Wire protocol request command.
9396
*/
94-
class WireCommand {
97+
class CUCUMBER_CPP_EXPORT WireCommand {
9598
public:
9699
/**
97100
* Runs the command on the provided engine
@@ -105,7 +108,7 @@ class WireCommand {
105108
virtual ~WireCommand() {};
106109
};
107110

108-
class WireMessageCodecException : public std::exception {
111+
class CUCUMBER_CPP_EXPORT WireMessageCodecException : public std::exception {
109112
private:
110113
const char *description;
111114

@@ -123,7 +126,7 @@ class WireMessageCodecException : public std::exception {
123126
/**
124127
* Transforms wire messages into commands and responses to messages.
125128
*/
126-
class WireMessageCodec {
129+
class CUCUMBER_CPP_EXPORT WireMessageCodec {
127130
public:
128131
/**
129132
* Decodes a wire message into a command.
@@ -151,7 +154,7 @@ class WireMessageCodec {
151154
/**
152155
* WireMessageCodec implementation with JsonSpirit.
153156
*/
154-
class JsonSpiritWireMessageCodec : public WireMessageCodec {
157+
class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec {
155158
public:
156159
JsonSpiritWireMessageCodec();
157160
boost::shared_ptr<WireCommand> decode(const std::string &request) const;
@@ -162,7 +165,7 @@ class JsonSpiritWireMessageCodec : public WireMessageCodec {
162165
* Wire protocol handler, delegating JSON encoding and decoding to a
163166
* codec object and running commands on a provided engine instance.
164167
*/
165-
class WireProtocolHandler : public ProtocolHandler {
168+
class CUCUMBER_CPP_EXPORT WireProtocolHandler : public ProtocolHandler {
166169
private:
167170
const WireMessageCodec& codec;
168171
CukeEngine& engine;

include/cucumber-cpp/internal/connectors/wire/WireServer.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "ProtocolHandler.hpp"
55

6+
#include "cucumber-cpp_export.h"
7+
68
#include <string>
79

810
#include <boost/asio.hpp>
@@ -19,7 +21,7 @@ using namespace boost::asio::local;
1921
/**
2022
* Socket server that calls a protocol handler line by line
2123
*/
22-
class SocketServer {
24+
class CUCUMBER_CPP_EXPORT SocketServer {
2325
public:
2426
/**
2527
* Constructor for DI
@@ -46,7 +48,7 @@ class SocketServer {
4648
/**
4749
* Socket server that calls a protocol handler line by line
4850
*/
49-
class TCPSocketServer : public SocketServer {
51+
class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
5052
public:
5153
/**
5254
* Type definition for TCP port

include/cucumber-cpp/internal/drivers/GTestDriver.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include "../step/StepManager.hpp"
55

6+
#include "cucumber-cpp_export.h"
7+
68
#include <iostream>
79

810
namespace cucumber {
911
namespace internal {
1012

11-
class GTestStep : public BasicStep {
13+
class CUCUMBER_CPP_EXPORT GTestStep : public BasicStep {
1214
protected:
1315
const InvokeResult invokeStepBody();
1416

include/cucumber-cpp/internal/hook/HookRegistrar.hpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "../Scenario.hpp"
66
#include "../step/StepManager.hpp"
77

8+
#include "cucumber-cpp_export.h"
9+
810
#include <boost/make_shared.hpp>
911
#include <boost/smart_ptr.hpp>
1012
using boost::shared_ptr;
@@ -14,12 +16,12 @@ using boost::shared_ptr;
1416
namespace cucumber {
1517
namespace internal {
1618

17-
class CallableStep {
19+
class CUCUMBER_CPP_EXPORT CallableStep {
1820
public:
1921
virtual void call() = 0;
2022
};
2123

22-
class Hook {
24+
class CUCUMBER_CPP_EXPORT Hook {
2325
public:
2426
void setTags(const std::string &csvTagNotation);
2527
virtual void invokeHook(Scenario *scenario, CallableStep *step);
@@ -31,35 +33,35 @@ class Hook {
3133
shared_ptr<TagExpression> tagExpression;
3234
};
3335

34-
class BeforeHook : public Hook {
36+
class CUCUMBER_CPP_EXPORT BeforeHook : public Hook {
3537
};
3638

37-
class AroundStepHook : public Hook {
39+
class CUCUMBER_CPP_EXPORT AroundStepHook : public Hook {
3840
public:
3941
virtual void invokeHook(Scenario *scenario, CallableStep *step);
4042
virtual void skipHook();
4143
protected:
4244
CallableStep *step;
4345
};
4446

45-
class AfterStepHook : public Hook {
47+
class CUCUMBER_CPP_EXPORT AfterStepHook : public Hook {
4648
};
4749

48-
class AfterHook : public Hook {
50+
class CUCUMBER_CPP_EXPORT AfterHook : public Hook {
4951
};
5052

51-
class UnconditionalHook : public Hook {
53+
class CUCUMBER_CPP_EXPORT UnconditionalHook : public Hook {
5254
public:
5355
virtual void invokeHook(Scenario *scenario, CallableStep *step);
5456
};
5557

56-
class BeforeAllHook : public UnconditionalHook {
58+
class CUCUMBER_CPP_EXPORT BeforeAllHook : public UnconditionalHook {
5759
};
5860

59-
class AfterAllHook : public UnconditionalHook {
61+
class CUCUMBER_CPP_EXPORT AfterAllHook : public UnconditionalHook {
6062
};
6163

62-
class HookRegistrar {
64+
class CUCUMBER_CPP_EXPORT HookRegistrar {
6365
public:
6466
typedef std::list< boost::shared_ptr<Hook> > hook_list_type;
6567
typedef std::list< boost::shared_ptr<AroundStepHook> > aroundhook_list_type;
@@ -97,7 +99,7 @@ class HookRegistrar {
9799
};
98100

99101

100-
class StepCallChain {
102+
class CUCUMBER_CPP_EXPORT StepCallChain {
101103
public:
102104
StepCallChain(Scenario *scenario, const boost::shared_ptr<const StepInfo>& stepInfo, const InvokeArgs *pStepArgs, HookRegistrar::aroundhook_list_type &aroundHooks);
103105
InvokeResult exec();
@@ -114,7 +116,7 @@ class StepCallChain {
114116
InvokeResult result;
115117
};
116118

117-
class CallableStepChain : public CallableStep {
119+
class CUCUMBER_CPP_EXPORT CallableStepChain : public CallableStep {
118120
public:
119121
CallableStepChain(StepCallChain *scc);
120122
void call();

0 commit comments

Comments
 (0)