From 97471106fffbb3a1e4947010aa5fee96e8199238 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 19:23:36 -0300 Subject: [PATCH 1/7] Move project() to main CMakeLists.txt file --- CMakeLists.txt | 1 + msgpack/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad9937a..ebaf8c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,4 @@ cmake_minimum_required(VERSION 3.9) +project(Msgpack LANGUAGES CXX VERSION 1.0) add_subdirectory(msgpack) \ No newline at end of file diff --git a/msgpack/CMakeLists.txt b/msgpack/CMakeLists.txt index 4bee2bc..5a05cc0 100644 --- a/msgpack/CMakeLists.txt +++ b/msgpack/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.9) -project(Msgpack LANGUAGES CXX VERSION 1.0) list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake) From ef04804852f9e7424d52dca8d0a5491ae39c87c8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 19:24:09 -0300 Subject: [PATCH 2/7] Add CPPACK_TESTS option to avoid compiling tests --- CMakeLists.txt | 2 ++ msgpack/CMakeLists.txt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebaf8c4..53b7fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.9) project(Msgpack LANGUAGES CXX VERSION 1.0) +option(CPPACK_TESTS "Enable cppack tests" ON) + add_subdirectory(msgpack) \ No newline at end of file diff --git a/msgpack/CMakeLists.txt b/msgpack/CMakeLists.txt index 5a05cc0..077168a 100644 --- a/msgpack/CMakeLists.txt +++ b/msgpack/CMakeLists.txt @@ -48,4 +48,6 @@ install(FILES export(EXPORT MsgpackTargets FILE ${CMAKE_CURRENT_BINARY_DIR}/MsgpackTargets.cmake NAMESPACE Msgpack::) export(PACKAGE Msgpack) -add_subdirectory(tests) \ No newline at end of file +if(CPPACK_TESTS) + add_subdirectory(tests) +endif() \ No newline at end of file From 0db6cafa1f2ea8ada32d50eccc18db3f69a94376 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 19:55:53 -0300 Subject: [PATCH 3/7] Add missing header files --- msgpack/include/msgpack/msgpack.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msgpack/include/msgpack/msgpack.hpp b/msgpack/include/msgpack/msgpack.hpp index a300d5d..1766538 100644 --- a/msgpack/include/msgpack/msgpack.hpp +++ b/msgpack/include/msgpack/msgpack.hpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace msgpack { enum class UnpackerError { From 2472865ad4cf71dd043650a137f9e7516d48147b Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 19:26:44 -0300 Subject: [PATCH 4/7] Get Catch2 library using FetchContent --- msgpack/tests/CMakeLists.txt | 9 ++++++--- msgpack/tests/error_handling.cpp | 2 +- msgpack/tests/examples.cpp | 2 +- msgpack/tests/main.cpp | 7 ------- msgpack/tests/object_packing_tests.cpp | 2 +- msgpack/tests/type_packing_tests.cpp | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 msgpack/tests/main.cpp diff --git a/msgpack/tests/CMakeLists.txt b/msgpack/tests/CMakeLists.txt index a9725f2..1286063 100644 --- a/msgpack/tests/CMakeLists.txt +++ b/msgpack/tests/CMakeLists.txt @@ -1,9 +1,12 @@ cmake_minimum_required(VERSION 3.9) -find_package(Catch2 REQUIRED) +include(FetchContent) +FetchContent_Declare(Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.1.0) +FetchContent_MakeAvailable(Catch2) add_executable(Msgpack_tests - main.cpp type_packing_tests.cpp examples.cpp error_handling.cpp @@ -17,7 +20,7 @@ else (MSVC) endif (MSVC) target_link_libraries(Msgpack_tests - Catch2::Catch2 + Catch2::Catch2WithMain Msgpack::Msgpack) set_target_properties(Msgpack_tests PROPERTIES CXX_STANDARD 17) diff --git a/msgpack/tests/error_handling.cpp b/msgpack/tests/error_handling.cpp index 197b3cf..99dda61 100644 --- a/msgpack/tests/error_handling.cpp +++ b/msgpack/tests/error_handling.cpp @@ -2,7 +2,7 @@ // Created by Mike Loomis on 6/29/2019. // -#include +#include #include "msgpack/msgpack.hpp" diff --git a/msgpack/tests/examples.cpp b/msgpack/tests/examples.cpp index 6519c67..d7e768a 100644 --- a/msgpack/tests/examples.cpp +++ b/msgpack/tests/examples.cpp @@ -2,7 +2,7 @@ // Created by Mike Loomis on 6/28/2019. // -#include +#include #include "msgpack/msgpack.hpp" diff --git a/msgpack/tests/main.cpp b/msgpack/tests/main.cpp deleted file mode 100644 index 9673894..0000000 --- a/msgpack/tests/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// -// Created by Mike Loomis on 6/22/2019. -// - -#define CATCH_CONFIG_MAIN - -#include diff --git a/msgpack/tests/object_packing_tests.cpp b/msgpack/tests/object_packing_tests.cpp index 6dfb391..50f2399 100644 --- a/msgpack/tests/object_packing_tests.cpp +++ b/msgpack/tests/object_packing_tests.cpp @@ -2,7 +2,7 @@ // Created by Mike Loomis on 7/31/2019. // -#include +#include #include diff --git a/msgpack/tests/type_packing_tests.cpp b/msgpack/tests/type_packing_tests.cpp index a80f21a..02e9b15 100644 --- a/msgpack/tests/type_packing_tests.cpp +++ b/msgpack/tests/type_packing_tests.cpp @@ -2,7 +2,7 @@ // Created by Mike Loomis on 6/22/2019. // -#include +#include #include From 2f8bffe7a031082fcf83ff19d56970ae2a06c501 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 19:28:12 -0300 Subject: [PATCH 5/7] Replace Travis CI with GitHub Actions --- .github/workflows/build.yml | 35 +++++++++++++++++++++++++++++++++++ .travis.yml | 25 ------------------------- README.md | 2 +- 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9491454 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,35 @@ +name: build +on: [push] +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, macos-latest, ubuntu-latest] + build_type: [debug,release] + sanitizer: [""] + include: + - os: macos-latest + build_type: debug + sanitizer: "-fsanitize=address" + steps: + - uses: actions/checkout@v2 + - uses: seanmiddleditch/gha-setup-ninja@master + - uses: ilammy/msvc-dev-cmd@v1 + if: runner.os == 'Windows' + - name: Generating Makefiles + shell: bash + run: | + cmake . -G Ninja \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DCMAKE_CXX_FLAGS=${{ matrix.sanitizer }} \ + -DCMAKE_EXE_LINKER_FLAGS=${{ matrix.sanitizer }} + - name: Compiling + shell: bash + run: | + ninja + - name: Running Tests + shell: bash + run: | + msgpack/tests/Msgpack_tests diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c640340..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -dist: xenial -sudo: true -language: cpp - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-7 - -matrix: - include: - - os: linux - before_install: - - git clone https://github.com/catchorg/Catch2.git - - cd Catch2 - - cmake -Bbuild -H. -DBUILD_TESTING=OFF - - sudo env "PATH=$PATH" cmake --build build/ --target install - - cd .. - -script: - - CXX=/usr/bin/g++-7 CC=/usr/bin/gcc-7 cmake . - - cmake --build . -- -j2 - - ./msgpack/tests/Msgpack_tests \ No newline at end of file diff --git a/README.md b/README.md index 1615eb2..7983945 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/mikeloomisgg/cppack.svg?branch=master)](https://travis-ci.com/mikeloomisgg/cppack) +[![build](https://github.com/dacap/cppack/actions/workflows/build.yml/badge.svg)](https://github.com/dacap/cppack/actions/workflows/build.yml) # cppack A modern (c++17 required) implementation of the [msgpack spec](https://github.com/msgpack/msgpack/blob/master/spec.md). From 515ad0ca048629a4f2b3970fdb4d34360b16603d Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 20:01:37 -0300 Subject: [PATCH 6/7] Enable C++ exception handling on MSVC --- msgpack/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msgpack/tests/CMakeLists.txt b/msgpack/tests/CMakeLists.txt index 1286063..d0b6b78 100644 --- a/msgpack/tests/CMakeLists.txt +++ b/msgpack/tests/CMakeLists.txt @@ -14,7 +14,7 @@ add_executable(Msgpack_tests ) if (MSVC) - target_compile_options(Msgpack_tests PRIVATE /WX /Zc:__cplusplus) + target_compile_options(Msgpack_tests PRIVATE /WX /Zc:__cplusplus /EHsc) else (MSVC) target_compile_options(Msgpack_tests PRIVATE -Wall -Wextra -pedantic -Werror) endif (MSVC) From ea0d3c4da326d4db84579f07f9758d2ff025cdda Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2022 20:18:23 -0300 Subject: [PATCH 7/7] Make UnpackerErrCategory an unique category This is a problem in Release compilation where the theUnpackerErrCategory variable is optimized and created on each compilation unit, and then the error_handling.cpp test fails in: REQUIRE(ec == msgpack::UnpackerError::OutOfRange); Because the category is different on each compilation unit. --- msgpack/include/msgpack/msgpack.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msgpack/include/msgpack/msgpack.hpp b/msgpack/include/msgpack/msgpack.hpp index 1766538..284ebdf 100644 --- a/msgpack/include/msgpack/msgpack.hpp +++ b/msgpack/include/msgpack/msgpack.hpp @@ -35,12 +35,12 @@ struct UnpackerErrCategory : public std::error_category { return "(unrecognized error)"; } }; -}; -const UnpackerErrCategory theUnpackerErrCategory{}; +}; inline std::error_code make_error_code(msgpack::UnpackerError e) { + static UnpackerErrCategory theUnpackerErrCategory; return {static_cast(e), theUnpackerErrCategory}; } }