Skip to content

Commit cd885d2

Browse files
authored
Merge pull request #1001 from redboltz/minimal_support_for_no_boost
Minimall supported build without boost.
2 parents 59f2da6 + 066d509 commit cd885d2

File tree

436 files changed

+47802
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

436 files changed

+47802
-69
lines changed

.github/workflows/gha.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
4)
150150
export CXX="clang++-10"
151151
export MSGPACK_CXX_VERSION="MSGPACK_CXX20=ON"
152+
export NO_BOOST="-DMSGPACK_NO_BOOST"
152153
;;
153154
5)
154155
export CXX="g++-10"
@@ -183,7 +184,7 @@ jobs:
183184
esac
184185
185186
# build and test
186-
CMAKE_CXX_COMPILER="$CXX" CXXFLAGS="-Werror -g ${SANITIZE}" ci/build_cmake.sh || exit 1
187+
CMAKE_CXX_COMPILER="$CXX" CXXFLAGS="-Werror -g ${SANITIZE} ${NO_BOOST}" ci/build_cmake.sh || exit 1
187188
cat Files.cmake| grep ".*\.[h|hpp]" | perl -pe 's/ //g' | sort > tmp1 && find include -name "*.h" -o -name "*.hpp" | sort > tmp2 && diff tmp1 tmp2
188189
189190
windows:

CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OPTION (MSGPACK_CXX17 "Using c++17 compiler" OFF)
2222
OPTION (MSGPACK_CXX20 "Using c++20 compiler" OFF)
2323

2424
OPTION (MSGPACK_32BIT "32bit compile" OFF)
25+
OPTION (MSGPACK_USE_BOOST "Use Boost libraried" ON)
2526
OPTION (MSGPACK_USE_X3_PARSE "Use Boost X3 parse" OFF)
2627
OPTION (MSGPACK_BUILD_TESTS "Build tests" OFF)
2728
OPTION (MSGPACK_BUILD_DOCS "Build Doxygen documentation" ON)
@@ -62,14 +63,20 @@ IF (MSGPACK_32BIT)
6263
ENDIF ()
6364
ENDIF ()
6465

65-
SET (Boost_USE_MULTITHREADED ON)
66+
IF (MSGPACK_USE_BOOST)
67+
SET (Boost_USE_MULTITHREADED ON)
6668

67-
IF (MSGPACK_USE_STATIC_BOOST)
68-
MESSAGE (STATUS "Staticly linking with Boost")
69-
SET (Boost_USE_STATIC_LIBS TRUE)
69+
IF (MSGPACK_USE_STATIC_BOOST)
70+
MESSAGE (STATUS "Staticly linking with Boost")
71+
SET (Boost_USE_STATIC_LIBS TRUE)
72+
ELSE ()
73+
MESSAGE (STATUS "Dynamically linking with Boost")
74+
SET (Boost_USE_STATIC_LIBS FALSE)
75+
ENDIF ()
76+
77+
FIND_PACKAGE (Boost REQUIRED)
7078
ELSE ()
71-
MESSAGE (STATUS "Dynamically linking with Boost")
72-
SET (Boost_USE_STATIC_LIBS FALSE)
79+
SET (CMAKE_CXX_FLAGS "-DMSGPACK_NO_BOOST ${CMAKE_CXX_FLAGS}")
7380
ENDIF ()
7481

7582
IF (MSGPACK_CHAR_SIGN)
@@ -100,7 +107,6 @@ int main(int argc, char * argv[])
100107
ENDIF ()
101108
ENDIF ()
102109

103-
FIND_PACKAGE (Boost REQUIRED)
104110

105111
INCLUDE (Files.cmake)
106112

@@ -113,7 +119,9 @@ TARGET_INCLUDE_DIRECTORIES (msgpackc-cxx
113119
$<INSTALL_INTERFACE:include>
114120
)
115121

116-
TARGET_LINK_LIBRARIES (msgpackc-cxx INTERFACE Boost::boost)
122+
IF (MSGPACK_USE_BOOST)
123+
TARGET_LINK_LIBRARIES (msgpackc-cxx INTERFACE Boost::boost)
124+
ENDIF ()
117125

118126
IF (MSGPACK_GEN_COVERAGE)
119127
IF (NOT MSGPACK_BUILD_TESTS)
@@ -131,6 +139,9 @@ IF (MSGPACK_GEN_COVERAGE)
131139
ENDIF ()
132140

