Skip to content

Commit b8e685f

Browse files
committed
Support building as a shared library on Windows
On Windows, it is necessary to add some __declspec() calls to expose some symbols with different linkage types. This commit adds the CUKE_API_ macro, which makes it possible for users to easily build cucumber-cpp on Windows 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 b8e685f

File tree

15 files changed

+84
-49
lines changed

15 files changed

+84
-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 "CukeDll.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 CUKE_API_ 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 "CukeDll.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 CUKE_API_ CukeCommands {
2526
public:
2627
CukeCommands();
2728
virtual ~CukeCommands();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef CUKE_CUKEDLL_HPP_
2+
#define CUKE_CUKEDLL_HPP_
3+
4+
#ifndef CUKE_API_
5+
#if CUKE_LINKED_AS_SHARED_LIBRARY
6+
#define CUKE_API_ __declspec(dllimport)
7+
#elif CUKE_CREATE_SHARED_LIBRARY
8+
#define CUKE_API_ __declspec(dllexport)
9+
#else
10+
#define CUKE_API_
11+
#endif
12+
#endif
13+
14+
#endif /* CUKE_CUKEDLL_HPP_ */

include/cucumber-cpp/internal/CukeEngine.hpp

Lines changed: 8 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 "CukeDll.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 CUKE_API_ StepMatchArg {
1315
public:
1416
std::string value;
1517
int position;
1618
};
1719

