Skip to content

Support building as a shared library on Windows #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 23, 2018
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
cmake_minimum_required(VERSION 3.1)

if(NOT CMAKE_VERSION VERSION_LESS "3.3")
# Don't ignore visibility related properties for non-SHARED targets
cmake_policy(SET CMP0063 NEW)
endif()

project(Cucumber-Cpp)

option(BUILD_SHARED_LIBS "Generate shared libraries" OFF)
option(CUKE_USE_STATIC_BOOST "Statically link Boost (except boost::test)" ${WIN32})
option(CUKE_USE_STATIC_GTEST "Statically link Google Test" ON)
option(CUKE_DISABLE_BOOST_TEST "Disable boost:test" OFF)
Expand Down Expand Up @@ -311,6 +317,8 @@ else()
${ARGN}
${CUKE_FEATURES_DIR}
${USES_TERMINAL}
# Execute in same directory as where DLLs appear on Windows
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
)
endfunction(add_feature_target)

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ install:

build_script:
- cmake -E make_directory build
- 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%" ..
- 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%" ..
- cmake --build build

test_script:
Expand Down
9 changes: 9 additions & 0 deletions cmake/modules/FindGMock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ if(NOT (${GMOCK_LIBRARY_EXISTS} AND ${GTEST_LIBRARY_EXISTS}))

