Skip to content

Commit 4d47d6c

Browse files
authored
Merge pull request #275 from ursfassler/less-boost
Remove dependency to Boost
2 parents bcdf7d3 + d131ae3 commit 4d47d6c

File tree

18 files changed

+150
-285
lines changed

18 files changed

+150
-285
lines changed

.github/workflows/run-all.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
g++ \
2323
gcovr \
2424
git \
25-
libboost-program-options-dev \
26-
libboost-system-dev \
25+
libasio-dev \
2726
libboost-test-dev \
27+
libtclap-dev \
2828
make \
2929
ninja-build \
3030
nlohmann-json3-dev \

CMakeLists.txt

+1-60
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ endif()
1414
project(Cucumber-Cpp)
1515

1616
option(BUILD_SHARED_LIBS "Generate shared libraries" OFF)
17-
option(CUKE_USE_STATIC_BOOST "Statically link Boost (except boost::test)" ${WIN32})
1817
option(CUKE_USE_STATIC_GTEST "Statically link Google Test" ON)
1918
option(CUKE_ENABLE_BOOST_TEST "Enable Boost.Test framework" ON)
2019
option(CUKE_ENABLE_EXAMPLES "Build examples" OFF)
@@ -111,69 +110,11 @@ endif()
111110
# Boost
112111
#
113112

114-
if(MSVC11)
115-
# Boost 1.51 fixed a bug with MSVC11
116-
message(STATUS "Forcing Boost 1.51+ on MSVC11")
117-
set(BOOST_MIN_VERSION "1.51")
118-
else()
119-
set(BOOST_MIN_VERSION "1.46")
120-
endif()
121-
122113
set(Boost_USE_STATIC_RUNTIME OFF)
123-
set(CUKE_CORE_BOOST_LIBS system program_options)
124114
if(CUKE_ENABLE_BOOST_TEST)
125115
# "An external test runner utility is required to link with dynamic library" (Boost User's Guide)
126-
set(Boost_USE_STATIC_LIBS OFF)
127116
set(CMAKE_CXX_FLAGS "-DBOOST_TEST_DYN_LINK ${CMAKE_CXX_FLAGS}")
128-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS unit_test_framework)
129-
endif()
130-
131-
if(CUKE_USE_STATIC_BOOST)
132-
set(Boost_USE_STATIC_LIBS ON)
133-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_CORE_BOOST_LIBS} REQUIRED)
134-
else()
135-
set(CMAKE_CXX_FLAGS "-DBOOST_ALL_DYN_LINK ${CMAKE_CXX_FLAGS}")
136-
set(Boost_USE_STATIC_LIBS OFF)
137-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_CORE_BOOST_LIBS} REQUIRED)
138-
endif()
139-
140-
# Create import targets for CMake versions older than 3.5 (actually older FindBoost.cmake)
141-
if(Boost_USE_STATIC_LIBS)
142-
set(LIBRARY_TYPE STATIC)
143-
else()
144-
# Just because we don't ask for static doesn't mean we're not getting static
145-
set(LIBRARY_TYPE UNKNOWN)
146-
endif()
147-
if(Boost_INCLUDE_DIRS AND NOT TARGET Boost::boost)
148-
add_library(Boost::boost INTERFACE IMPORTED)
149-
set_target_properties(Boost::boost PROPERTIES
150-
"INTERFACE_INCLUDE_DIRECTORIES" "${Boost_INCLUDE_DIRS}")
151-
endif()
152-
if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system)
153-
add_library(Boost::system ${LIBRARY_TYPE} IMPORTED)
154-
set_target_properties(Boost::system PROPERTIES
155-
"IMPORTED_LOCATION" "${Boost_SYSTEM_LIBRARY}"
156-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
157-
)
158-
if(Boost_USE_STATIC_LIBS)
159-
set_target_properties(Boost::system PROPERTIES
160-
"COMPILE_DEFINITIONS" BOOST_ERROR_CODE_HEADER_ONLY=1
161-
)
162-
endif()
163-
endif()
164-
if(Boost_PROGRAM_OPTIONS_LIBRARY AND NOT TARGET Boost::program_options)
165-
add_library(Boost::program_options ${LIBRARY_TYPE} IMPORTED)
166-
set_target_properties(Boost::program_options PROPERTIES
167-
"IMPORTED_LOCATION" "${Boost_PROGRAM_OPTIONS_LIBRARY}"
168-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
169-
)
170-
endif()
171-
if(Boost_UNIT_TEST_FRAMEWORK_LIBRARY AND NOT TARGET Boost::unit_test_framework)
172-
add_library(Boost::unit_test_framework ${LIBRARY_TYPE} IMPORTED)
173-
set_target_properties(Boost::unit_test_framework PROPERTIES
174-
"IMPORTED_LOCATION" "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}"
175-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
176-
)
117+
find_package(Boost 1.70 COMPONENTS unit_test_framework)
177118
endif()
178119

