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/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: + - "*" + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a408a9dfe..12564936b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,13 +6,18 @@ on: branches: [ master ] workflow_dispatch: permissions: read-all +defaults: + run: + shell: bash jobs: cmake-build: strategy: fail-fast: false matrix: 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 @@ -21,34 +26,78 @@ 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_CPP_BUILD_TESTS: 'ON' + 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 + CMAKE_CXX_FLAGS_DEBUG: ${{ matrix.googletest == 'build' && '-g -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC' || '-g' }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v1 + - uses: awalsh128/cache-apt-pkgs-action@latest + if: matrix.os == 'ubuntu-latest' + with: + packages: googletest libgmock-dev libgtest-dev + version: 1.0 - - name: Build - shell: bash + - uses: actions/checkout@v4 + + - name: Configure 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 + 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 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 + + - name: Build 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 }} - 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: @@ -56,17 +105,34 @@ 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 run: | cd "${{ github.workspace }}" bazel build :all - name: Test - shell: bash run: | 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@v4 + + - 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/.github/workflows/bzlmod-archive.yml b/.github/workflows/bzlmod-archive.yml new file mode 100644 index 000000000..cdb008fe7 --- /dev/null +++ b/.github/workflows/bzlmod-archive.yml @@ -0,0 +1,19 @@ +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 + permissions: + contents: write + steps: + - 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: + GH_TOKEN: ${{ github.token }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef6e8a30..4b0978b2a 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 @@ -7,7 +8,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) @@ -24,13 +25,18 @@ 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}) +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 "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) +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) @@ -143,13 +149,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( @@ -168,15 +173,15 @@ if (YAML_CPP_INSTALL) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") install(EXPORT yaml-cpp-targets - DESTINATION "${CONFIG_EXPORT_DIR}") + NAMESPACE yaml-cpp:: + 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) @@ -195,7 +200,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" 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) diff --git a/README.md b/README.md index 70c231445..a121b700c 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! @@ -38,6 +49,29 @@ 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 # 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) + 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. 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. 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 +``` 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; diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 292c5d3c0..d49702f82 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -18,6 +18,10 @@ #include #include +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __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 ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __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/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; 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/CMakeLists.txt b/test/CMakeLists.txt index 351b03f81..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") @@ -33,11 +39,12 @@ 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 yaml-cpp + gtest gmock) set_property(TARGET yaml-cpp-tests PROPERTY CXX_STANDARD_REQUIRED ON) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt new file mode 100644 index 000000000..a2b8e78a8 --- /dev/null +++ b/test/cmake/CMakeLists.txt @@ -0,0 +1,21 @@ +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) +if (NOT DEFINED CMAKE_CXX_STANDARD) + set_target_properties(main PROPERTIES CXX_STANDARD 11) +endif() +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/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; 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"; 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 {} }; diff --git a/yaml-cpp-config.cmake.in b/yaml-cpp-config.cmake.in index 799b9b418..260ae00e0 100644 --- a/yaml-cpp-config.cmake.in +++ b/yaml-cpp-config.cmake.in @@ -11,12 +11,23 @@ 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@) +# 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) + 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)