if(GTEST_USE_STATIC_LIBS)
set(GTEST_CMAKE_ARGS -Dgtest_force_shared_crt:BOOL=ON -DBUILD_SHARED_LIBS=OFF)
if(BUILD_SHARED_LIBS)
list(APPEND GTEST_CMAKE_ARGS
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-Dgtest_hide_internal_symbols=ON
-DCMAKE_CXX_VISIBILITY_PRESET=hidden
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON
-DCMAKE_POLICY_DEFAULT_CMP0063=NEW
)
endif()
set(GTEST_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
else()
set(GTEST_CMAKE_ARGS -DBUILD_SHARED_LIBS=ON)
Expand Down
2 changes: 1 addition & 1 deletion examples/Calc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(Calc)

add_library(Calc src/Calculator)
add_library(Calc STATIC src/Calculator)
target_include_directories(Calc INTERFACE src)

if(TARGET GTest::GTest)
Expand Down
2 changes: 1 addition & 1 deletion examples/CalcQt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(CalcQt)

if(TARGET Qt::Core AND TARGET Qt::Gui AND TARGET Qt::Widgets AND TARGET Qt::Test)
add_library(libcalcqt src/CalculatorWidget.cpp src/CalculatorWidget.h)
add_library(libcalcqt STATIC src/CalculatorWidget.cpp src/CalculatorWidget.h)
set_target_properties(libcalcqt PROPERTIES AUTOMOC ON)
target_include_directories(libcalcqt INTERFACE src)
target_link_libraries(libcalcqt
Expand Down
4 changes: 3 additions & 1 deletion include/cucumber-cpp/internal/ContextManager.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CUKE_CONTEXTMANAGER_HPP_
#define CUKE_CONTEXTMANAGER_HPP_

#include <cucumber-cpp/internal/CukeExport.hpp>

#include <vector>

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

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

class ContextManager {
class CUCUMBER_CPP_EXPORT ContextManager {
public:
void purgeContexts();
template<class T> boost::weak_ptr<T> addContext();
Expand Down
3 changes: 2 additions & 1 deletion include/cucumber-cpp/internal/CukeCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CUKE_CUKECOMMANDS_HPP_

#include "ContextManager.hpp"
#include <cucumber-cpp/internal/CukeExport.hpp>
#include "Scenario.hpp"
#include "Table.hpp"
#include "step/StepManager.hpp"
Expand All @@ -20,7 +21,7 @@ using boost::shared_ptr;
/**
* Legacy class to be removed when feature #31 is complete, substituted by CukeEngineImpl.
*/
class CukeCommands {
class CUCUMBER_CPP_EXPORT CukeCommands {
public:
CukeCommands();
virtual ~CukeCommands();
Expand Down
15 changes: 9 additions & 6 deletions include/cucumber-cpp/internal/CukeEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@

#include <boost/multi_array.hpp>

#include <cucumber-cpp/internal/CukeExport.hpp>

namespace cucumber {
namespace internal {

class StepMatchArg {
class CUCUMBER_CPP_EXPORT StepMatchArg {
public:
std::string value;
std::ptrdiff_t position;
};

class StepMatch {
class CUCUMBER_CPP_EXPORT StepMatch {
public:
std::string id;
std::vector<StepMatchArg> args;
std::string source;
std::string regexp;
};

class InvokeException {
class CUCUMBER_CPP_EXPORT InvokeException {
private:
const std::string message;

Expand All @@ -37,7 +39,7 @@ class InvokeException {
virtual ~InvokeException() {}
};

class InvokeFailureException : public InvokeException {
class CUCUMBER_CPP_EXPORT InvokeFailureException : public InvokeException {
private:
const std::string exceptionType;

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

class PendingStepException : public InvokeException {
class CUCUMBER_CPP_EXPORT PendingStepException : public InvokeException {
public:
PendingStepException(const std::string & message);
PendingStepException(const PendingStepException &rhs);
Expand Down Expand Up @@ -96,7 +98,8 @@ class CukeEngine {
*/
virtual std::string snippetText(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) const = 0;

virtual ~CukeEngine() {}
CUCUMBER_CPP_EXPORT CukeEngine();
CUCUMBER_CPP_EXPORT virtual ~CukeEngine();
};

}
Expand Down
3 changes: 2 additions & 1 deletion include/cucumber-cpp/internal/CukeEngineImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CUKE_CUKEENGINE_IMPL_HPP_

#include "CukeEngine.hpp"
#include <cucumber-cpp/internal/CukeExport.hpp>
#include "CukeCommands.hpp"

namespace cucumber {
Expand All @@ -13,7 +14,7 @@ namespace internal {
* Currently it is a wrapper around CukeCommands. It will have its own
* implementation when feature #31 is complete.
*/
class CukeEngineImpl : public CukeEngine {
class CUCUMBER_CPP_EXPORT CukeEngineImpl : public CukeEngine {
private:
CukeCommands cukeCommands;

Expand Down
4 changes: 3 additions & 1 deletion include/cucumber-cpp/internal/Table.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CUKE_TABLE_HPP_
#define CUKE_TABLE_HPP_

#include <cucumber-cpp/internal/CukeExport.hpp>

#include <vector>
#include <map>
#include <string>
Expand All @@ -9,7 +11,7 @@
namespace cucumber {
namespace internal {

class Table {
class CUCUMBER_CPP_EXPORT Table {
private:
typedef std::vector<std::string> basic_type;
public:
Expand Down
26 changes: 14 additions & 12 deletions include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef CUKE_WIREPROTOCOL_HPP_
#define CUKE_WIREPROTOCOL_HPP_

#include <cucumber-cpp/internal/CukeExport.hpp>
#include "ProtocolHandler.hpp"
#include "../../CukeEngine.hpp"

#include <boost/shared_ptr.hpp>

namespace cucumber {
Expand All @@ -14,7 +16,7 @@ namespace internal {

class WireResponseVisitor;

class WireResponse {
class CUCUMBER_CPP_EXPORT WireResponse {
public:
WireResponse() {};

Expand All @@ -23,12 +25,12 @@ class WireResponse {
virtual ~WireResponse() {};
};

class SuccessResponse : public WireResponse {
class CUCUMBER_CPP_EXPORT SuccessResponse : public WireResponse {
public:
void accept(WireResponseVisitor& visitor) const;
};

class FailureResponse : public WireResponse {
class CUCUMBER_CPP_EXPORT FailureResponse : public WireResponse {
private:
const std::string message, exceptionType;

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

class PendingResponse : public WireResponse {
class CUCUMBER_CPP_EXPORT PendingResponse : public WireResponse {
private:
const std::string message;

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

class StepMatchesResponse : public WireResponse {
class CUCUMBER_CPP_EXPORT StepMatchesResponse : public WireResponse {
private:
const std::vector<StepMatch> matchingSteps;

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

class SnippetTextResponse : public WireResponse {
class CUCUMBER_CPP_EXPORT SnippetTextResponse : public WireResponse {
private:
const std::string stepSnippet;

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

class WireResponseVisitor {
class CUCUMBER_CPP_EXPORT WireResponseVisitor {
public:
virtual void visit(const SuccessResponse& response) = 0;
virtual void visit(const FailureResponse& response) = 0;
Expand All @@ -91,7 +93,7 @@ class WireResponseVisitor {
/**
* Wire protocol request command.
*/
class WireCommand {
class CUCUMBER_CPP_EXPORT WireCommand {
public:
/**
* Runs the command on the provided engine
Expand All @@ -105,7 +107,7 @@ class WireCommand {
virtual ~WireCommand() {};
};

class WireMessageCodecException : public std::exception {
class CUCUMBER_CPP_EXPORT WireMessageCodecException : public std::exception {
private:
const char *description;

Expand All @@ -123,7 +125,7 @@ class WireMessageCodecException : public std::exception {
/**
* Transforms wire messages into commands and responses to messages.
*/
class WireMessageCodec {
class CUCUMBER_CPP_EXPORT WireMessageCodec {
public:
/**
* Decodes a wire message into a command.
Expand Down Expand Up @@ -151,7 +153,7 @@ class WireMessageCodec {
/**
* WireMessageCodec implementation with JsonSpirit.
*/
class JsonSpiritWireMessageCodec : public WireMessageCodec {
class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec {
public:
JsonSpiritWireMessageCodec();
boost::shared_ptr<WireCommand> decode(const std::string &request) const;
Expand All @@ -162,7 +164,7 @@ class JsonSpiritWireMessageCodec : public WireMessageCodec {
* Wire protocol handler, delegating JSON encoding and decoding to a
* codec object and running commands on a provided engine instance.
*/
class WireProtocolHandler : public ProtocolHandler {
class CUCUMBER_CPP_EXPORT WireProtocolHandler : public ProtocolHandler {
private:
const WireMessageCodec& codec;
CukeEngine& engine;
Expand Down
7 changes: 4 additions & 3 deletions include/cucumber-cpp/internal/connectors/wire/WireServer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CUKE_WIRESERVER_HPP_
#define CUKE_WIRESERVER_HPP_

#include <cucumber-cpp/internal/CukeExport.hpp>
#include "ProtocolHandler.hpp"

#include <string>
Expand All @@ -13,7 +14,7 @@ namespace internal {
/**
* Socket server that calls a protocol handler line by line
*/
class SocketServer {
class CUCUMBER_CPP_EXPORT SocketServer {
public:
/**
* Constructor for DI
Expand Down Expand Up @@ -49,7 +50,7 @@ class SocketServer {
/**
* Socket server that calls a protocol handler line by line
*/
class TCPSocketServer : public SocketServer {
class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
public:
/**
* Type definition for TCP port
Expand Down Expand Up @@ -90,7 +91,7 @@ class TCPSocketServer : public SocketServer {
/**
* Socket server that calls a protocol handler line by line
*/
class UnixSocketServer : public SocketServer {
class CUCUMBER_CPP_EXPORT UnixSocketServer : public SocketServer {
public:
/**
* Constructor for DI
Expand Down
3 changes: 2 additions & 1 deletion include/cucumber-cpp/internal/drivers/BoostDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#define CUKE_BOOSTDRIVER_HPP_

#include "../step/StepManager.hpp"
#include <cucumber-cpp/internal/CukeExport.hpp>

namespace cucumber {
namespace internal {

class CukeBoostLogInterceptor;

class BoostStep : public BasicStep {
class CUCUMBER_CPP_EXPORT BoostStep : public BasicStep {
protected:
const InvokeResult invokeStepBody();

Expand Down
3 changes: 2 additions & 1 deletion include/cucumber-cpp/internal/drivers/GTestDriver.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef CUKE_GTESTDRIVER_HPP_
#define CUKE_GTESTDRIVER_HPP_

#include <cucumber-cpp/internal/CukeExport.hpp>
#include "../step/StepManager.hpp"

#include <iostream>

namespace cucumber {
namespace internal {

class GTestStep : public BasicStep {
class CUCUMBER_CPP_EXPORT GTestStep : public BasicStep {
protected:
const InvokeResult invokeStepBody();

Expand Down
3 changes: 2 additions & 1 deletion include/cucumber-cpp/internal/drivers/GenericDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define CUKE_GENERICDRIVER_HPP_

#include "../step/StepManager.hpp"
#include <cucumber-cpp/internal/CukeExport.hpp>

namespace cucumber {
namespace internal {

class GenericStep : public BasicStep {
class CUCUMBER_CPP_EXPORT GenericStep : public BasicStep {
protected:
virtual const InvokeResult invokeStepBody();
};
Expand Down
Loading