Skip to content

Commit 756d02f

Browse files
committed
Added Boost.Predef to check environment such as endian.
https://github.com/boostorg/predef.git has been added as a submodule on external/boost/predef. In order to avoid macro name conflicts, replaced "BOOST_" with "MSGPACK_" and "boost/" with "msgpack/" then copy replaced files to include/msgpack. This process is described in CMakeLists.txt. Replaced files are included as a part of msgpack-c. So you don't need to do the converting process each time. Fixed endian checking logic.
1 parent d3450c1 commit 756d02f

Some content is hidden

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

125 files changed

+6512
-186
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "external/boost/predef"]
2+
path = external/boost/predef
3+
url = https://github.com/boostorg/predef.git

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ IF (MSGPACK_BOOST)
4545
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
4646
ENDIF ()
4747

48+
FILE (GLOB_RECURSE PREDEF_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/*.h)
49+
FOREACH (F ${PREDEF_FILES})
50+
SET(M "Converting ${F}")
51+
MESSAGE(STATUS ${M})
52+
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/${F} CONTENT)
53+
STRING(REPLACE "BOOST_" "MSGPACK_" CONTENT ${CONTENT})
54+
STRING(REPLACE "boost/" "msgpack/" CONTENT ${CONTENT})
55+
FILE (WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/${F} ${CONTENT})
56+
ENDFOREACH ()
57+
4858
FIND_PACKAGE (GTest)
4959
FIND_PACKAGE (ZLIB)
5060
FIND_PACKAGE (Threads)
@@ -100,6 +110,11 @@ LIST (APPEND msgpack_HEADERS
100110
include/msgpack/zone.h
101111
)
102112

113+
FILE (GLOB_RECURSE PREDEF_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/predef/*.h)
114+
115+
LIST (APPEND msgpack_HEADERS ${PREDEF_FILES})
116+
LIST (APPEND msgpack_HEADERS include/msgpack/predef.h)
117+
103118
IF (MSGPACK_ENABLE_CXX)
104119
LIST (APPEND msgpack_HEADERS
105120
include/msgpack.hpp

NOTICE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This product bundles Boost Predef, which is available under a
2+
Boost Software License - Version 1.0. For details, see external/boost/predef,
3+
include/msgpack/predef.h, and include/msgpack/predef/*
4+
5+
---------------------------------------------------------------------------
6+
Boost Software License - Version 1.0 - August 17th, 2003
7+
8+
Permission is hereby granted, free of charge, to any person or organization
9+
obtaining a copy of the software and accompanying documentation covered by
10+
this license (the "Software") to use, reproduce, display, distribute,
11+
execute, and transmit the Software, and to prepare derivative works of the
12+
Software, and to permit third-parties to whom the Software is furnished to
13+
do so, all subject to the following:
14+
15+
The copyright notices in the Software and this entire statement, including
16+
the above license grant, this restriction and the following disclaimer,
17+
must be included in all copies of the Software, in whole or in part, and
18+
all derivative works of the Software, unless such copies or derivative
19+
works are solely in the form of machine-executable object code generated by
20+
a source language processor.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28+
DEALINGS IN THE SOFTWARE.
29+
---------------------------------------------------------------------------

external/boost/predef

Submodule predef added at c14eafa

include/msgpack/pack.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ inline void pack(Stream& s, const T& v)
149149
}
150150

151151

152-
#if defined(__LITTLE_ENDIAN__)
152+
#if MSGPACK_ENDIAN_LITTLE_BYTE
153153
template <typename T>
154154
inline char take8_8(T d) {
155155
return static_cast<char>(reinterpret_cast<uint8_t*>(&d)[0]);
@@ -167,7 +167,7 @@ inline char take8_64(T d) {
167167
return static_cast<char>(reinterpret_cast<uint8_t*>(&d)[0]);
168168
}
169169

170-
#elif defined(__BIG_ENDIAN__)
170+
#elif MSGPACK_ENDIAN_BIG_BYTE
171171

172172
template <typename T>
173173
inline char take8_8(T d) {
@@ -186,6 +186,8 @@ inline char take8_64(T d) {
186186
return static_cast<char>(reinterpret_cast<uint8_t*>(&d)[7]);
187187
}
188188

189+
#else
190+
#error msgpack-c supports only big endian and little endian
189191
#endif
190192

191193
template <typename Stream>

include/msgpack/pack_template.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
* limitations under the License.
1717
*/
1818

19-
#if defined(__LITTLE_ENDIAN__)
19+
#if MSGPACK_ENDIAN_LITTLE_BYTE
2020
#define TAKE8_8(d) ((uint8_t*)&d)[0]
2121
#define TAKE8_16(d) ((uint8_t*)&d)[0]
2222
#define TAKE8_32(d) ((uint8_t*)&d)[0]
2323
#define TAKE8_64(d) ((uint8_t*)&d)[0]
24-
#elif defined(__BIG_ENDIAN__)
24+
#elif MSGPACK_ENDIAN_BIG_BYTE
2525
#define TAKE8_8(d) ((uint8_t*)&d)[0]
2626
#define TAKE8_16(d) ((uint8_t*)&d)[1]
2727
#define TAKE8_32(d) ((uint8_t*)&d)[3]
2828
#define TAKE8_64(d) ((uint8_t*)&d)[7]
29+
#else
30+
#error msgpack-c supports only big endian and little endian
2931
#endif
3032

3133
#ifndef msgpack_pack_inline_func

include/msgpack/predef.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright Rene Rivera 2008-2013
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+
#ifndef MSGPACK_PREDEF_H
9+
#define MSGPACK_PREDEF_H
10+
11+
#include <msgpack/predef/language.h>
12+
#include <msgpack/predef/architecture.h>
13+
#include <msgpack/predef/compiler.h>
14+
#include <msgpack/predef/library.h>
15+
#include <msgpack/predef/os.h>
16+
#include <msgpack/predef/other.h>
17+
#include <msgpack/predef/platform.h>
18+
19+
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright Rene Rivera 2008-2013
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+
#ifndef MSGPACK_PREDEF_ARCHITECTURE_H
9+
#define MSGPACK_PREDEF_ARCHITECTURE_H
10+
11+
#include <msgpack/predef/architecture/alpha.h>
12+
#include <msgpack/predef/architecture/arm.h>
13+
#include <msgpack/predef/architecture/blackfin.h>
14+
#include <msgpack/predef/architecture/convex.h>
15+
#include <msgpack/predef/architecture/ia64.h>
16+
#include <msgpack/predef/architecture/m68k.h>
17+
#include <msgpack/predef/architecture/mips.h>
18+
#include <msgpack/predef/architecture/parisc.h>
19+
#include <msgpack/predef/architecture/ppc.h>
20+
#include <msgpack/predef/architecture/pyramid.h>
21+
#include <msgpack/predef/architecture/rs6k.h>
22+
#include <msgpack/predef/architecture/sparc.h>
23+
#include <msgpack/predef/architecture/superh.h>
24+
#include <msgpack/predef/architecture/sys370.h>
25+
#include <msgpack/predef/architecture/sys390.h>
26+
#include <msgpack/predef/architecture/x86.h>
27+
#include <msgpack/predef/architecture/z.h>
28+
/*#include <msgpack/predef/architecture/.h>*/
29+
30+
#endif
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright Rene Rivera 2008-2013
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+
#ifndef MSGPACK_PREDEF_ARCHITECTURE_ALPHA_H
9+
#define MSGPACK_PREDEF_ARCHITECTURE_ALPHA_H
10+
11+
#include <msgpack/predef/version_number.h>
12+
#include <msgpack/predef/make.h>
13+
14+
/*`
15+
[heading `MSGPACK_ARCH_ALPHA`]
16+
17+
[@http://en.wikipedia.org/wiki/DEC_Alpha DEC Alpha] architecture.
18+
19+
[table
20+
[[__predef_symbol__] [__predef_version__]]
21+
[[`__alpha__`] [__predef_detection__]]
22+
[[`__alpha`] [__predef_detection__]]
23+
[[`_M_ALPHA`] [__predef_detection__]]
24+
25+
[[`__alpha_ev4__`] [4.0.0]]
26+
[[`__alpha_ev5__`] [5.0.0]]
27+
[[`__alpha_ev6__`] [6.0.0]]
28+
]
29+
*/
30+
31+
#define MSGPACK_ARCH_ALPHA MSGPACK_VERSION_NUMBER_NOT_AVAILABLE
32+
33+
#if defined(__alpha__) || defined(__alpha) || \
34+
defined(_M_ALPHA)
35+
# undef MSGPACK_ARCH_ALPHA
36+
# if !defined(MSGPACK_ARCH_ALPHA) && defined(__alpha_ev4__)
37+
# define MSGPACK_ARCH_ALPHA MSGPACK_VERSION_NUMBER(4,0,0)
38+
# endif
39+
# if !defined(MSGPACK_ARCH_ALPHA) && defined(__alpha_ev5__)
40+
# define MSGPACK_ARCH_ALPHA MSGPACK_VERSION_NUMBER(5,0,0)
41+
# endif
42+
# if !defined(MSGPACK_ARCH_ALPHA) && defined(__alpha_ev6__)
43+
# define MSGPACK_ARCH_ALPHA MSGPACK_VERSION_NUMBER(6,0,0)
44+
# endif
45+
# if !defined(MSGPACK_ARCH_ALPHA)
46+
# define MSGPACK_ARCH_ALPHA MSGPACK_VERSION_NUMBER_AVAILABLE
47+
# endif
48+
#endif
49+
50+
#if MSGPACK_ARCH_ALPHA
51+
# define MSGPACK_ARCH_ALPHA_AVAILABLE
52+
#endif
53+
54+
#define MSGPACK_ARCH_ALPHA_NAME "DEC Alpha"
55+
56+
#include <msgpack/predef/detail/test.h>
57+
MSGPACK_PREDEF_DECLARE_TEST(MSGPACK_ARCH_ALPHA,MSGPACK_ARCH_ALPHA_NAME)
58+
59+
60+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright Rene Rivera 2008-2013
3+
Copyright Franz Detro 2014
4+
Copyright (c) Microsoft Corporation 2014
5+
Distributed under the Boost Software License, Version 1.0.
6+
(See accompanying file LICENSE_1_0.txt or copy at
7+
http://www.boost.org/LICENSE_1_0.txt)
8+
*/
9+
10+
#ifndef MSGPACK_PREDEF_ARCHITECTURE_ARM_H
11+
#define MSGPACK_PREDEF_ARCHITECTURE_ARM_H
12+
13+
#include <msgpack/predef/version_number.h>
14+
#include <msgpack/predef/make.h>
15+
16+
/*`
17+
[heading `MSGPACK_ARCH_ARM`]
18+
19+
[@http://en.wikipedia.org/wiki/ARM_architecture ARM] architecture.
20+
21+
[table
22+
[[__predef_symbol__] [__predef_version__]]
23+
24+
[[`__arm__`] [__predef_detection__]]
25+
[[`__arm64`] [__predef_detection__]]
26+
[[`__thumb__`] [__predef_detection__]]
27+
[[`__TARGET_ARCH_ARM`] [__predef_detection__]]
28+
[[`__TARGET_ARCH_THUMB`] [__predef_detection__]]
29+
[[`_M_ARM`] [__predef_detection__]]
30+
31+
[[`__arm64`] [8.0.0]]
32+
[[`__TARGET_ARCH_ARM`] [V.0.0]]
33+
[[`__TARGET_ARCH_THUMB`] [V.0.0]]
34+
[[`_M_ARM`] [V.0.0]]
35+
]
36+
*/
37+
38+
#define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER_NOT_AVAILABLE
39+
40+
#if defined(__arm__) || defined(__arm64) || defined(__thumb__) || \
41+
defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB) || \
42+
defined(_M_ARM)
43+
# undef MSGPACK_ARCH_ARM
44+
# if !defined(MSGPACK_ARCH_ARM) && defined(__arm64)
45+
# define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER(8,0,0)
46+
# endif
47+
# if !defined(MSGPACK_ARCH_ARM) && defined(__TARGET_ARCH_ARM)
48+
# define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER(__TARGET_ARCH_ARM,0,0)
49+
# endif
50+
# if !defined(MSGPACK_ARCH_ARM) && defined(__TARGET_ARCH_THUMB)
51+
# define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER(__TARGET_ARCH_THUMB,0,0)
52+
# endif
53+
# if !defined(MSGPACK_ARCH_ARM) && defined(_M_ARM)
54+
# define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER(_M_ARM,0,0)
55+
# endif
56+
# if !defined(MSGPACK_ARCH_ARM)
57+
# define MSGPACK_ARCH_ARM MSGPACK_VERSION_NUMBER_AVAILABLE
58+
# endif
59+
#endif
60+
61+
#if MSGPACK_ARCH_ARM
62+
# define MSGPACK_ARCH_ARM_AVAILABLE
63+
#endif
64+
65+
#define MSGPACK_ARCH_ARM_NAME "ARM"
66+
67+
#include <msgpack/predef/detail/test.h>
68+
MSGPACK_PREDEF_DECLARE_TEST(MSGPACK_ARCH_ARM,MSGPACK_ARCH_ARM_NAME)
69+
70+
71+
#endif

0 commit comments

Comments
 (0)