179120
#

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ It relies on a few executables:
2222

2323
It relies on a few libraries:
2424

25-
* [Boost](http://www.boost.org/) 1.46 or later (1.51+ on Windows).
26-
Required libraries: *system* and *program_options*.
27-
Optional library for Boost Test driver: *test*.
25+
* [Asio](https://think-async.com/Asio/) 1.18.1 or later.
26+
* [Boost.Test](http://www.boost.org/) 1.70. Optional for the Boost Test driver.
2827
* [GTest](http://code.google.com/p/googletest/) 1.6 or later.
2928
Optional for the GTest driver. By default downloaded and built by CMake.
3029
* [GMock](http://code.google.com/p/googlemock/) 1.6 or later.
3130
Optional for the internal test suite. By default downloaded and built by CMake.
3231
* [nlohmann-json](https://github.com/nlohmann/json) 3.10.5 or later.
3332
* [Qt 4 or 5](http://qt-project.org/). Optional for the CalcQt example and QtTest driver (only Qt 5).
33+
* [TCLAP](https://tclap.sourceforge.net/) 1.2.5 or later.
3434

3535
It might work with earlier versions of the libraries, but it was not tested with them.
3636
See the [CI scripts](.github/workflows/run-all.yml) for details about dependency installation.

cmake/modules/FindAsio.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
find_path(ASIO_INCLUDE_DIR asio.hpp)
2+
3+
if (ASIO_INCLUDE_DIR)
4+
set(ASIO_FOUND TRUE)
5+
else ()
6+
set(ASIO_FOUND FALSE)
7+
endif ()
8+
9+
include(FindPackageHandleStandardArgs)
10+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Asio REQUIRED_VARS ASIO_INCLUDE_DIR)

cmake/modules/FindTCLAP.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
find_path(TCLAP_INCLUDE_DIR tclap/CmdLine.h)
2+
3+
if (TCLAP_INCLUDE_DIR)
4+
set(TCLAP_FOUND TRUE)
5+
else ()
6+
set(TCLAP_FOUND FALSE)
7+
endif ()
8+
9+
include(FindPackageHandleStandardArgs)
10+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCLAP REQUIRED_VARS TCLAP_INCLUDE_DIR)

cmake/modules/GitVersion.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function(git_get_version VERSION_VARIABLE)
2+
find_program(GIT_EXECUTABLE git)
3+
4+
if(NOT GIT_EXECUTABLE)
5+
message(FATAL_ERROR "Git not found. Please install Git and make sure it is in your system's PATH.")
6+
endif()
7+
8+
execute_process(
9+
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
10+
OUTPUT_VARIABLE VERSION_STRING
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
13+
ERROR_VARIABLE GIT_DESCRIBE_ERROR
14+
RESULT_VARIABLE GIT_DESCRIBE_RESULT
15+
)
16+
17+
if(NOT GIT_DESCRIBE_RESULT EQUAL 0)
18+
message(FATAL_ERROR "Error running 'git describe': ${GIT_DESCRIBE_ERROR}")
19+
endif()
20+
21+
string(LENGTH "${VERSION_STRING}" VERSION_STRING_LENGTH)
22+
string(SUBSTRING "${VERSION_STRING}" 0 1 FIRST_CHARACTER)
23+
24+
if("${FIRST_CHARACTER}" STREQUAL "v")
25+
string(SUBSTRING "${VERSION_STRING}" 1 ${VERSION_STRING_LENGTH} VERSION_STRING)
26+
endif()
27+
28+
set(${VERSION_VARIABLE} ${VERSION_STRING} PARENT_SCOPE)
29+
endfunction()
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
#ifndef CUKE_REGISTRATIONMACROS_HPP_
22
#define CUKE_REGISTRATIONMACROS_HPP_
33

4-
#if __cplusplus >= 201103L
5-
#define CUKE_OVERRIDE override
6-
#else
7-
#define CUKE_OVERRIDE
8-
#endif
9-
104
// ************************************************************************** //
115
// ************** OBJECT NAMING MACROS ************** //
126
// ************************************************************************** //
137

8+
// from https://www.boost.org/doc/libs/1_84_0/boost/config/helper_macros.hpp
9+
#define CUKE_JOIN(X, Y) CUKE_DO_JOIN(X, Y)
10+
#define CUKE_DO_JOIN(X, Y) CUKE_DO_JOIN2(X, Y)
11+
#define CUKE_DO_JOIN2(X, Y) X##Y
12+
1413
#ifndef CUKE_OBJECT_PREFIX
1514
#define CUKE_OBJECT_PREFIX CukeObject
1615
#endif
1716

1817
#ifdef __COUNTER__
19-
#define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __COUNTER__)
18+
#define CUKE_GEN_OBJECT_NAME_ CUKE_JOIN(CUKE_OBJECT_PREFIX, __COUNTER__)
2019
#else
2120
// Use a counter to be incremented every time cucumber-cpp is included
2221
// in case this does not suffice (possible with multiple files only)
23-
#define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __LINE__)
22+
#define CUKE_GEN_OBJECT_NAME_ CUKE_JOIN(CUKE_OBJECT_PREFIX, __LINE__)
2423
#endif
2524

2625
// ************************************************************************** //
2726
// ************** CUKE OBJECTS ************** //
2827
// ************************************************************************** //
2928

30-
#define CUKE_OBJECT_(class_name, parent_class, registration_fn, args) \
31-
class class_name : public parent_class { \
32-
public: \
33-
void body() CUKE_OVERRIDE { return invokeWithArgs(*this, &class_name::bodyWithArgs); } \
34-
void bodyWithArgs args; \
35-
\
36-
private: \
37-
static const int cukeRegId; \
38-
}; \
39-
const int class_name ::cukeRegId = registration_fn; \
29+
#define CUKE_OBJECT_(class_name, parent_class, registration_fn, args) \
30+
class class_name : public parent_class { \
31+
public: \
32+
void body() override { return invokeWithArgs(*this, &class_name::bodyWithArgs); } \
33+
void bodyWithArgs args; \
34+
\
35+
private: \
36+
static const int cukeRegId; \
37+
}; \
38+
const int class_name ::cukeRegId = registration_fn; \
4039
void class_name ::bodyWithArgs args /**/
4140

4241
#endif /* CUKE_REGISTRATIONMACROS_HPP_ */

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

+12-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <string>
88

9-
#include <boost/asio.hpp>
9+
#include <asio.hpp>
1010

1111
namespace cucumber {
1212
namespace internal {
@@ -29,25 +29,14 @@ class CUCUMBER_CPP_EXPORT SocketServer {
2929

3030
protected:
3131
const ProtocolHandler* protocolHandler;
32-
boost::asio::io_service ios;
32+
asio::io_service ios;
3333

34-
#if BOOST_VERSION <= 106500
35-
template<typename Protocol, typename Service>
36-
void doListen(
37-
boost::asio::basic_socket_acceptor<Protocol, Service>& acceptor,
38-
const typename Protocol::endpoint& endpoint
39-
);
40-
template<typename Protocol, typename Service>
41-
void doAcceptOnce(boost::asio::basic_socket_acceptor<Protocol, Service>& acceptor);
42-
#else
4334
template<typename Protocol>
4435
void doListen(
45-
boost::asio::basic_socket_acceptor<Protocol>& acceptor,
46-
const typename Protocol::endpoint& endpoint
36+
asio::basic_socket_acceptor<Protocol>& acceptor, const typename Protocol::endpoint& endpoint
4737
);
4838
template<typename Protocol>
49-
void doAcceptOnce(boost::asio::basic_socket_acceptor<Protocol>& acceptor);
50-
#endif
39+
void doAcceptOnce(asio::basic_socket_acceptor<Protocol>& acceptor);
5140
void processStream(std::iostream& stream);
5241
};
5342

@@ -74,24 +63,24 @@ class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
7463
/**
7564
* Bind and listen to a TCP port on the given endpoint
7665
*/
77-
void listen(const boost::asio::ip::tcp::endpoint endpoint);
66+
void listen(const asio::ip::tcp::endpoint endpoint);
7867

7968
/**
8069
* Endpoint (IP address and port number) that this server is currently
8170
* listening on.
8271
*
83-
* @throw boost::system::system_error when not listening on any socket or
72+
* @throw std::system_error when not listening on any socket or
8473
* the endpoint cannot be determined.
8574
*/
86-
boost::asio::ip::tcp::endpoint listenEndpoint() const;
75+
asio::ip::tcp::endpoint listenEndpoint() const;
8776

8877
void acceptOnce() override;
8978

9079
private:
91-
boost::asio::ip::tcp::acceptor acceptor;
80+
asio::ip::tcp::acceptor acceptor;
9281
};
9382

94-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
83+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
9584
/**
9685
* Socket server that calls a protocol handler line by line
9786
*/
@@ -110,17 +99,17 @@ class CUCUMBER_CPP_EXPORT UnixSocketServer : public SocketServer {
11099
/**
111100
* Port number that this server is currently listening on.
112101
*
113-
* @throw boost::system::system_error when not listening on any socket or
102+
* @throw std::system_error when not listening on any socket or
114103
* the endpoint cannot be determined.
115104
*/
116-
boost::asio::local::stream_protocol::endpoint listenEndpoint() const;
105+
asio::local::stream_protocol::endpoint listenEndpoint() const;
117106

118107
void acceptOnce() override;
119108

120109
~UnixSocketServer() override;
121110

122111
private:
123-
boost::asio::local::stream_protocol::acceptor acceptor;
112+
asio::local::stream_protocol::acceptor acceptor;
124113
};
125114
#endif
126115

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include "../Scenario.hpp"
77
#include "../step/StepManager.hpp"
88

9-
#include <boost/config.hpp>
109
#include <memory>
11-
1210
#include <list>
1311

1412
namespace cucumber {
@@ -102,11 +100,7 @@ class CUCUMBER_CPP_EXPORT HookRegistrar {
102100

103101
private:
104102
// We're a singleton so don't allow instances
105-
HookRegistrar()
106-
#ifndef BOOST_NO_DELETED_FUNCTIONS
107-
= delete
108-
#endif
109-
;
103+
HookRegistrar() = delete;
110104
};
111105

112106
class CUCUMBER_CPP_EXPORT StepCallChain {

include/cucumber-cpp/internal/step/StepManager.hpp

+3-23
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@
66
#include <stdexcept>
77
#include <string>
88
#include <vector>
9-
10-
#include <boost/config.hpp>
119
#include <memory>
12-
13-
#ifndef BOOST_NO_VARIADIC_TEMPLATES
14-
#include <type_traits>
15-
#endif
10+
#include <type_traits>
1611

1712
#include <cucumber-cpp/internal/CukeExport.hpp>
1813
#include "../Table.hpp"
@@ -43,10 +38,7 @@ class CUCUMBER_CPP_EXPORT MatchResult {
4338
const match_results_type& getResultSet();
4439
void addMatch(SingleStepMatch match);
4540

46-
#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
47-
explicit
48-
#endif
49-
operator bool() const;
41+
explicit operator bool() const;
5042

5143
private:
5244
match_results_type resultSet;
@@ -139,13 +131,6 @@ class CUCUMBER_CPP_EXPORT BasicStep {
139131
const T getInvokeArg();
140132
const InvokeArgs* getArgs();
141133

142-
#ifdef BOOST_NO_VARIADIC_TEMPLATES
143-
// Special case for zero arguments, only thing we bother to support on C++98
144-
template<typename Derived, typename R>
145-
static R invokeWithArgs(Derived& that, R (Derived::*f)()) {
146-
return (that.*f)();
147-
}
148-
#else
149134
template<typename Derived, typename R, typename... Args, std::size_t... N>
150135
static R invokeWithIndexedArgs(Derived& that, R (Derived::*f)(Args...), index_sequence<N...>) {
151136
return (that.*f)(that.pArgs->template getInvokeArg<typename std::decay<Args>::type>(N)...);
@@ -156,7 +141,6 @@ class CUCUMBER_CPP_EXPORT BasicStep {
156141
that.currentArgIndex = sizeof...(Args);
157142
return invokeWithIndexedArgs(that, f, index_sequence_for<Args...>{});
158143
}
159-
#endif
160144

161145
private:
162146
// FIXME: awful hack because of Boost::Test
@@ -188,11 +172,7 @@ class CUCUMBER_CPP_EXPORT StepManager {
188172

189173
private:
190174
// We're a singleton so don't allow instances
191-
StepManager()
192-
#ifndef BOOST_NO_DELETED_FUNCTIONS
193-
= delete
194-
#endif
195-
;
175+
StepManager() = delete;
196176
};
197177

198178
static inline std::string toSourceString(const char* filePath, const int line) {

0 commit comments

Comments
 (0)