133141
IF (MSGPACK_BUILD_TESTS)
142+
IF (NOT MSGPACK_USE_BOOST)
143+
MESSAGE(FATAL_ERROR "Test requires -DMSGPACK_USE_BOOST=ON")
144+
ENDIF ()
134145
ENABLE_TESTING ()
135146
# MEMORYCHECK_COMMAND_OPTIONS needs to place prior to CTEST_MEMORYCHECK_COMMAND
136147
SET (MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=definite,possible --error-exitcode=1")

Files.cmake

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ C++ version of msgpack-c itself is a header-only library and depends only on
7171
boost headers. Tests depend on boost unit test framework and are linked with
7272
it, so if you want to build them, you need to have this dependency installed.
7373

74+
Experimental support for removing boost dependency
75+
76+
For cmake:
77+
78+
```
79+
cmake -DMSGPACK_USE_BOOST=OFF ..
80+
```
81+
82+
NOTE: `-DMSGPACK_BUILD_TESTS=ON` doesn't work with `-DMSGPACK_USE_BOOST=OFF`.
83+
84+
For C++ compiler
85+
86+
```
87+
clang++ -DMSGPACK_NO_BOOST your_code.cpp
88+
```
89+
90+
7491
Usage
7592
-----
7693

erb/v1/cpp03_zone.hpp.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313
#include "msgpack/versioning.hpp"
1414
#include "msgpack/cpp_config.hpp"
1515
#include "msgpack/zone_decl.hpp"
16+
#include "msgpack/assert.hpp"
1617

1718
#include <stdint.h>
1819
#include <cstdlib>
1920
#include <memory>
2021
#include <vector>
2122

22-
#include <boost/assert.hpp>
23-
2423
<% GENERATION_LIMIT = 15 %>
2524
namespace msgpack {
2625

@@ -201,7 +200,7 @@ inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_
201200

202201
inline char* zone::get_aligned(char* ptr, size_t align)
203202
{
204-
BOOST_ASSERT(align != 0 && (align & (align - 1)) == 0); // align must be 2^n (n >= 0)
203+
MSGPACK_ASSERT(align != 0 && (align & (align - 1)) == 0); // align must be 2^n (n >= 0)
205204
return
206205
reinterpret_cast<char*>(
207206
reinterpret_cast<uintptr_t>(ptr + (align - 1)) & ~static_cast<uintptr_t>(align - 1)

example/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
ADD_SUBDIRECTORY (cpp03)
22
ADD_SUBDIRECTORY (cpp11)
3-
ADD_SUBDIRECTORY (boost)
4-
ADD_SUBDIRECTORY (x3)
3+
4+
IF (MSGPACK_USE_BOOST)
5+
ADD_SUBDIRECTORY (boost)
6+
IF (MSGPACK_USE_X3_PARSE)
7+
ADD_SUBDIRECTORY (x3)
8+
ENDIF ()
9+
ENDIF ()

example/cpp03/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ IF (NOT MSVC)
2626
)
2727
ENDIF ()
2828

29-
if (Boost_TIMER_LIBRARY)
30-
LIST (APPEND with_boost_lib_PROGRAMS
31-
speed_test.cpp
32-
speed_test_nested_array.cpp
33-
)
34-
endif()
29+
30+
IF (MSGPACK_USE_BOOST)
31+
IF (Boost_TIMER_LIBRARY)
32+
LIST (APPEND with_boost_lib_PROGRAMS
33+
speed_test.cpp
34+
speed_test_nested_array.cpp
35+
)
36+
ENDIF ()
37+
ENDIF ()
3538

3639
FOREACH (source_file ${exec_PROGRAMS})
3740
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)

include/msgpack/adaptor/define_decl.hpp

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,74 @@
1010
#ifndef MSGPACK_DEFINE_DECL_HPP
1111
#define MSGPACK_DEFINE_DECL_HPP
1212

13-
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
13+
#if defined(MSGPACK_NO_BOOST)
14+
15+
// MSGPACK_PP_VARIADICS is defined in msgpack/preprocessor/config/config.hpp
1416
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
1517
// However, supporting compiler detection is not complete. msgpack-c requires
16-
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
17-
#if !defined(BOOST_PP_VARIADICS)
18-
#define BOOST_PP_VARIADICS
18+
// variadic macro arguments support. So MSGPACK_PP_VARIADICS is defined here explicitly.
19+
#if !defined(MSGPACK_PP_VARIADICS)
20+
#define MSGPACK_PP_VARIADICS
1921
#endif
2022

21-
#include <boost/preprocessor.hpp>
23+
#include <msgpack/preprocessor.hpp>
2224

23-
#include "msgpack/versioning.hpp"
25+
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
26+
#define MSGPACK_NVP(name, value) (name) (value)
2427

25-
// for MSGPACK_ADD_ENUM
26-
#include "msgpack/adaptor/int.hpp"
28+
#define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
29+
MSGPACK_PP_IF( \
30+
MSGPACK_PP_IS_BEGIN_PARENS(elem), \
31+
elem, \
32+
(MSGPACK_PP_STRINGIZE(elem))(elem) \
33+
)
2734

28-
#define MSGPACK_DEFINE_ARRAY(...) \
35+
#define MSGPACK_DEFINE_MAP_IMPL(...) \
36+
MSGPACK_PP_SEQ_TO_TUPLE( \
37+
MSGPACK_PP_SEQ_FOR_EACH( \
38+
MSGPACK_DEFINE_MAP_EACH_PROC, \
39+
0, \
40+
MSGPACK_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
41+
) \
42+
)
43+
44+
#define MSGPACK_DEFINE_MAP(...) \
2945
template <typename Packer> \
3046
void msgpack_pack(Packer& msgpack_pk) const \
3147
{ \
32-
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
48+
msgpack::type::make_define_map \
49+
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
50+
.msgpack_pack(msgpack_pk); \
3351
} \
3452
void msgpack_unpack(msgpack::object const& msgpack_o) \
3553
{ \
36-
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
54+
msgpack::type::make_define_map \
55+
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
56+
.msgpack_unpack(msgpack_o); \
3757
}\
3858
template <typename MSGPACK_OBJECT> \
3959
void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
4060
{ \
41-
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
61+
msgpack::type::make_define_map \
62+
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
63+
.msgpack_object(msgpack_o, msgpack_z); \
4264
}
4365

66+
#define MSGPACK_BASE_MAP(base) \
67+
(MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
68+
69+
#else // defined(MSGPACK_NO_BOOST)
70+
71+
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
72+
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
73+
// However, supporting compiler detection is not complete. msgpack-c requires
74+
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
75+
#if !defined(BOOST_PP_VARIADICS)
76+
#define BOOST_PP_VARIADICS
77+
#endif
78+
79+
#include <boost/preprocessor.hpp>
80+
4481
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
4582
#define MSGPACK_NVP(name, value) (name) (value)
4683

@@ -85,6 +122,29 @@
85122
#define MSGPACK_BASE_MAP(base) \
86123
(BOOST_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
87124

125+
#endif // defined(MSGPACK_NO_BOOST)
126+
127+
#include "msgpack/versioning.hpp"
128+
129+
// for MSGPACK_ADD_ENUM
130+
#include "msgpack/adaptor/int.hpp"
131+
132+
#define MSGPACK_DEFINE_ARRAY(...) \
133+
template <typename Packer> \
134+
void msgpack_pack(Packer& msgpack_pk) const \
135+
{ \
136+
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
137+
} \
138+
void msgpack_unpack(msgpack::object const& msgpack_o) \
139+
{ \
140+
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
141+
}\
142+
template <typename MSGPACK_OBJECT> \
143+
void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
144+
{ \
145+
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
146+
}
147+
88148
// MSGPACK_ADD_ENUM must be used in the global namespace.
89149
#define MSGPACK_ADD_ENUM(enum_name) \
90150
namespace msgpack { \

include/msgpack/assert.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2022 KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
11+
#ifndef MSGPACK_ASSERT_HPP
12+
#define MSGPACK_ASSERT_HPP
13+
14+
#if defined(MSGPACK_NO_BOOST)
15+
16+
#include <cassert>
17+
#define MSGPACK_ASSERT assert
18+
19+
#else // defined(MSGPACK_NO_BOOST)
20+
21+
#include <boost/assert.hpp>
22+
#define MSGPACK_ASSERT BOOST_ASSERT
23+
24+
#endif // defined(MSGPACK_NO_BOOST)
25+
26+
#endif // MSGPACK_ASSERT_HPP

include/msgpack/predef.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright Rene Rivera 2008-2015
3+
Distributed under the Boost Software License, Version 1.0.
4+
(See accompanying file LICENSE_1_0.txt or copy at
5+
http://www.boost.org/LICENSE_1_0.txt)
6+
*/
7+
8+
#if !defined(MSGPACK_PREDEF_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS)
9+
#ifndef MSGPACK_PREDEF_H
10+
#define MSGPACK_PREDEF_H
11+
#endif
12+
13+
#include <msgpack/predef/language.h>
14+
#include <msgpack/predef/architecture.h>
15+
#include <msgpack/predef/compiler.h>
16+
#include <msgpack/predef/library.h>
17+
#include <msgpack/predef/os.h>
18+
#include <msgpack/predef/other.h>
19+
#include <msgpack/predef/platform.h>
20+
#include <msgpack/predef/hardware.h>
21+
22+
#include <msgpack/predef/version.h>
23+
24+
#endif

0 commit comments

Comments
 (0)