Skip to content

Commit 3de2faa

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 34b0150 commit 3de2faa

File tree

14 files changed

+91
-49
lines changed

14 files changed

+91
-49
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
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

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>
@@ -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

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"
@@ -21,7 +22,7 @@ using boost::shared_ptr;
2122
/**
2223
* Legacy class to be removed when feature #31 is complete, substituted by CukeEngineImpl.
2324
*/
24-
class CukeCommands {
25+
class CUCUMBER_CPP_EXPORT CukeCommands {
2526
public:
2627
CukeCommands();
2728
virtual ~CukeCommands();

include/cucumber-cpp/internal/CukeEngine.hpp

Lines changed: 9 additions & 6 deletions
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 "CukeExport.hpp"
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);
@@ -95,7 +97,8 @@ class CukeEngine {
9597
*/
9698
virtual std::string snippetText(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) const = 0;
9799

98-
virtual ~CukeEngine() {}
100+
CUCUMBER_CPP_EXPORT CukeEngine();
101+
CUCUMBER_CPP_EXPORT virtual ~CukeEngine();
99102
};
100103

101104
}

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>
@@ -19,7 +20,7 @@ using namespace boost::asio::local;
1920
/**
2021
* Socket server that calls a protocol handler line by line
2122
*/
22-
class SocketServer {
23+
class CUCUMBER_CPP_EXPORT SocketServer {
2324
public:
2425
/**
2526
* Constructor for DI
@@ -46,7 +47,7 @@ class SocketServer {
4647
/**
4748
* Socket server that calls a protocol handler line by line
4849
*/
49-
class TCPSocketServer : public SocketServer {
50+
class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
5051
public:
5152
/**
5253
* 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 & 12 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 @@ using boost::shared_ptr;
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);
@@ -31,35 +32,35 @@ class Hook {
3132
shared_ptr<TagExpression> tagExpression;
3233
};
3334

34-
class BeforeHook : public Hook {
35+
class CUCUMBER_CPP_EXPORT BeforeHook : public Hook {
3536
};
3637

37-
class AroundStepHook : public Hook {
38+
class CUCUMBER_CPP_EXPORT AroundStepHook : public Hook {
3839
public:
3940
virtual void invokeHook(Scenario *scenario, CallableStep *step);
4041
virtual void skipHook();
4142
protected:
4243
CallableStep *step;
4344
};
4445

45-
class AfterStepHook : public Hook {
46+
class CUCUMBER_CPP_EXPORT AfterStepHook : public Hook {
4647
};
4748

48-
class AfterHook : public Hook {
49+
class CUCUMBER_CPP_EXPORT AfterHook : public Hook {
4950
};
5051

51-
class UnconditionalHook : public Hook {
52+
class CUCUMBER_CPP_EXPORT UnconditionalHook : public Hook {
5253
public:
5354
virtual void invokeHook(Scenario *scenario, CallableStep *step);
5455
};
5556

56-
class BeforeAllHook : public UnconditionalHook {
57+
class CUCUMBER_CPP_EXPORT BeforeAllHook : public UnconditionalHook {
5758
};
5859

59-
class AfterAllHook : public UnconditionalHook {
60+
class CUCUMBER_CPP_EXPORT AfterAllHook : public UnconditionalHook {
6061
};
6162

62-
class HookRegistrar {
63+
class CUCUMBER_CPP_EXPORT HookRegistrar {
6364
public:
6465
typedef std::list< boost::shared_ptr<Hook> > hook_list_type;
6566
typedef std::list< boost::shared_ptr<AroundStepHook> > aroundhook_list_type;
@@ -97,7 +98,7 @@ class HookRegistrar {
9798
};
9899

99100

100-
class StepCallChain {
101+
class CUCUMBER_CPP_EXPORT StepCallChain {
101102
public:
102103
StepCallChain(Scenario *scenario, const boost::shared_ptr<const StepInfo>& stepInfo, const InvokeArgs *pStepArgs, HookRegistrar::aroundhook_list_type &aroundHooks);
103104
InvokeResult exec();
@@ -114,7 +115,7 @@ class StepCallChain {
114115
InvokeResult result;
115116
};
116117

117-
class CallableStepChain : public CallableStep {
118+
class CUCUMBER_CPP_EXPORT CallableStepChain : public CallableStep {
118119
public:
119120
CallableStepChain(StepCallChain *scc);
120121
void call();

0 commit comments

Comments
 (0)