Skip to content

Commit

Permalink
Merge branch 'master' into cmake-hide-symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Apr 25, 2024
2 parents d7520f7 + 76dc671 commit f421443
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
github-actions:
patterns:
- "*"

8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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: |
Expand All @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bzlmod-archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,47 @@ 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!
* The command you'll need to run depends on the generator you chose earlier.

**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 <tag_name> # 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.
Expand Down
1 change: 1 addition & 0 deletions include/yaml-cpp/emitfromevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/yaml-cpp/node/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct as_if {
if (!node.m_pNode)
return fallback;

T t;
T t = fallback;
if (convert<T>::decode(node, t))
return t;
return fallback;
Expand Down
3 changes: 2 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions yaml-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f421443

Please sign in to comment.