18-
class StepMatch {
20+
class CUKE_API_ 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 CUKE_API_ 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 CUKE_API_ 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 CUKE_API_ 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 CUKE_API_ 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace internal {
1313
* Currently it is a wrapper around CukeCommands. It will have its own
1414
* implementation when feature #31 is complete.
1515
*/
16-
class CukeEngineImpl : public CukeEngine {
16+
class CUKE_API_ CukeEngineImpl : public CukeEngine {
1717
private:
1818
CukeCommands cukeCommands;
1919

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 "CukeDll.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 CUKE_API_ Table {
1315
private:
1416
typedef std::vector<std::string> basic_type;
1517
public:

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CUKE_WIREPROTOCOL_HPP_
33

44
#include "ProtocolHandler.hpp"
5+
#include "../../CukeDll.hpp"
56
#include "../../CukeEngine.hpp"
67
#include <boost/shared_ptr.hpp>
78

@@ -14,7 +15,7 @@ namespace internal {
1415

1516
class WireResponseVisitor;
1617

17-
class WireResponse {
18+
class CUKE_API_ WireResponse {
1819
public:
1920
WireResponse() {};
2021

@@ -23,12 +24,12 @@ class WireResponse {
2324
virtual ~WireResponse() {};
2425
};
2526

26-
class SuccessResponse : public WireResponse {
27+
class CUKE_API_ SuccessResponse : public WireResponse {
2728
public:
2829
void accept(WireResponseVisitor& visitor) const;
2930
};
3031

31-
class FailureResponse : public WireResponse {
32+
class CUKE_API_ FailureResponse : public WireResponse {
3233
private:
3334
const std::string message, exceptionType;
3435

@@ -41,7 +42,7 @@ class FailureResponse : public WireResponse {
4142
void accept(WireResponseVisitor& visitor) const;
4243
};
4344

44-
class PendingResponse : public WireResponse {
45+
class CUKE_API_ PendingResponse : public WireResponse {
4546
private:
4647
const std::string message;
4748

@@ -53,7 +54,7 @@ class PendingResponse : public WireResponse {
5354
void accept(WireResponseVisitor& visitor) const;
5455
};
5556

56-
class StepMatchesResponse : public WireResponse {
57+
class CUKE_API_ StepMatchesResponse : public WireResponse {
5758
private:
5859
const std::vector<StepMatch> matchingSteps;
5960

@@ -64,7 +65,7 @@ class StepMatchesResponse : public WireResponse {
6465
void accept(WireResponseVisitor& visitor) const;
6566
};
6667

67-
class SnippetTextResponse : public WireResponse {
68+
class CUKE_API_ SnippetTextResponse : public WireResponse {
6869
private:
6970
const std::string stepSnippet;
7071

@@ -76,7 +77,7 @@ class SnippetTextResponse : public WireResponse {
7677
void accept(WireResponseVisitor& visitor) const;
7778
};
7879

79-
class WireResponseVisitor {
80+
class CUKE_API_ WireResponseVisitor {
8081
public:
8182
virtual void visit(const SuccessResponse& response) = 0;
8283
virtual void visit(const FailureResponse& response) = 0;
@@ -91,7 +92,7 @@ class WireResponseVisitor {
9192
/**
9293
* Wire protocol request command.
9394
*/
94-
class WireCommand {
95+
class CUKE_API_ WireCommand {
9596
public:
9697
/**
9798
* Runs the command on the provided engine
@@ -105,7 +106,7 @@ class WireCommand {
105106
virtual ~WireCommand() {};
106107
};
107108

108-
class WireMessageCodecException : public std::exception {
109+
class CUKE_API_ WireMessageCodecException : public std::exception {
109110
private:
110111
const char *description;
111112

@@ -123,7 +124,7 @@ class WireMessageCodecException : public std::exception {
123124
/**
124125
* Transforms wire messages into commands and responses to messages.
125126
*/
126-
class WireMessageCodec {
127+
class CUKE_API_ WireMessageCodec {
127128
public:
128129
/**
129130
* Decodes a wire message into a command.
@@ -151,7 +152,7 @@ class WireMessageCodec {
151152
/**
152153
* WireMessageCodec implementation with JsonSpirit.
153154
*/
154-
class JsonSpiritWireMessageCodec : public WireMessageCodec {
155+
class CUKE_API_ JsonSpiritWireMessageCodec : public WireMessageCodec {
155156
public:
156157
JsonSpiritWireMessageCodec();
157158
boost::shared_ptr<WireCommand> decode(const std::string &request) const;
@@ -162,7 +163,7 @@ class JsonSpiritWireMessageCodec : public WireMessageCodec {
162163
* Wire protocol handler, delegating JSON encoding and decoding to a
163164
* codec object and running commands on a provided engine instance.
164165
*/
165-
class WireProtocolHandler : public ProtocolHandler {
166+
class CUKE_API_ WireProtocolHandler : public ProtocolHandler {
166167
private:
167168
const WireMessageCodec& codec;
168169
CukeEngine& engine;

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

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

44
#include "ProtocolHandler.hpp"
5+
#include "../../CukeDll.hpp"
56

67
#include <string>
78

@@ -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 CUKE_API_ 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 CUKE_API_ TCPSocketServer : public SocketServer {
5051
public:
5152
/**
5253
* Type definition for TCP port
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "step/StepManager.hpp"
22
#include "hook/HookRegistrar.hpp"
33
#include "ContextManager.hpp"
4+
#include "CukeDll.hpp"
45
#include "Macros.hpp"
56
#include "drivers/DriverSelector.hpp"

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 "../CukeDll.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 CUKE_API_ 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
@@ -2,6 +2,7 @@
22
#define CUKE_HOOKREGISTRAR_HPP_
33

44
#include "Tag.hpp"
5+
#include "../CukeDll.hpp"
56
#include "../Scenario.hpp"
67
#include "../step/StepManager.hpp"
78

@@ -14,12 +15,12 @@ using boost::shared_ptr;
1415
namespace cucumber {
1516
namespace internal {
1617

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

22-
class Hook {
23+
class CUKE_API_ 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 CUKE_API_ BeforeHook : public Hook {
3536
};
3637

37-
class AroundStepHook : public Hook {
38+
class CUKE_API_ 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 CUKE_API_ AfterStepHook : public Hook {
4647
};
4748

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

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

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

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

62-
class HookRegistrar {
63+
class CUKE_API_ 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 CUKE_API_ 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 CUKE_API_ CallableStepChain : public CallableStep {
118119
public:
119120
CallableStepChain(StepCallChain *scc);
120121
void call();

0 commit comments

Comments
 (0)