Skip to content

Commit 183c79d

Browse files
committed
Merge #147 'Support building as DLL on Windows'
This exports all externally used functions and variables to make them accessible from a DLL build. Additionally we now hide all non-marked symbols by default to achieve a similar effect with shared library builds on other platforms.
2 parents 0550fa1 + 9fe13ae commit 183c79d

25 files changed

+132
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
88
* Listen on localhost by default to avoid firewall warnings ([#158](https://github.com/cucumber/cucumber-cpp/pull/158) Nik Reiman)
99
* Better integrate Qt into buildsystem, it can now be disabled, and test it in CI ([#160](https://github.com/cucumber/cucumber-cpp/pull/160) Kamil Strzempowicz & Giel van Schijndel)
1010
* Support taking regex captures as arguments to the step definition's function ([#159](https://github.com/cucumber/cucumber-cpp/pull/159) Giel van Schijndel)
11+
* Support building as shared library on Windows and hide internal symbols on all platforms ([#147](https://github.com/cucumber/cucumber-cpp/pull/147) [Nik Reiman](https://github.com/nre-ableton))
1112

1213
### Changed
1314

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
cmake_minimum_required(VERSION 3.1)
22

3+
if(NOT CMAKE_VERSION VERSION_LESS "3.3")
4+
# Don't ignore visibility related properties for non-SHARED targets
5+
cmake_policy(SET CMP0063 NEW)
6+
endif()
7+
38
project(Cucumber-Cpp)
49

10+
option(BUILD_SHARED_LIBS "Generate shared libraries" OFF)
511
option(CUKE_USE_STATIC_BOOST "Statically link Boost (except boost::test)" ${WIN32})
612
option(CUKE_USE_STATIC_GTEST "Statically link Google Test" ON)
713
option(CUKE_DISABLE_BOOST_TEST "Disable boost:test" OFF)
@@ -311,6 +317,8 @@ else()
311317
${ARGN}
312318
${CUKE_FEATURES_DIR}
313319
${USES_TERMINAL}
320+
# Execute in same directory as where DLLs appear on Windows
321+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
314322
)
315323
endfunction(add_feature_target)
316324

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ install:
4141

4242
build_script:
4343
- cmake -E make_directory build
44-
- cmake -E chdir build cmake -G "%CMAKE_GENERATOR%" -DCUKE_ENABLE_EXAMPLES=ON -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_INCLUDEDIR="%BOOST_INCLUDEDIR%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DCMAKE_PREFIX_PATH="%QT_DIR%" ..
44+
- cmake -E chdir build cmake -G "%CMAKE_GENERATOR%" -DCUKE_ENABLE_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_INCLUDEDIR="%BOOST_INCLUDEDIR%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DCMAKE_PREFIX_PATH="%QT_DIR%" ..
4545
- cmake --build build
4646

4747
test_script:

cmake/modules/FindGMock.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ if(NOT (${GMOCK_LIBRARY_EXISTS} AND ${GTEST_LIBRARY_EXISTS}))
260260

261261
if(GTEST_USE_STATIC_LIBS)
262262
set(GTEST_CMAKE_ARGS -Dgtest_force_shared_crt:BOOL=ON -DBUILD_SHARED_LIBS=OFF)
263+
if(BUILD_SHARED_LIBS)
264+
list(APPEND GTEST_CMAKE_ARGS
265+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
266+
-Dgtest_hide_internal_symbols=ON
267+
-DCMAKE_CXX_VISIBILITY_PRESET=hidden
268+
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON
269+
-DCMAKE_POLICY_DEFAULT_CMP0063=NEW
270+
)
271+
endif()
263272
set(GTEST_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
264273
else()
265274
set(GTEST_CMAKE_ARGS -DBUILD_SHARED_LIBS=ON)

examples/Calc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project(Calc)
22

3-
add_library(Calc src/Calculator)
3+
add_library(Calc STATIC src/Calculator)
44
target_include_directories(Calc INTERFACE src)
55

66
if(TARGET GTest::GTest)

examples/CalcQt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(CalcQt)
22

33
if(TARGET Qt::Core AND TARGET Qt::Gui AND TARGET Qt::Widgets AND TARGET Qt::Test)
4-
add_library(libcalcqt src/CalculatorWidget.cpp src/CalculatorWidget.h)
4+
add_library(libcalcqt STATIC src/CalculatorWidget.cpp src/CalculatorWidget.h)
55
set_target_properties(libcalcqt PROPERTIES AUTOMOC ON)
66
target_include_directories(libcalcqt INTERFACE src)
77
target_link_libraries(libcalcqt

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 <cucumber-cpp/internal/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 <cucumber-cpp/internal/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 <cucumber-cpp/internal/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 <cucumber-cpp/internal/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 <cucumber-cpp/internal/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 <cucumber-cpp/internal/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: 4 additions & 3 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 <cucumber-cpp/internal/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
@@ -90,7 +91,7 @@ class TCPSocketServer : public SocketServer {
9091
/**
9192
* Socket server that calls a protocol handler line by line
9293
*/
93-
class UnixSocketServer : public SocketServer {
94+
class CUCUMBER_CPP_EXPORT UnixSocketServer : public SocketServer {
9495
public:
9596
/**
9697
* Constructor for DI

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#define CUKE_BOOSTDRIVER_HPP_
33

44
#include "../step/StepManager.hpp"
5+
#include <cucumber-cpp/internal/CukeExport.hpp>
56

67
namespace cucumber {
78
namespace internal {
89

910
class CukeBoostLogInterceptor;
1011

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

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 <cucumber-cpp/internal/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/drivers/GenericDriver.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define CUKE_GENERICDRIVER_HPP_
33

44
#include "../step/StepManager.hpp"
5+
#include <cucumber-cpp/internal/CukeExport.hpp>
56

67
namespace cucumber {
78
namespace internal {
89

9-
class GenericStep : public BasicStep {
10+
class CUCUMBER_CPP_EXPORT GenericStep : public BasicStep {
1011
protected:
1112
virtual const InvokeResult invokeStepBody();
1213
};

0 commit comments

Comments
 (0)