From b8882652fcbeba4c00dec019a39da91e702e474e Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 28 Jun 2023 10:37:09 -0600 Subject: [PATCH 01/32] Add namespace for the exported targets (#1196) This matches the name for the ALIAS targets, and fixes #1025. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef6e8a30..0c5375865 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,7 @@ if (YAML_CPP_INSTALL) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") install(EXPORT yaml-cpp-targets + NAMESPACE yaml-cpp:: DESTINATION "${CONFIG_EXPORT_DIR}") install(FILES "${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" From 35b4498026b6293bfadc75f9ee325cb16d6975af Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 25 Jul 2023 03:51:05 +0800 Subject: [PATCH 02/32] node/convert: support conversion for std::string_view (#1148) --- include/yaml-cpp/node/convert.h | 18 ++++++++++++++++++ test/node/node_test.cpp | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 292c5d3c0..d0eb450f7 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -18,6 +18,10 @@ #include #include +#if __cplusplus >= 201703L +#include +#endif + #include "yaml-cpp/binary.h" #include "yaml-cpp/node/impl.h" #include "yaml-cpp/node/iterator.h" @@ -89,6 +93,20 @@ struct convert { static Node encode(const char* rhs) { return Node(rhs); } }; +#if __cplusplus >= 201703L +template <> +struct convert { + static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } + + static bool decode(const Node& node, std::string_view& rhs) { + if (!node.IsScalar()) + return false; + rhs = node.Scalar(); + return true; + } +}; +#endif + template <> struct convert<_Null> { static Node encode(const _Null& /* rhs */) { return Node(); } diff --git a/test/node/node_test.cpp b/test/node/node_test.cpp index ff3d799e3..5f41ef255 100644 --- a/test/node/node_test.cpp +++ b/test/node/node_test.cpp @@ -356,6 +356,15 @@ TEST(NodeTest, ConstInteratorOnSequence) { EXPECT_EQ(3, count); } +#if __cplusplus >= 201703L +TEST(NodeTest, StdStringViewAsKey) { + Node node; + std::string_view key = "username"; + node[key] = "monkey"; + EXPECT_EQ("monkey", node[key].as()); +} +#endif + TEST(NodeTest, SimpleSubkeys) { Node node; node["device"]["udid"] = "12345"; From f6c8b17c3a89766e8fdada53abdea2e56b487634 Mon Sep 17 00:00:00 2001 From: Diogo Teles Sant'Anna Date: Thu, 10 Aug 2023 16:02:27 -0300 Subject: [PATCH 03/32] Create Security-Policy (#1189) --- SECURITY.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..06a17511b --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +Security updates are applied only to the latest release. + +## Reporting a Vulnerability + +If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. + +Please disclose it at [security advisory](https://github.com/jbeder/yaml-cpp/security/advisories/new). + +This project is maintained by a team of volunteers on a reasonable-effort basis. As such, vulnerabilities will be disclosed in a best effort base. From f7320141120f720aecc4c32be25586e7da9eb978 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 10 Aug 2023 14:27:56 -0500 Subject: [PATCH 04/32] Bump version to 0.8.0. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c5375865..46dc18059 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ if(POLICY CMP0091) cmake_policy(SET CMP0091 NEW) endif() -project(YAML_CPP VERSION 0.7.0 LANGUAGES CXX) +project(YAML_CPP VERSION 0.8.0 LANGUAGES CXX) set(YAML_CPP_MAIN_PROJECT OFF) if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) From c2680200486572baf8221ba052ef50b58ecd816e Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Thu, 17 Aug 2023 08:54:05 +1000 Subject: [PATCH 05/32] Specify CMake policy range to avoid deprecation warning (#1211) --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46dc18059..1ae92e2b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ -# 3.5 is actually available almost everywhere, but this a good minimum -cmake_minimum_required(VERSION 3.4) +# 3.5 is actually available almost everywhere, but this a good minimum. +# 3.14 as the upper policy limit avoids CMake deprecation warnings. +cmake_minimum_required(VERSION 3.4...3.14) # enable MSVC_RUNTIME_LIBRARY target property # see https://cmake.org/cmake/help/latest/policy/CMP0091.html From fcbb8193b94921e058be7b563aea053531e5b2d9 Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Sat, 19 Aug 2023 21:36:16 +0200 Subject: [PATCH 06/32] Fix testsuite with gcc-13 (#1216) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cd /<>/build-static/test && /usr/bin/c++ -DYAML_CPP_STATIC_DEFINE -I/<>/test/integration -I/<>/test -I/<>/src -I/<>/include -isystem /usr/src/googletest/googlemock/include -isystem /usr/src/googletest/googlemock -isystem /usr/src/googletest/googletest/include -isystem /usr/src/googletest/googletest -g -O2 -ffile-prefix-map=/<>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fdebug-prefix-map=/<>=/usr/src/yaml-cpp-0.8.0+dfsg-1~build1 -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++14 -Wno-variadic-macros -Wno-sign-compare -DGTEST_HAS_PTHREAD=1 -MD -MT test/CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o -MF CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o.d -o CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o -c /<>/test/binary_test.cpp /<>/test/binary_test.cpp: In member function ‘virtual void BinaryTest_DecodingNoCrashOnNegative_Test::TestBody()’: /<>/test/binary_test.cpp:11:38: error: narrowing conversion of ‘-58’ from ‘int’ to ‘char’ [-Wnarrowing] 11 | std::string input{-58, -1, -99, 109}; | ^ --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 351b03f81..c9e7f041b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,7 +33,7 @@ target_include_directories(yaml-cpp-tests target_compile_options(yaml-cpp-tests PRIVATE $<$:-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare> - $<$:-Wno-variadic-macros -Wno-sign-compare>) + $<$:-Wno-variadic-macros -Wno-sign-compare -Wno-narrowing>) target_link_libraries(yaml-cpp-tests PRIVATE Threads::Threads From 6262201182a0ee357d8a456e6d1a8e5984e4c6dd Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 6 Sep 2023 20:57:12 +0800 Subject: [PATCH 07/32] node/convert: relax the check for string_view (#1222) --- include/yaml-cpp/node/convert.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index d0eb450f7..9dea37059 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -17,8 +17,9 @@ #include #include #include +#include -#if __cplusplus >= 201703L +#ifdef __cpp_lib_string_view #include #endif @@ -93,7 +94,7 @@ struct convert { static Node encode(const char* rhs) { return Node(rhs); } }; -#if __cplusplus >= 201703L +#ifdef __cpp_lib_string_view template <> struct convert { static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } From 2383e6d0f29c95587bf49890af10f0b8557a8cd1 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 10 Sep 2023 20:28:52 +0800 Subject: [PATCH 08/32] Revert "node/convert: relax the check for string_view (#1222)" (#1225) This reverts commit 6262201182a0ee357d8a456e6d1a8e5984e4c6dd. in 62622011, we wanted address the needs to use the `string_view` converter in C++98, but that requirement was based on wrong preconditions. `std::string_view` was introduced in C++17, and popular standard libraries like libstdc++ and libc++ both provide `std::string_view` when the source is built with C++17. furthermore 62622011 is buggy. because it uses `` to tell the feature set provided by the standard library. but `` is a part of C++20. so this defeats the purpose of the change of 62622011. Fixes #1223 --- include/yaml-cpp/node/convert.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 9dea37059..d0eb450f7 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -17,9 +17,8 @@ #include #include #include -#include -#ifdef __cpp_lib_string_view +#if __cplusplus >= 201703L #include #endif @@ -94,7 +93,7 @@ struct convert { static Node encode(const char* rhs) { return Node(rhs); } }; -#ifdef __cpp_lib_string_view +#if __cplusplus >= 201703L template <> struct convert { static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } From 016b2e77691c5578f90e35d772fea80540f2b30e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 10 Sep 2023 20:38:51 +0800 Subject: [PATCH 09/32] CI: test with supported C++ standards (#1226) * CI: test with supported C++ standards let's test with the supported standards for better coverage. C++23 standard was just out, but the support on the toolchain is not quite ready yet. so let's leave it for a future change. Signed-off-by: Kefu Chai * CI: drop redundant Build step "Build Tests" is strictly a superset of "Build". in addition to the library, the former builds the tests also. both these steps share the same set of command line arguments. by removing "Build" step, we don't lose anything regarding the test coverage and information for further investigation if the build fails. Signed-off-by: Kefu Chai --------- Signed-off-by: Kefu Chai --- .github/workflows/build.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a408a9dfe..ea824c94d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] + cxx_standard: [11, 17, 20] build: [static, shared] generator: ["Default Generator", "MinGW Makefiles"] exclude: @@ -23,7 +24,6 @@ jobs: generator: "MinGW Makefiles" env: YAML_BUILD_SHARED_LIBS: ${{ matrix.build == 'shared' && 'ON' || 'OFF' }} - YAML_CPP_BUILD_TESTS: 'ON' CMAKE_GENERATOR: >- ${{format(matrix.generator != 'Default Generator' && '-G "{0}"' || '', matrix.generator)}} runs-on: ${{ matrix.os }} @@ -33,16 +33,10 @@ jobs: - name: Get number of CPU cores uses: SimenB/github-actions-cpu-cores@v1 - - name: Build - shell: bash - run: | - cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} - cd build && cmake --build . --parallel ${{ steps.cpu-cores.outputs.count }} - - name: Build Tests shell: bash run: | - cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} -DYAML_CPP_BUILD_TESTS=${{ env.YAML_CPP_BUILD_TESTS }} + cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} -DYAML_CPP_BUILD_TESTS=ON cd build && cmake --build . --parallel ${{ steps.cpu-cores.outputs.count }} - name: Run Tests From 9f31491b0fceb506fa5d4d1ec3b5e942483adbe7 Mon Sep 17 00:00:00 2001 From: Daniel Stonier Date: Sun, 17 Sep 2023 11:57:52 -0400 Subject: [PATCH 10/32] bzlmodded (#1224) --- .bazelignore | 1 + .github/workflows/build.yml | 19 +++++++++++++++++++ MODULE.bazel | 14 ++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 .bazelignore create mode 100644 MODULE.bazel diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 000000000..51b34029a --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +test/gtest-1.11.0 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea824c94d..f3fc2dd7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,3 +64,22 @@ jobs: cd "${{ github.workspace }}" bazel test test + bzlmod-build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + + - name: Build + shell: bash + run: | + cd "${{ github.workspace }}" + bazel build --enable_bzlmod :all + + - name: Test + shell: bash + run: | + cd "${{ github.workspace }}" + bazel test --enable_bzlmod test diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..7119060bf --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,14 @@ +""" +yaml-cpp is a YAML parser and emitter in c++ matching the YAML specification. +""" + +module( + name = "yaml-cpp", + compatibility_level = 1, + version = "0.8.0", +) + +bazel_dep(name = "platforms", version = "0.0.7") +bazel_dep(name = "rules_cc", version = "0.0.8") + +bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True) From d046eea3313f25ee20d1cfc5dc9a107bab35af96 Mon Sep 17 00:00:00 2001 From: FireWolf <10460478+0xFireWolf@users.noreply.github.com> Date: Sun, 17 Sep 2023 08:58:31 -0700 Subject: [PATCH 11/32] node/convert: Enable the template specialization for `std::string_view` properly when the library is compiled by MSVC on Windows. (#1227) --- include/yaml-cpp/node/convert.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index d0eb450f7..d49702f82 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -18,7 +18,7 @@ #include #include -#if __cplusplus >= 201703L +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) #include #endif @@ -93,7 +93,7 @@ struct convert { static Node encode(const char* rhs) { return Node(rhs); } }; -#if __cplusplus >= 201703L +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) template <> struct convert { static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } From 37f1b8b8c9e5172ff3a79a3d5fdbb87f2994842b Mon Sep 17 00:00:00 2001 From: Paul Jurczak Date: Thu, 21 Sep 2023 13:38:56 -0700 Subject: [PATCH 12/32] Update How-To-Emit-YAML.md (#976) --- docs/How-To-Emit-YAML.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/How-To-Emit-YAML.md b/docs/How-To-Emit-YAML.md index 934070199..f28fcbe0e 100644 --- a/docs/How-To-Emit-YAML.md +++ b/docs/How-To-Emit-YAML.md @@ -155,15 +155,9 @@ produces We overload `operator <<` for `std::vector`, `std::list`, and `std::map`, so you can write stuff like: ```cpp -std::vector squares; -squares.push_back(1); -squares.push_back(4); -squares.push_back(9); -squares.push_back(16); +std::vector squares = {1, 4, 9, 16}; -std::map ages; -ages["Daniel"] = 26; -ages["Jesse"] = 24; +std::map ages = {{"Daniel", 26}, {"Jesse", 24}}; YAML::Emitter out; out << YAML::BeginSeq; @@ -227,4 +221,4 @@ assert(out.good()); out << YAML::Key; assert(!out.good()); std::cout << "Emitter error: " << out.GetLastError() << "\n"; -``` \ No newline at end of file +``` From 4c061a5058721795b6851b593b09bac7763b92c8 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Oct 2023 10:40:09 +0700 Subject: [PATCH 13/32] Disable `format` target when not building as the main project (#1231) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ae92e2b7..82eec7b6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,14 +25,14 @@ option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON) option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON) option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS}) option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT}) -option(YAML_CPP_FORMAT_SOURCE "Format source" ON) +option(YAML_CPP_FORMAT_SOURCE "Format source" ${YAML_CPP_MAIN_PROJECT}) cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" OFF "BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF) cmake_dependent_option(YAML_MSVC_SHARED_RT "MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON "CMAKE_SYSTEM_NAME MATCHES Windows" OFF) - + if (YAML_CPP_FORMAT_SOURCE) find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format) endif() From ac144ed46cbc7e93a953ed08c6fbb5edad4f79b1 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 11 Oct 2023 06:02:33 +0200 Subject: [PATCH 14/32] Hide uninstall target unless YAML_CPP_INSTALL is set, and allow it to be disabled by YAML_CPP_DISABLE_UNINSTALL add_custom_target uninstall causes a clash with the same target in rtmidi (https://github.com/thestk/rtmidi). "add_custom_target cannot create target "uninstall" because another target with the same name already exists. The existing target is a custom target created in source directory" Adds new option YAML_CPP_DISABLE_UNINSTALL fixes #1151 --------- Co-authored-by: Megamouse Co-authored-by: Jesse Beder --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82eec7b6b..b13e77fa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON) option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS}) option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT}) option(YAML_CPP_FORMAT_SOURCE "Format source" ${YAML_CPP_MAIN_PROJECT}) +option(YAML_CPP_DISABLE_UNINSTALL "Disable uninstallation of yaml-cpp" OFF) + cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" OFF "BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF) @@ -197,7 +199,7 @@ if (YAML_CPP_FORMAT_SOURCE AND YAML_CPP_CLANG_FORMAT_EXE) endif() # uninstall target -if(NOT TARGET uninstall) +if(YAML_CPP_INSTALL AND NOT YAML_CPP_DISABLE_UNINSTALL AND NOT TARGET uninstall) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" From c26e047223248dfa1d4bafe228437bc1397751a6 Mon Sep 17 00:00:00 2001 From: Pierre Wendling <50808272+FtZPetruska@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:48:16 +0200 Subject: [PATCH 15/32] CMake: Fixes for generated config (#1212) * CMake: Add option to set the package install dir. * CMake: Fix generated config. - `YAML_CPP_SHARED_LIBS_BUILT` should not be set with a `PATH_VAR` as it would always evaluate to true. - `YAML_CPP_LIBRARIES` should used the exported target name including the namespace, but `check_required_components` shouldn't. - Use `CMAKE_CURRENT_LIST_DIR` to find the target file, instead of a `PATH_VAR`. Package managers such as vcpkg move CMake configs after installing. * CI: Test the generated CMake package. * CMake: Create add a deprecated yaml-cpp target. This target is meant to provide compatibility with versions prior to 0.8.0. * CMake: mark the yaml-cpp target as IMPORTED. --------- Co-authored-by: Jesse Beder --- .github/workflows/build.yml | 59 ++++++++++++++++++++++++++++++------- CMakeLists.txt | 16 +++++----- test/cmake/CMakeLists.txt | 19 ++++++++++++ test/cmake/main.cpp | 3 ++ yaml-cpp-config.cmake.in | 14 +++++++-- 5 files changed, 89 insertions(+), 22 deletions(-) create mode 100644 test/cmake/CMakeLists.txt create mode 100644 test/cmake/main.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3fc2dd7a..78b2956d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,9 @@ on: branches: [ master ] workflow_dispatch: permissions: read-all +defaults: + run: + shell: bash jobs: cmake-build: strategy: @@ -26,23 +29,59 @@ jobs: YAML_BUILD_SHARED_LIBS: ${{ matrix.build == 'shared' && 'ON' || 'OFF' }} CMAKE_GENERATOR: >- ${{format(matrix.generator != 'Default Generator' && '-G "{0}"' || '', matrix.generator)}} + CMAKE_INSTALL_PREFIX: "${{ github.workspace }}/install-prefix" + CMAKE_BUILD_TYPE: Debug runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v1 + - name: Configure + run: | + cmake \ + ${{ env.CMAKE_GENERATOR }} \ + -S "${{ github.workspace }}" \ + -B build \ + -D CMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} \ + -D CMAKE_INSTALL_PREFIX="${{ env.CMAKE_INSTALL_PREFIX }}" \ + -D CMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ + -D YAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} \ + -D YAML_CPP_BUILD_TESTS=ON - - name: Build Tests - shell: bash + - name: Build run: | - cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} -DYAML_CPP_BUILD_TESTS=ON - cd build && cmake --build . --parallel ${{ steps.cpu-cores.outputs.count }} + cmake \ + --build build \ + --config ${{ env.CMAKE_BUILD_TYPE }} \ + --verbose \ + --parallel - name: Run Tests shell: bash run: | - cd build && ctest -C Debug --output-on-failure --verbose + ctest \ + --test-dir build \ + --build-config ${{ env.CMAKE_BUILD_TYPE }} \ + --output-on-failure \ + --verbose + + - name: Install + run: cmake --install build --config ${{ env.CMAKE_BUILD_TYPE }} + + - name: Configure CMake package test + run: | + cmake \ + ${{ env.CMAKE_GENERATOR }} \ + -S "${{ github.workspace }}/test/cmake" \ + -B consumer-build \ + -D CMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ + -D CMAKE_PREFIX_PATH="${{ env.CMAKE_INSTALL_PREFIX }}" + + - name: Build CMake package test + run: | + cmake \ + --build consumer-build \ + --config ${{ env.CMAKE_BUILD_TYPE }} \ + --verbose bazel-build: strategy: @@ -50,16 +89,14 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Build - shell: bash run: | cd "${{ github.workspace }}" bazel build :all - name: Test - shell: bash run: | cd "${{ github.workspace }}" bazel test test diff --git a/CMakeLists.txt b/CMakeLists.txt index b13e77fa7..d152fd5c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,9 @@ cmake_dependent_option(YAML_CPP_BUILD_TESTS cmake_dependent_option(YAML_MSVC_SHARED_RT "MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON "CMAKE_SYSTEM_NAME MATCHES Windows" OFF) - +set(YAML_CPP_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/yaml-cpp" + CACHE STRING "Path to install the CMake package to") + if (YAML_CPP_FORMAT_SOURCE) find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format) endif() @@ -146,13 +148,12 @@ set_target_properties(yaml-cpp PROPERTIES PROJECT_LABEL "yaml-cpp ${yaml-cpp-label-postfix}" DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") -set(CONFIG_EXPORT_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/yaml-cpp") -set(EXPORT_TARGETS yaml-cpp) +set(EXPORT_TARGETS yaml-cpp::yaml-cpp) configure_package_config_file( "${PROJECT_SOURCE_DIR}/yaml-cpp-config.cmake.in" "${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" - INSTALL_DESTINATION "${CONFIG_EXPORT_DIR}" - PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR CONFIG_EXPORT_DIR YAML_BUILD_SHARED_LIBS) + INSTALL_DESTINATION "${YAML_CPP_INSTALL_CMAKEDIR}" + PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR) unset(EXPORT_TARGETS) write_basic_package_version_file( @@ -172,15 +173,14 @@ if (YAML_CPP_INSTALL) FILES_MATCHING PATTERN "*.h") install(EXPORT yaml-cpp-targets NAMESPACE yaml-cpp:: - DESTINATION "${CONFIG_EXPORT_DIR}") + DESTINATION "${YAML_CPP_INSTALL_CMAKEDIR}") install(FILES "${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" "${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake" - DESTINATION "${CONFIG_EXPORT_DIR}") + DESTINATION "${YAML_CPP_INSTALL_CMAKEDIR}") install(FILES "${PROJECT_BINARY_DIR}/yaml-cpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() -unset(CONFIG_EXPORT_DIR) if(YAML_CPP_BUILD_TESTS) add_subdirectory(test) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt new file mode 100644 index 000000000..19a7910ae --- /dev/null +++ b/test/cmake/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.5) +project(yaml-cpp-consumer LANGUAGES CXX) + +find_package(yaml-cpp CONFIG REQUIRED) +get_target_property(LIBRARY_TYPE yaml-cpp::yaml-cpp TYPE) + +if(LIBRARY_TYPE STREQUAL "SHARED_LIBRARY") + if(NOT YAML_CPP_SHARED_LIBS_BUILT) + message(FATAL_ERROR "Library type (${LIBRARY_TYPE}) contradicts config: ${YAML_CPP_SHARED_LIBS_BUILT}") + endif() +else() + if(YAML_CPP_SHARED_LIBS_BUILT) + message(FATAL_ERROR "Library type (${LIBRARY_TYPE}) contradicts config: ${YAML_CPP_SHARED_LIBS_BUILT}") + endif() +endif() + +add_executable(main main.cpp) +set_target_properties(main PROPERTIES CXX_STANDARD 11) +target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES}) diff --git a/test/cmake/main.cpp b/test/cmake/main.cpp new file mode 100644 index 000000000..bce9ea62c --- /dev/null +++ b/test/cmake/main.cpp @@ -0,0 +1,3 @@ +#include "yaml-cpp/yaml.h" + +int main(int, char**) { YAML::Parser foo{}; } diff --git a/yaml-cpp-config.cmake.in b/yaml-cpp-config.cmake.in index 799b9b418..f71e13b8f 100644 --- a/yaml-cpp-config.cmake.in +++ b/yaml-cpp-config.cmake.in @@ -11,12 +11,20 @@ set_and_check(YAML_CPP_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") set_and_check(YAML_CPP_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@") # Are we building shared libraries? -set(YAML_CPP_SHARED_LIBS_BUILT "@PACKAGE_YAML_BUILD_SHARED_LIBS@") +set(YAML_CPP_SHARED_LIBS_BUILT @YAML_BUILD_SHARED_LIBS@) # Our library dependencies (contains definitions for IMPORTED targets) -include(@PACKAGE_CONFIG_EXPORT_DIR@/yaml-cpp-targets.cmake) +include("${CMAKE_CURRENT_LIST_DIR}/yaml-cpp-targets.cmake") # These are IMPORTED targets created by yaml-cpp-targets.cmake set(YAML_CPP_LIBRARIES "@EXPORT_TARGETS@") -check_required_components(@EXPORT_TARGETS@) +add_library(yaml-cpp INTERFACE IMPORTED) +target_link_libraries(yaml-cpp INTERFACE yaml-cpp::yaml-cpp) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + set_target_properties(yaml-cpp PROPERTIES + DEPRECATION "The target yaml-cpp is deprecated and will be removed in version 0.10.0. Use the yaml-cpp::yaml-cpp target instead." + ) +endif() + +check_required_components(yaml-cpp) From 8106fcf1e52efeef054bc7f84a40bd345c357a83 Mon Sep 17 00:00:00 2001 From: Pete Lewis Date: Thu, 12 Oct 2023 08:49:34 -0700 Subject: [PATCH 16/32] Resolve warnings about unreferenced parameter 'style' in NullEventHandlers (#1193) --- util/read.cpp | 4 ++-- util/sandbox.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/read.cpp b/util/read.cpp index 3455ea3cf..65e8de999 100644 --- a/util/read.cpp +++ b/util/read.cpp @@ -20,10 +20,10 @@ class NullEventHandler : public YAML::EventHandler { void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) override {} void OnSequenceStart(const Mark&, const std::string&, anchor_t, - YAML::EmitterStyle::value style) override {} + YAML::EmitterStyle::value) override {} void OnSequenceEnd() override {} void OnMapStart(const Mark&, const std::string&, anchor_t, - YAML::EmitterStyle::value style) override {} + YAML::EmitterStyle::value) override {} void OnMapEnd() override {} }; diff --git a/util/sandbox.cpp b/util/sandbox.cpp index f21490e7a..cb39dba06 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -18,10 +18,10 @@ class NullEventHandler : public YAML::EventHandler { void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) override {} void OnSequenceStart(const Mark&, const std::string&, anchor_t, - YAML::EmitterStyle::value style) override {} + YAML::EmitterStyle::value) override {} void OnSequenceEnd() override {} void OnMapStart(const Mark&, const std::string&, anchor_t, - YAML::EmitterStyle::value style) override {} + YAML::EmitterStyle::value) override {} void OnMapEnd() override {} }; From 4fc5ec36bcd29495438ac239d5e69f447cc0751a Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 12 Oct 2023 08:52:22 -0700 Subject: [PATCH 17/32] automatically create bzlmod archive for release (#1230) --- .github/workflows/bzlmod-archive.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/bzlmod-archive.yml diff --git a/.github/workflows/bzlmod-archive.yml b/.github/workflows/bzlmod-archive.yml new file mode 100644 index 000000000..cf999f3ad --- /dev/null +++ b/.github/workflows/bzlmod-archive.yml @@ -0,0 +1,20 @@ +name: Bazel Release + +on: + release: + types: [published] + +jobs: + # A release archive is required for bzlmod + # See: https://blog.bazel.build/2023/02/15/github-archive-checksum.html + bazel-release-archive: + runs-on: ubuntu-latest + continue-on-error: true + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + - run: git archive $GITHUB_REF -o "yaml-cpp-${GITHUB_REF:10}.tar.gz" + - run: gh release upload ${GITHUB_REF:10} "yaml-cpp-${GITHUB_REF:10}.tar.gz" + env: + GH_TOKEN: ${{ github.token }} From f791b955d8649751421911048a7c9dd967689811 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 12 Oct 2023 16:27:47 -0700 Subject: [PATCH 18/32] remove unncessary continue-on-error (#1234) --- .github/workflows/bzlmod-archive.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/bzlmod-archive.yml b/.github/workflows/bzlmod-archive.yml index cf999f3ad..362888c7e 100644 --- a/.github/workflows/bzlmod-archive.yml +++ b/.github/workflows/bzlmod-archive.yml @@ -9,7 +9,6 @@ jobs: # See: https://blog.bazel.build/2023/02/15/github-archive-checksum.html bazel-release-archive: runs-on: ubuntu-latest - continue-on-error: true permissions: contents: write steps: From 145eec5f3ef09ce25a38d7ab043b68f20b665e47 Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Sun, 22 Oct 2023 07:06:39 +0200 Subject: [PATCH 19/32] Add CMake option YAML_USE_SYSTEM_GTEST to use system googletest if available. (#1035) There is no need to use the embedded gtest code copy in Linux systems, if they already provide the googletest framework system-wide. Search for it, and fallback to the embedded one if the system one is not detected. This patch has been also contributed by Simon Quigley --- .github/workflows/build.yml | 14 ++++++++++++++ CMakeLists.txt | 1 + test/CMakeLists.txt | 17 ++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78b2956d0..f681eb12f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] cxx_standard: [11, 17, 20] build: [static, shared] + googletest: [build, system] generator: ["Default Generator", "MinGW Makefiles"] exclude: - os: macos-latest @@ -25,14 +26,26 @@ jobs: generator: "MinGW Makefiles" - os: ubuntu-latest generator: "MinGW Makefiles" + - os: macos-latest + googletest: system + - os: windows-latest + googletest: system env: YAML_BUILD_SHARED_LIBS: ${{ matrix.build == 'shared' && 'ON' || 'OFF' }} + YAML_USE_SYSTEM_GTEST: ${{ matrix.googletest == 'system' && 'ON' || 'OFF' }} CMAKE_GENERATOR: >- ${{format(matrix.generator != 'Default Generator' && '-G "{0}"' || '', matrix.generator)}} CMAKE_INSTALL_PREFIX: "${{ github.workspace }}/install-prefix" CMAKE_BUILD_TYPE: Debug runs-on: ${{ matrix.os }} steps: + + - uses: awalsh128/cache-apt-pkgs-action@latest + if: matrix.os == 'ubuntu-latest' + with: + packages: googletest libgmock-dev libgtest-dev + version: 1.0 + - uses: actions/checkout@v3 - name: Configure @@ -45,6 +58,7 @@ jobs: -D CMAKE_INSTALL_PREFIX="${{ env.CMAKE_INSTALL_PREFIX }}" \ -D CMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ -D YAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} \ + -D YAML_USE_SYSTEM_GTEST=${{ env.YAML_USE_SYSTEM_GTEST }} \ -D YAML_CPP_BUILD_TESTS=ON - name: Build diff --git a/CMakeLists.txt b/CMakeLists.txt index d152fd5c7..4b0978b2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIB option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT}) option(YAML_CPP_FORMAT_SOURCE "Format source" ${YAML_CPP_MAIN_PROJECT}) option(YAML_CPP_DISABLE_UNINSTALL "Disable uninstallation of yaml-cpp" OFF) +option(YAML_USE_SYSTEM_GTEST "Use system googletest if found" OFF) cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" OFF diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c9e7f041b..bc239a552 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,11 +4,17 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(BUILD_MOCK ON CACHE BOOL "" FORCE) set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) -add_subdirectory( - "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0" - "${CMAKE_CURRENT_BINARY_DIR}/prefix") - -include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0/googletest/include") +if(YAML_USE_SYSTEM_GTEST) + find_package(GTest) + if (NOT GTEST_FOUND) + message(FATAL_ERROR "system googletest was requested but not found") + endif() +else() + add_subdirectory( + "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0" + "${CMAKE_CURRENT_BINARY_DIR}/prefix") + include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0/googletest/include") +endif() set(test-new-api-pattern "new-api/*.cpp") set(test-source-pattern "*.cpp" "integration/*.cpp" "node/*.cpp") @@ -38,6 +44,7 @@ target_link_libraries(yaml-cpp-tests PRIVATE Threads::Threads yaml-cpp + gtest gmock) set_property(TARGET yaml-cpp-tests PROPERTY CXX_STANDARD_REQUIRED ON) From db03655d58c66f31952c772718d0394eac2e5481 Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Mon, 23 Oct 2023 14:20:22 +0200 Subject: [PATCH 20/32] Make sure CXX_STANDARD can be overridden from outside (#1239) --- test/cmake/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 19a7910ae..a2b8e78a8 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -15,5 +15,7 @@ else() endif() add_executable(main main.cpp) -set_target_properties(main PROPERTIES CXX_STANDARD 11) +if (NOT DEFINED CMAKE_CXX_STANDARD) + set_target_properties(main PROPERTIES CXX_STANDARD 11) +endif() target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES}) From 30e69332799eda1f6067b60990938ac13a21a73e Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Mon, 6 Nov 2023 08:48:29 -0600 Subject: [PATCH 21/32] Fix yaml-cpp-config.cmake.in --- yaml-cpp-config.cmake.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/yaml-cpp-config.cmake.in b/yaml-cpp-config.cmake.in index f71e13b8f..7f16f7958 100644 --- a/yaml-cpp-config.cmake.in +++ b/yaml-cpp-config.cmake.in @@ -19,8 +19,11 @@ include("${CMAKE_CURRENT_LIST_DIR}/yaml-cpp-targets.cmake") # These are IMPORTED targets created by yaml-cpp-targets.cmake set(YAML_CPP_LIBRARIES "@EXPORT_TARGETS@") -add_library(yaml-cpp INTERFACE IMPORTED) -target_link_libraries(yaml-cpp INTERFACE yaml-cpp::yaml-cpp) +if(NOT TARGET yaml-cpp) + add_library(yaml-cpp INTERFACE IMPORTED) + target_link_libraries(yaml-cpp INTERFACE yaml-cpp::yaml-cpp) +endif() + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) set_target_properties(yaml-cpp PROPERTIES DEPRECATION "The target yaml-cpp is deprecated and will be removed in version 0.10.0. Use the yaml-cpp::yaml-cpp target instead." From 51adc5f7392648622c80909f65bf794fc48d013f Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Mon, 6 Nov 2023 10:17:50 -0600 Subject: [PATCH 22/32] Update yaml-cpp-config.cmake.in --- yaml-cpp-config.cmake.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yaml-cpp-config.cmake.in b/yaml-cpp-config.cmake.in index 7f16f7958..260ae00e0 100644 --- a/yaml-cpp-config.cmake.in +++ b/yaml-cpp-config.cmake.in @@ -19,15 +19,15 @@ include("${CMAKE_CURRENT_LIST_DIR}/yaml-cpp-targets.cmake") # These are IMPORTED targets created by yaml-cpp-targets.cmake set(YAML_CPP_LIBRARIES "@EXPORT_TARGETS@") +# Protect against multiple inclusion, which would fail when already imported targets are added once more. if(NOT TARGET yaml-cpp) add_library(yaml-cpp INTERFACE IMPORTED) target_link_libraries(yaml-cpp INTERFACE yaml-cpp::yaml-cpp) -endif() - -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) - set_target_properties(yaml-cpp PROPERTIES - DEPRECATION "The target yaml-cpp is deprecated and will be removed in version 0.10.0. Use the yaml-cpp::yaml-cpp target instead." - ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + set_target_properties(yaml-cpp PROPERTIES + DEPRECATION "The target yaml-cpp is deprecated and will be removed in version 0.10.0. Use the yaml-cpp::yaml-cpp target instead." + ) + endif() endif() check_required_components(yaml-cpp) From 1c5a38eef3fafea9f796b04d16d1c27874f70a02 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sun, 26 Nov 2023 18:30:38 +0100 Subject: [PATCH 23/32] workflows/build.yml: Use debug std C++ library on Ubuntu Protect from regressions due to use of undefined or implementation-specific behavior when using `std::` containers and smart pointers. This only has effect on platforms with the GNU standard C++ library. Refer to https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html. --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f681eb12f..a939320d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,6 +37,7 @@ jobs: ${{format(matrix.generator != 'Default Generator' && '-G "{0}"' || '', matrix.generator)}} CMAKE_INSTALL_PREFIX: "${{ github.workspace }}/install-prefix" CMAKE_BUILD_TYPE: Debug + CMAKE_CXX_FLAGS_DEBUG: ${{ matrix.googletest == 'build' && '-g -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC' || '-g' }} runs-on: ${{ matrix.os }} steps: @@ -57,6 +58,7 @@ jobs: -D CMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} \ -D CMAKE_INSTALL_PREFIX="${{ env.CMAKE_INSTALL_PREFIX }}" \ -D CMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ + -D CMAKE_CXX_FLAGS_DEBUG="${{ env.CMAKE_CXX_FLAGS_DEBUG }}" \ -D YAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} \ -D YAML_USE_SYSTEM_GTEST=${{ env.YAML_USE_SYSTEM_GTEST }} \ -D YAML_CPP_BUILD_TESTS=ON From eaf72053724814be3b99d38e292fca5797a57b7b Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Mon, 27 Nov 2023 18:57:10 +0100 Subject: [PATCH 24/32] README.md: Describe building with debug libstdc++ mode --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 70c231445..e8607062b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,17 @@ cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=on|OFF] .. * `yaml-cpp` builds a static library by default, you may want to build a shared library by specifying `-DYAML_BUILD_SHARED_LIBS=ON`. + * [Debug mode of the GNU standard C++ + library](https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html) + can be used when both `yaml-cpp` and client code is compiled with the + `_GLIBCXX_DEBUG` flag (e.g. by calling CMake with `-D + CMAKE_CXX_FLAGS_DEBUG='-g -D_GLIBCXX_DEBUG'` option). + + Note that for `yaml-cpp` unit tests to run successfully, the _GoogleTest_ + library also must be built with this flag, i.e. the system one cannot be + used (the _YAML_USE_SYSTEM_GTEST_ CMake option must be _OFF_, which is the + default). + * For more options on customizing the build, see the [CMakeLists.txt](https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt) file. #### 2. Build it! From f30582fb09c4203872fc28443541ae3c5c540057 Mon Sep 17 00:00:00 2001 From: Diogo Teles Sant'Anna Date: Wed, 13 Dec 2023 20:22:04 +0000 Subject: [PATCH 25/32] ci: hash-pin sensitive workflow dependency Signed-off-by: Diogo Teles Sant'Anna --- .github/workflows/bzlmod-archive.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bzlmod-archive.yml b/.github/workflows/bzlmod-archive.yml index 362888c7e..38a75dd84 100644 --- a/.github/workflows/bzlmod-archive.yml +++ b/.github/workflows/bzlmod-archive.yml @@ -12,7 +12,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - run: git archive $GITHUB_REF -o "yaml-cpp-${GITHUB_REF:10}.tar.gz" - run: gh release upload ${GITHUB_REF:10} "yaml-cpp-${GITHUB_REF:10}.tar.gz" env: From c7639e81d5f00a5b47a2c9bd668f10d74b949071 Mon Sep 17 00:00:00 2001 From: Diogo Teles Sant'Anna Date: Thu, 14 Dec 2023 14:56:37 +0000 Subject: [PATCH 26/32] ci: configure dependabot to montly update GHAs Signed-off-by: Diogo Teles Sant'Anna --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..dc2380610 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + groups: + github-actions: + patterns: + - "*" + From 94710bb2213cb6793121eaaa4edfb15abcca7af9 Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Thu, 28 Dec 2023 10:11:58 -0600 Subject: [PATCH 27/32] Add default destructor to EmitFromEvents --- include/yaml-cpp/emitfromevents.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/yaml-cpp/emitfromevents.h b/include/yaml-cpp/emitfromevents.h index 1f389c5a1..c00d26e74 100644 --- a/include/yaml-cpp/emitfromevents.h +++ b/include/yaml-cpp/emitfromevents.h @@ -23,6 +23,7 @@ class Emitter; class EmitFromEvents : public EventHandler { public: EmitFromEvents(Emitter& emitter); + ~EmitFromEvents() override = default; void OnDocumentStart(const Mark& mark) override; void OnDocumentEnd() override; From c28295bda489422e4b5928aa0b978eb51dbdcbb1 Mon Sep 17 00:00:00 2001 From: Alexandre TISSOT <60519602+Trompettesib@users.noreply.github.com> Date: Thu, 13 Oct 2022 22:12:19 +0200 Subject: [PATCH 28/32] Add CMake integration example --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index e8607062b..f2ec0613a 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,27 @@ cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=on|OFF] .. **Note:** To clean up, just remove the `build` directory. +## How to Integrate it within your project using CMake + +You can use for example FetchContent : + +```cmake +include(FetchContent) + +FetchContent_Declare(yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + GIT_TAG 1b50109f7bea60bd382d8ea7befce3d2bd67da5f) # The latest yaml-cpp commit at the time of writing. +FetchContent_GetProperties(yaml-cpp) + +if(NOT yaml-cpp_POPULATED) + message(STATUS "Fetching yaml-cpp...") + FetchContent_Populate(yaml-cpp) + add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR}) +endif() + +target_link_libraries(YOUR_LIBRARY PUBLIC yaml-cpp::yaml-cpp) # The library or executable that require yaml-cpp library +``` + ## Recent Releases [yaml-cpp 0.6.0](https://github.com/jbeder/yaml-cpp/releases/tag/yaml-cpp-0.6.0) released! This release requires C++11, and no longer depends on Boost. From 9eb1142900096b9115ba2db2a521c76c117cacd9 Mon Sep 17 00:00:00 2001 From: Trompettesib Date: Thu, 4 Jan 2024 12:03:33 +0100 Subject: [PATCH 29/32] Fix GIT_TAG field in cmake integration example --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f2ec0613a..a121b700c 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,11 @@ You can use for example FetchContent : ```cmake include(FetchContent) -FetchContent_Declare(yaml-cpp +FetchContent_Declare( + yaml-cpp GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git - GIT_TAG 1b50109f7bea60bd382d8ea7befce3d2bd67da5f) # The latest yaml-cpp commit at the time of writing. + GIT_TAG # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master) +) FetchContent_GetProperties(yaml-cpp) if(NOT yaml-cpp_POPULATED) From c67d701ad81da65a576efd3341634f8cd3892c9b Mon Sep 17 00:00:00 2001 From: Alejandro-FA <61871580+Alejandro-FA@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:19:15 +0100 Subject: [PATCH 30/32] Fix indentation of empty sequences and add test --- src/emitter.cpp | 3 ++- test/integration/emitter_test.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/emitter.cpp b/src/emitter.cpp index 4d483075b..2a2262d4b 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -213,7 +213,8 @@ void Emitter::EmitEndSeq() { if (m_pState->CurGroupFlowType() == FlowType::Flow) { if (m_stream.comment()) m_stream << "\n"; - m_stream << IndentTo(m_pState->CurIndent()); + if (originalType == FlowType::Block || m_pState->HasBegunNode()) + m_stream << IndentTo(m_pState->CurIndent()); if (originalType == FlowType::Block) { m_stream << "["; } else { diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp index b277d5717..e3464a644 100644 --- a/test/integration/emitter_test.cpp +++ b/test/integration/emitter_test.cpp @@ -176,6 +176,17 @@ TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) { ]])"); } +TEST_F(EmitterTest, EmptyFlowSeqInMap) { + out << BeginMap; + out << Key << Flow << BeginSeq << EndSeq; + out << Value << 1; + out << Key << 2; + out << Value << Flow << BeginSeq << EndSeq; + out << EndMap; + + ExpectEmit("[]: 1\n2: []"); +} + TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) { out << Flow; out << BeginSeq; From 96f5c887f373ac483844c51cfc9a3621002314f0 Mon Sep 17 00:00:00 2001 From: Jason Beach Date: Fri, 26 Jan 2024 12:26:52 -0500 Subject: [PATCH 31/32] assign fallback value --- include/yaml-cpp/node/impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 312281f18..150a6cfc6 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -97,7 +97,7 @@ struct as_if { if (!node.m_pNode) return fallback; - T t; + T t = fallback; if (convert::decode(node, t)) return t; return fallback; From 4afd53b0d3140ba2eb85816bfced209cf37ff096 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 16:49:13 +0000 Subject: [PATCH 32/32] Bump the github-actions group with 1 update Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout). - [Release notes](https://github.com/actions/checkout/releases) - [Commits](https://github.com/actions/checkout/compare/v2...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 6 +++--- .github/workflows/bzlmod-archive.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a939320d4..12564936b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,7 @@ jobs: packages: googletest libgmock-dev libgtest-dev version: 1.0 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Configure run: | @@ -105,7 +105,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -123,7 +123,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build shell: bash diff --git a/.github/workflows/bzlmod-archive.yml b/.github/workflows/bzlmod-archive.yml index 38a75dd84..cdb008fe7 100644 --- a/.github/workflows/bzlmod-archive.yml +++ b/.github/workflows/bzlmod-archive.yml @@ -12,7 +12,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - run: git archive $GITHUB_REF -o "yaml-cpp-${GITHUB_REF:10}.tar.gz" - run: gh release upload ${GITHUB_REF:10} "yaml-cpp-${GITHUB_REF:10}.tar.gz" env: