Skip to content

Commit d7b95d0

Browse files
nre-abletonmuggenhor
authored andcommitted
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 07cbc39 commit d7b95d0

File tree

14 files changed

+88
-60
lines changed

14 files changed

+88
-60
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.1)
22

33
project(Cucumber-Cpp)
44

5+
option(CUKE_ENABLE_SHARED_LIB "Generate a shared library" OFF)
56
option(CUKE_USE_STATIC_BOOST "Statically link Boost (except boost::test)" ${WIN32})
67
option(CUKE_USE_STATIC_GTEST "Statically link Google Test" ON)
78
option(CUKE_DISABLE_BOOST_TEST "Disable boost:test" OFF)

include/cucumber-cpp/internal/ContextManager.hpp

Lines changed: 3 additions & 1 deletion
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 "CukeExport.hpp"
5+
46
#include <vector>
57

68
#include <boost/make_shared.hpp>
@@ -13,7 +15,7 @@ namespace internal {
1315

1416
typedef std::vector<boost::shared_ptr<void> > contexts_type;
1517

16-
class ContextManager {
18+
class CUCUMBER_CPP_EXPORT ContextManager {
1719
public:
1820
void purgeContexts();
1921
template<class T> boost::weak_ptr<T> addContext();

include/cucumber-cpp/internal/CukeCommands.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CUKE_CUKECOMMANDS_HPP_
33

44
#include "ContextManager.hpp"
5+
#include "CukeExport.hpp"
56
#include "Scenario.hpp"
67
#include "Table.hpp"
78
#include "step/StepManager.hpp"
@@ -20,7 +21,7 @@ using boost::shared_ptr;
2021
/**
2122
* Legacy class to be removed when feature #31 is complete, substituted by CukeEngineImpl.
2223
*/
23-
class CukeCommands {
24+
class CUCUMBER_CPP_EXPORT CukeCommands {
2425
public:
2526
CukeCommands();
2627
virtual ~CukeCommands();

include/cucumber-cpp/internal/CukeEngine.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77

88
#include <boost/multi_array.hpp>
99

10+
#include "CukeExport.hpp"
11+
1012
namespace cucumber {
1113
namespace internal {
1214

13-
class StepMatchArg {
15+
class CUCUMBER_CPP_EXPORT StepMatchArg {
1416
public:
1517
std::string value;
1618
std::ptrdiff_t position;
1719
};
1820

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

27-
class InvokeException {
29+
class CUCUMBER_CPP_EXPORT InvokeException {
2830
private:
2931
const std::string message;
3032

@@ -37,7 +39,7 @@ class InvokeException {
3739
virtual ~InvokeException() {}
3840
};
3941

40-
class InvokeFailureException : public InvokeException {
42+
class CUCUMBER_CPP_EXPORT InvokeFailureException : public InvokeException {
4143
private:
4244
const std::string exceptionType;
4345

@@ -48,7 +50,7 @@ class InvokeFailureException : public InvokeException {
4850
const std::string getExceptionType() const;
4951
};
5052

51-
class PendingStepException : public InvokeException {
53+
class CUCUMBER_CPP_EXPORT PendingStepException : public InvokeException {
5254
public:
5355
PendingStepException(const std::string & message);
5456
PendingStepException(const PendingStepException &rhs);
@@ -96,7 +98,8 @@ class CukeEngine {
9698
*/
9799
virtual std::string snippetText(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) const = 0;
98100

99-
virtual ~CukeEngine() {}
101+
CUCUMBER_CPP_EXPORT CukeEngine();
102+
CUCUMBER_CPP_EXPORT virtual ~CukeEngine();
100103
};
101104

102105
}

include/cucumber-cpp/internal/CukeEngineImpl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CUKE_CUKEENGINE_IMPL_HPP_
33

44
#include "CukeEngine.hpp"
5+
#include "CukeExport.hpp"
56
#include "CukeCommands.hpp"
67

78
namespace cucumber {
@@ -13,7 +14,7 @@ namespace internal {
1314
* Currently it is a wrapper around CukeCommands. It will have its own
1415
* implementation when feature #31 is complete.
1516
*/
16-
class CukeEngineImpl : public CukeEngine {
17+
class CUCUMBER_CPP_EXPORT CukeEngineImpl : public CukeEngine {
1718
private:
1819
CukeCommands cukeCommands;
1920

include/cucumber-cpp/internal/Table.hpp

Lines changed: 3 additions & 1 deletion
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 "CukeExport.hpp"
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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifndef CUKE_WIREPROTOCOL_HPP_
22
#define CUKE_WIREPROTOCOL_HPP_
33

4+
#include "CukeExport.hpp"
45
#include "ProtocolHandler.hpp"
56
#include "../../CukeEngine.hpp"
7+
68
#include <boost/shared_ptr.hpp>
79

810
namespace cucumber {
@@ -14,7 +16,7 @@ namespace internal {
1416

1517
class WireResponseVisitor;
1618

17-
class WireResponse {
19+
class CUCUMBER_CPP_EXPORT WireResponse {
1820
public:
1921
WireResponse() {};
2022

@@ -23,12 +25,12 @@ class WireResponse {
2325
virtual ~WireResponse() {};
2426
};
2527

26-
class SuccessResponse : public WireResponse {
28+
class CUCUMBER_CPP_EXPORT SuccessResponse : public WireResponse {
2729
public:
2830
void accept(WireResponseVisitor& visitor) const;
2931
};
3032

31-
class FailureResponse : public WireResponse {
33+
class CUCUMBER_CPP_EXPORT FailureResponse : public WireResponse {
3234
private:
3335
const std::string message, exceptionType;
3436

@@ -41,7 +43,7 @@ class FailureResponse : public WireResponse {
4143
void accept(WireResponseVisitor& visitor) const;
4244
};
4345

44-
class PendingResponse : public WireResponse {
46+
class CUCUMBER_CPP_EXPORT PendingResponse : public WireResponse {
4547
private:
4648
const std::string message;
4749

@@ -53,7 +55,7 @@ class PendingResponse : public WireResponse {
5355
void accept(WireResponseVisitor& visitor) const;
5456
};
5557

56-
class StepMatchesResponse : public WireResponse {
58+
class CUCUMBER_CPP_EXPORT StepMatchesResponse : public WireResponse {
5759
private:
5860
const std::vector<StepMatch> matchingSteps;
5961

@@ -64,7 +66,7 @@ class StepMatchesResponse : public WireResponse {
6466
void accept(WireResponseVisitor& visitor) const;
6567
};
6668

67-
class SnippetTextResponse : public WireResponse {
69+
class CUCUMBER_CPP_EXPORT SnippetTextResponse : public WireResponse {
6870
private:
6971
const std::string stepSnippet;
7072

@@ -76,7 +78,7 @@ class SnippetTextResponse : public WireResponse {
7678
void accept(WireResponseVisitor& visitor) const;
7779
};
7880

79-
class WireResponseVisitor {
81+
class CUCUMBER_CPP_EXPORT WireResponseVisitor {
8082
public:
8183
virtual void visit(const SuccessResponse& response) = 0;
8284
virtual void visit(const FailureResponse& response) = 0;
@@ -91,7 +93,7 @@ class WireResponseVisitor {
9193
/**
9294
* Wire protocol request command.
9395
*/
94-
class WireCommand {
96+
class CUCUMBER_CPP_EXPORT WireCommand {
9597
public:
9698
/**
9799
* Runs the command on the provided engine
@@ -105,7 +107,7 @@ class WireCommand {
105107
virtual ~WireCommand() {};
106108
};
107109

108-
class WireMessageCodecException : public std::exception {
110+
class CUCUMBER_CPP_EXPORT WireMessageCodecException : public std::exception {
109111
private:
110112
const char *description;
111113

@@ -123,7 +125,7 @@ class WireMessageCodecException : public std::exception {
123125
/**
124126
* Transforms wire messages into commands and responses to messages.
125127
*/
126-
class WireMessageCodec {
128+
class CUCUMBER_CPP_EXPORT WireMessageCodec {
127129
public:
128130
/**
129131
* Decodes a wire message into a command.
@@ -151,7 +153,7 @@ class WireMessageCodec {
151153
/**
152154
* WireMessageCodec implementation with JsonSpirit.
153155
*/
154-
class JsonSpiritWireMessageCodec : public WireMessageCodec {
156+
class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec {
155157
public:
156158
JsonSpiritWireMessageCodec();
157159
boost::shared_ptr<WireCommand> decode(const std::string &request) const;
@@ -162,7 +164,7 @@ class JsonSpiritWireMessageCodec : public WireMessageCodec {
162164
* Wire protocol handler, delegating JSON encoding and decoding to a
163165
* codec object and running commands on a provided engine instance.
164166
*/
165-
class WireProtocolHandler : public ProtocolHandler {
167+
class CUCUMBER_CPP_EXPORT WireProtocolHandler : public ProtocolHandler {
166168
private:
167169
const WireMessageCodec& codec;
168170
CukeEngine& engine;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CUKE_WIRESERVER_HPP_
22
#define CUKE_WIRESERVER_HPP_
33

4+
#include "CukeExport.hpp"
45
#include "ProtocolHandler.hpp"
56

67
#include <string>
@@ -13,7 +14,7 @@ namespace internal {
1314
/**
1415
* Socket server that calls a protocol handler line by line
1516
*/
16-
class SocketServer {
17+
class CUCUMBER_CPP_EXPORT SocketServer {
1718
public:
1819
/**
1920
* Constructor for DI
@@ -49,7 +50,7 @@ class SocketServer {
4950
/**
5051
* Socket server that calls a protocol handler line by line
5152
*/
52-
class TCPSocketServer : public SocketServer {
53+
class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
5354
public:
5455
/**
5556
* Type definition for TCP port

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#ifndef CUKE_GTESTDRIVER_HPP_
22
#define CUKE_GTESTDRIVER_HPP_
33

4+
#include "CukeExport.hpp"
45
#include "../step/StepManager.hpp"
56

67
#include <iostream>
78

89
namespace cucumber {
910
namespace internal {
1011

11-
class GTestStep : public BasicStep {
12+
class CUCUMBER_CPP_EXPORT GTestStep : public BasicStep {
1213
protected:
1314
const InvokeResult invokeStepBody();
1415

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CUKE_HOOKREGISTRAR_HPP_
22
#define CUKE_HOOKREGISTRAR_HPP_
33

4+
#include "CukeExport.hpp"
45
#include "Tag.hpp"
56
#include "../Scenario.hpp"
67
#include "../step/StepManager.hpp"
@@ -14,12 +15,12 @@
1415
namespace cucumber {
1516
namespace internal {
1617

17-
class CallableStep {
18+
class CUCUMBER_CPP_EXPORT CallableStep {
1819
public:
1920
virtual void call() = 0;
2021
};
2122

22-
class Hook {
23+
class CUCUMBER_CPP_EXPORT Hook {
2324
public:
2425
void setTags(const std::string &csvTagNotation);
2526
virtual void invokeHook(Scenario *scenario, CallableStep *step);
@@ -36,35 +37,30 @@ class Hook {
3637
AndTagExpression tagExpression;
3738
};
3839

39-
class BeforeHook : public Hook {
40-
};
40+
class CUCUMBER_CPP_EXPORT BeforeHook : public Hook {};
4141

42-
class AroundStepHook : public Hook {
42+
class CUCUMBER_CPP_EXPORT AroundStepHook : public Hook {
4343
public:
4444
virtual void invokeHook(Scenario *scenario, CallableStep *step);
4545
virtual void skipHook();
4646
protected:
4747
CallableStep *step;
4848
};
4949

50-
class AfterStepHook : public Hook {
51-
};
50+
class CUCUMBER_CPP_EXPORT AfterStepHook : public Hook {};
5251

53-
class AfterHook : public Hook {
54-
};
52+
class CUCUMBER_CPP_EXPORT AfterHook : public Hook {};
5553

56-
class UnconditionalHook : public Hook {
54+
class CUCUMBER_CPP_EXPORT UnconditionalHook : public Hook {
5755
public:
5856
virtual void invokeHook(Scenario *scenario, CallableStep *step);
5957
};
6058

61-
class BeforeAllHook : public UnconditionalHook {
62-
};
59+
class CUCUMBER_CPP_EXPORT BeforeAllHook : public UnconditionalHook {};
6360

64-
class AfterAllHook : public UnconditionalHook {
65-
};
61+
class CUCUMBER_CPP_EXPORT AfterAllHook : public UnconditionalHook {};
6662

67-
class HookRegistrar {
63+
class CUCUMBER_CPP_EXPORT HookRegistrar {
6864
public:
6965
typedef std::list< boost::shared_ptr<Hook> > hook_list_type;
7066
typedef std::list< boost::shared_ptr<AroundStepHook> > aroundhook_list_type;
@@ -107,8 +103,7 @@ class HookRegistrar {
107103
;
108104
};
109105

110-
111-
class StepCallChain {
106+
class CUCUMBER_CPP_EXPORT StepCallChain {
112107
public:
113108
StepCallChain(Scenario *scenario, const StepInfo* stepInfo, const InvokeArgs *pStepArgs, HookRegistrar::aroundhook_list_type &aroundHooks);
114109
InvokeResult exec();
@@ -125,7 +120,7 @@ class StepCallChain {
125120
InvokeResult result;
126121
};
127122

128-
class CallableStepChain : public CallableStep {
123+
class CUCUMBER_CPP_EXPORT CallableStepChain : public CallableStep {
129124
public:
130125
CallableStepChain(StepCallChain *scc);
131126
void call();

0 commit comments

Comments
 (0)