From 12b5a6235a712275e8c4815199a24c3a484b41a2 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Wed, 12 Aug 2015 12:53:56 +0900 Subject: [PATCH] Added examples to cmake building process. Set /WX flas that is warnings as errors on MSVC build. Updated linux, osx, msvc build to refer to appropriate boost libraries. --- .travis.yml | 15 +-- CMakeLists.txt | 11 ++- appveyor.yml | 2 +- example/CMakeLists.txt | 3 + example/c/CMakeLists.txt | 32 +++++++ example/c/{simple.c => simple_c.c} | 0 example/c/speed_test_uint32_array.c | 6 +- example/c/speed_test_uint64_array.c | 4 +- example/cpp03/CMakeLists.txt | 107 ++++++++++++++++++++++ example/cpp03/class_intrusive_map.cpp | 80 ++++++++++++++++ example/cpp03/speed_test_nested_array.cpp | 10 +- example/cpp03/stream.cpp | 2 +- example/cpp11/CMakeLists.txt | 28 ++++++ example/cpp11/container.cpp | 4 +- test/CMakeLists.txt | 5 +- 15 files changed, 284 insertions(+), 25 deletions(-) create mode 100644 example/CMakeLists.txt create mode 100644 example/c/CMakeLists.txt rename example/c/{simple.c => simple_c.c} (100%) create mode 100644 example/cpp03/CMakeLists.txt create mode 100644 example/cpp03/class_intrusive_map.cpp create mode 100644 example/cpp11/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 9604ee70..2b6a55b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,12 @@ os: - linux before_install: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm; fi + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm-upper; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi install: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-4.8-multilib g++-4.8-multilib; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.5; fi + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.6; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32gcc1; fi @@ -27,10 +27,13 @@ install: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y bzip2; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-dbg; fi - wget https://googletest.googlecode.com/files/gtest-1.7.0.zip - - wget http://sourceforge.net/projects/boost/files/boost/1.58.0/ - wget http://valgrind.org/downloads/valgrind-3.10.1.tar.bz2 && tar xjf valgrind-3.10.1.tar.bz2 && cd valgrind-3.10.1 && ./configure && make && sudo make install && cd .. - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd .. && wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && sudo mkdir /usr/local/boost && sudo cp -r boost_1_58_0/boost /usr/local/boost/; fi - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd .. && wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && sudo mkdir /usr/local/boost && sudo cp -r boost_1_58_0/boost /usr/local/boost/; fi + + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew unlink boost; fi + - if [ "$BOOST" == "boost" ]; then wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && cd boost_1_58_0 && ./bootstrap.sh && ./b2 --with-timer --with-chrono address-model="$ARCH" > /dev/null && sudo ./b2 --with-timer --with-chrono address-model="$ARCH" install > /dev/null && cd ..; fi + + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd ..; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd ..; fi env: - ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" @@ -43,7 +46,7 @@ env: - ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" before_script: - - export PATH=/usr/local/bin:$PATH && rm -rf install1 + - export PATH=/usr/local/bin:$PATH && rm -rf install matrix: exclude: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f3e5501..7665674f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,10 @@ ENDIF () IF (MSGPACK_BOOST) SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}") + SET (Boost_USE_STATIC_LIBS ON) # only find static libs + SET (Boost_USE_MULTITHREADED ON) + SET (Boost_USE_STATIC_RUNTIME OFF) + FIND_PACKAGE (Boost COMPONENTS chrono timer system) ENDIF () 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) @@ -221,7 +225,6 @@ INCLUDE_DIRECTORIES ( ./ include/ ${CMAKE_CURRENT_BINARY_DIR}/include/ - ${MSGPACK_BOOST_DIR} ) ADD_LIBRARY (msgpack SHARED @@ -253,9 +256,9 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" ST ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE () - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") ENDIF () ENDIF () @@ -267,6 +270,8 @@ IF (NOT DEFINED CMAKE_INSTALL_LIBDIR) SET(CMAKE_INSTALL_LIBDIR lib) ENDIF () +ADD_SUBDIRECTORY (example) + INSTALL (TARGETS msgpack msgpack-static DESTINATION ${CMAKE_INSTALL_LIBDIR}) INSTALL (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX}) IF (NOT MSVC) diff --git a/appveyor.yml b/appveyor.yml index dad30349..969c5337 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,7 +24,7 @@ before_build: build_script: - md build - cd build -- cmake -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 .. +- cmake -DMSGPACK_BOOST=ON -DMSGPACK_BOOST_DIR=C:\Libraries\boost -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 .. - cmake --build . --config Release test_script: diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 00000000..5fa8a3f6 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,3 @@ +ADD_SUBDIRECTORY (c) +ADD_SUBDIRECTORY (cpp03) +ADD_SUBDIRECTORY (cpp11) diff --git a/example/c/CMakeLists.txt b/example/c/CMakeLists.txt new file mode 100644 index 00000000..ab337dba --- /dev/null +++ b/example/c/CMakeLists.txt @@ -0,0 +1,32 @@ +INCLUDE_DIRECTORIES ( + ../include +) + +LIST (APPEND exec_PROGRAMS + lib_buffer_unpack.c + simple_c.c + speed_test_uint32_array.c + speed_test_uint64_array.c + user_buffer_unpack.c +) + +FOREACH (source_file ${exec_PROGRAMS}) + GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + ADD_EXECUTABLE ( + ${source_file_we} + ${source_file} + ) + TARGET_LINK_LIBRARIES (${source_file_we} + msgpack + ) + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -Wno-mismatched-tags -g -O3") + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + ELSE () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") + ENDIF () + ENDIF () +ENDFOREACH () diff --git a/example/c/simple.c b/example/c/simple_c.c similarity index 100% rename from example/c/simple.c rename to example/c/simple_c.c diff --git a/example/c/speed_test_uint32_array.c b/example/c/speed_test_uint32_array.c index 282a53b0..0fca7865 100644 --- a/example/c/speed_test_uint32_array.c +++ b/example/c/speed_test_uint32_array.c @@ -7,14 +7,14 @@ void test() msgpack_packer * pk; size_t upk_pos = 0; msgpack_unpacked msg; - + msgpack_sbuffer_init(&buf); pk = msgpack_packer_new(&buf, msgpack_sbuffer_write); msgpack_pack_array(pk, size); { - int idx = 0; + size_t idx = 0; for (; idx < size; ++idx) msgpack_pack_uint32(pk, 1); } @@ -28,7 +28,7 @@ void test() msgpack_sbuffer_destroy(&buf); } -int main(int argc, char **argv) +int main(void) { int i = 0; for (; i < 10; ++i) test(); diff --git a/example/c/speed_test_uint64_array.c b/example/c/speed_test_uint64_array.c index a6994803..d8598384 100644 --- a/example/c/speed_test_uint64_array.c +++ b/example/c/speed_test_uint64_array.c @@ -15,7 +15,7 @@ void test() msgpack_pack_array(pk, size); { - int idx = 0; + size_t idx = 0; for (; idx < size; ++idx) msgpack_pack_uint64(pk, test_u64); } @@ -29,7 +29,7 @@ void test() msgpack_sbuffer_destroy(&buf); } -int main(int argc, char **argv) +int main(void) { int i = 0; for (; i < 10; ++i) test(); diff --git a/example/cpp03/CMakeLists.txt b/example/cpp03/CMakeLists.txt new file mode 100644 index 00000000..e26e822e --- /dev/null +++ b/example/cpp03/CMakeLists.txt @@ -0,0 +1,107 @@ +LIST (APPEND exec_PROGRAMS + class_intrusive.cpp + class_intrusive_map.cpp + class_non_intrusive.cpp + custom.cpp + enum.cpp + map_based_versionup.cpp + protocol.cpp + protocol_new.cpp + reuse_zone.cpp + simple.cpp +) + +IF (NOT MSVC) + LIST (APPEND with_pthread_PROGRAMS + stream.cpp + ) +ENDIF () + +IF (MSGPACK_BOOST) + IF (NOT MSVC) + LIST (APPEND with_boost_lib_PROGRAMS + speed_test.cpp + speed_test_nested_array.cpp + ) + ENDIF () +ENDIF () + +FOREACH (source_file ${exec_PROGRAMS}) + INCLUDE_DIRECTORIES ( + ../include + ${MSGPACK_BOOST_DIR} + ) + GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + ADD_EXECUTABLE ( + ${source_file_we} + ${source_file} + ) + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3") + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + ELSE () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") + ENDIF () + ENDIF () +ENDFOREACH () + +FOREACH (source_file ${with_pthread_PROGRAMS}) + INCLUDE_DIRECTORIES ( + ../include + ${MSGPACK_BOOST_DIR} + ) + GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + ADD_EXECUTABLE ( + ${source_file_we} + ${source_file} + ) + TARGET_LINK_LIBRARIES (${source_file_we} + pthread + ) + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3 -pthread") + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + ELSE () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") + ENDIF () + ENDIF () +ENDFOREACH () + +FOREACH (source_file ${with_boost_lib_PROGRAMS}) + INCLUDE_DIRECTORIES ( + ../include + ${Boost_INCLUDE_DIRS} + ) + GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + ADD_EXECUTABLE ( + ${source_file_we} + ${source_file} + ) + LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) + TARGET_LINK_LIBRARIES (${source_file_we} + ${Boost_TIMER_LIBRARY} + ${Boost_CHRONO_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ) + IF (NOT MSVC AND NOT APPLE) + TARGET_LINK_LIBRARIES (${source_file_we} + rt + ) + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3") + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + ELSE () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") + ENDIF () + ENDIF () +ENDFOREACH () diff --git a/example/cpp03/class_intrusive_map.cpp b/example/cpp03/class_intrusive_map.cpp new file mode 100644 index 00000000..5b5fef33 --- /dev/null +++ b/example/cpp03/class_intrusive_map.cpp @@ -0,0 +1,80 @@ +// MessagePack for C++ example +// +// Copyright (C) 2015 KONDO Takatoshi +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include +#include +#include +#include + +#include + + +class my_class { +public: + my_class() {} // When you want to convert from msgpack::object to my_class, + // my_class should be default constractible. + my_class(std::string const& name, int age):name_(name), age_(age) {} + + friend bool operator==(my_class const& lhs, my_class const& rhs) { + return lhs.name_ == rhs.name_ && lhs.age_ == rhs.age_; + } + +private: + std::string name_; + int age_; + +public: + MSGPACK_DEFINE(name_, age_); +}; + +void print(std::string const& buf) { + for (std::string::const_iterator it = buf.begin(), end = buf.end(); + it != end; + ++it) { + std::cout + << std::setw(2) + << std::hex + << std::setfill('0') + << (static_cast(*it) & 0xff) + << ' '; + } + std::cout << std::dec << std::endl; +} + +int main() { + { // pack, unpack + my_class my("John Smith", 42); + std::stringstream ss; + msgpack::pack(ss, my); + + print(ss.str()); + + msgpack::unpacked unp; + msgpack::unpack(unp, ss.str().data(), ss.str().size()); + msgpack::object obj = unp.get(); + std::cout << obj << std::endl; + assert(obj.as() == my); + } + { // create object with zone + my_class my("John Smith", 42); + msgpack::zone z; + msgpack::object obj(my, z); + std::cout << obj << std::endl; + assert(obj.as() == my); + } +} diff --git a/example/cpp03/speed_test_nested_array.cpp b/example/cpp03/speed_test_nested_array.cpp index c63249fa..2180f61e 100644 --- a/example/cpp03/speed_test_nested_array.cpp +++ b/example/cpp03/speed_test_nested_array.cpp @@ -29,7 +29,7 @@ template struct vecvec { typedef std::vector::type> type; static void fill(type& v, std::size_t num_of_elems, T const& val) { - for (int elem = 0; elem < num_of_elems; ++elem) { + for (std::size_t elem = 0; elem < num_of_elems; ++elem) { typename vecvec::type child; vecvec::fill(child, num_of_elems, val); v.push_back(child); @@ -41,7 +41,7 @@ template struct vecvec { typedef std::vector type; static void fill(type& v, std::size_t num_of_elems, T const& val) { - for (int elem = 0; elem < num_of_elems; ++elem) { + for (std::size_t elem = 0; elem < num_of_elems; ++elem) { v.push_back(val); } } @@ -50,9 +50,9 @@ struct vecvec { void test_array_of_array() { std::cout << "[TEST][array_of_array]" << std::endl; // setup - int const depth = 16; + int const depth = 4; std::cout << "Setting up array data..." << std::endl; - typename vecvec::type v1; + vecvec::type v1; vecvec::fill(v1, 3, 42); std::cout << "Start packing..." << std::endl; @@ -77,7 +77,7 @@ void test_array_of_array() { std::cout << result << std::endl; } std::cout << "Unpack finished..." << std::endl; - typename vecvec::type v2; + vecvec::type v2; std::cout << "Start converting..." << std::endl; { boost::timer::cpu_timer timer; diff --git a/example/cpp03/stream.cpp b/example/cpp03/stream.cpp index d5913614..415428b9 100644 --- a/example/cpp03/stream.cpp +++ b/example/cpp03/stream.cpp @@ -122,7 +122,7 @@ private: int main(void) { int pair[2]; - pipe(pair); + if (pipe(pair) != 0) return -1; // run server thread Server srv(pair[0]); diff --git a/example/cpp11/CMakeLists.txt b/example/cpp11/CMakeLists.txt new file mode 100644 index 00000000..cdbc7e07 --- /dev/null +++ b/example/cpp11/CMakeLists.txt @@ -0,0 +1,28 @@ +IF (MSGPACK_CXX11) + INCLUDE_DIRECTORIES ( + ../include + ) + + LIST (APPEND exec_PROGRAMS + container.cpp + non_def_con_class.cpp + ) + + FOREACH (source_file ${exec_PROGRAMS}) + GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + ADD_EXECUTABLE ( + ${source_file_we} + ${source_file} + ) + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3") + ENDIF () + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + ELSE () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX") + ENDIF () + ENDIF () + ENDFOREACH () +ENDIF () diff --git a/example/cpp11/container.cpp b/example/cpp11/container.cpp index d3006309..770b9996 100644 --- a/example/cpp11/container.cpp +++ b/example/cpp11/container.cpp @@ -29,7 +29,7 @@ #include void array() { - std::array a { 1, 2, 3, 4, 5 }; + std::array a { { 1, 2, 3, 4, 5 } }; std::stringstream ss; msgpack::pack(ss, a); @@ -77,7 +77,7 @@ void forward_list() { } void combi() { - std::array a { 1, 2, 3, 4, 5 }; + std::array a { { 1, 2, 3, 4, 5 } }; std::tuple t {true, "ABC", 42}; std::unordered_map m { {"ABC", 1}, {"DEF", 3} }; std::unordered_set s { "ABC", "DEF" }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5775fd2a..c05084f0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,6 +5,7 @@ FIND_PACKAGE (Threads REQUIRED) INCLUDE_DIRECTORIES ( ${GTEST_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} + ${MSGPACK_BOOST_DIR} ) LIST (APPEND check_PROGRAMS @@ -69,8 +70,8 @@ FOREACH (source_file ${check_PROGRAMS}) SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -Wno-mismatched-tags -g -O3") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4] /WX") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE () SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") ENDIF ()