diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..dc23806 --- /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 f681eb1..1256493 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: @@ -46,7 +47,7 @@ jobs: packages: googletest libgmock-dev libgtest-dev version: 1.0 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Configure run: | @@ -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 @@ -103,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: | @@ -121,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 362888c..cdb008f 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@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: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0674afe..63ddc41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_C 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) +option(YAML_ENABLE_PIC "Use Position-Independent Code " ON) cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" OFF @@ -96,7 +97,7 @@ if(YAML_BUILD_SHARED_LIBS) VISIBILITY_INLINES_HIDDEN ON ) else() - set_property(TARGET yaml-cpp PROPERTY POSITION_INDEPENDENT_CODE ON) + set_property(TARGET yaml-cpp PROPERTY POSITION_INDEPENDENT_CODE ${YAML_ENABLE_PIC}) endif() target_include_directories(yaml-cpp diff --git a/README.md b/README.md index 70c2314..a121b70 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/include/yaml-cpp/emitfromevents.h b/include/yaml-cpp/emitfromevents.h index 1f389c5..c00d26e 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/impl.h b/include/yaml-cpp/node/impl.h index 312281f..150a6cf 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 4d48307..2a2262d 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 b277d57..e3464a6 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/yaml-cpp-config.cmake.in b/yaml-cpp-config.cmake.in index f71e13b..260ae00 100644 --- a/yaml-cpp-config.cmake.in +++ b/yaml-cpp-config.cmake.in @@ -19,12 +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@") -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." - ) +# 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)