From 21ae20318a5b30d5e593aa3c3fd9987378b1e63b Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Wed, 12 Aug 2026 22:17:03 +0800 Subject: [PATCH 1/7] Default MSVC static CRT for static yaml-cpp builds Signed-off-by: harleywilsoneng --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1eee6ad5..f90f6ee04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,8 @@ 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 + "MSVC: Build yaml-cpp with shared runtime libs (/MD). When building a static library, leave OFF for /MT to match statically-linked apps." + ${YAML_BUILD_SHARED_LIBS} "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") From 87947f617819769c5a736e743ed722f43db54503 Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Wed, 12 Aug 2026 22:17:05 +0800 Subject: [PATCH 2/7] Default MSVC static CRT for static yaml-cpp builds Signed-off-by: harleywilsoneng --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index fb46a1713..2abcd3cdf 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ 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`. + * On Windows with MSVC, static builds default to the static CRT (`/MT`) so yaml-cpp can link into + statically-linked applications (e.g. static MFC). Set `-DYAML_MSVC_SHARED_RT=ON` if you need + the dynamic CRT (`/MD`) instead. When linking yaml-cpp statically into your project, define + `YAML_CPP_STATIC_DEFINE` in your target (or consume the `yaml-cpp::yaml-cpp` imported target, + which sets it automatically). + * [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 From 9e2da141f91bb915d7ca002c4660227e81eaf606 Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Thu, 13 Aug 2026 12:39:49 +0800 Subject: [PATCH 3/7] fix(cmake): match consumer MSVC CRT with static yaml-cpp Signed-off-by: harleywilsoneng From 0a872e25194025cbfaf4ed7d4dae41f73fa3df5e Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Thu, 13 Aug 2026 12:39:51 +0800 Subject: [PATCH 4/7] fix(cmake): match consumer MSVC CRT with static yaml-cpp Signed-off-by: harleywilsoneng From 598deae570ca978f5adda55afd673a83a552a2cf Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Thu, 13 Aug 2026 12:39:52 +0800 Subject: [PATCH 5/7] fix(cmake): match consumer MSVC CRT with static yaml-cpp Signed-off-by: harleywilsoneng --- test/cmake/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 2ee23679b..7c7e7cac1 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -18,4 +18,10 @@ add_executable(main main.cpp) if (NOT DEFINED CMAKE_CXX_STANDARD) set_target_properties(main PROPERTIES CXX_STANDARD 11) endif() +if(MSVC) + get_target_property(_yaml_cpp_rt yaml-cpp::yaml-cpp MSVC_RUNTIME_LIBRARY) + if(_yaml_cpp_rt) + set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY "${_yaml_cpp_rt}") + endif() +endif() target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES}) From 8875339c8c02b9773027a52af83b476d28eab3c0 Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Thu, 13 Aug 2026 12:48:33 +0800 Subject: [PATCH 6/7] fix(test): align consumer CRT with static yaml-cpp on MSVC Signed-off-by: harleywilsoneng --- test/cmake/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 7c7e7cac1..961b7ce81 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -19,9 +19,12 @@ if (NOT DEFINED CMAKE_CXX_STANDARD) set_target_properties(main PROPERTIES CXX_STANDARD 11) endif() if(MSVC) - get_target_property(_yaml_cpp_rt yaml-cpp::yaml-cpp MSVC_RUNTIME_LIBRARY) - if(_yaml_cpp_rt) - set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY "${_yaml_cpp_rt}") + if(YAML_CPP_SHARED_LIBS_BUILT) + set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY + MultiThreaded$<$:Debug>DLL) + else() + set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY + MultiThreaded$<$:Debug>) endif() endif() target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES}) From 378068aa44999ee9771e31dd4cf8599b8da22a56 Mon Sep 17 00:00:00 2001 From: harleywilsoneng Date: Fri, 14 Aug 2026 16:58:22 +0800 Subject: [PATCH 7/7] docs: prefer yaml-cpp::yaml-cpp in README CRT note Signed-off-by: harleywilsoneng --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2abcd3cdf..f8a92d7c7 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,12 @@ 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`. - * On Windows with MSVC, static builds default to the static CRT (`/MT`) so yaml-cpp can link into - statically-linked applications (e.g. static MFC). Set `-DYAML_MSVC_SHARED_RT=ON` if you need - the dynamic CRT (`/MD`) instead. When linking yaml-cpp statically into your project, define - `YAML_CPP_STATIC_DEFINE` in your target (or consume the `yaml-cpp::yaml-cpp` imported target, - which sets it automatically). + * On Windows with MSVC, static builds default to the static CRT (`/MT`) so yaml-cpp can link into + statically-linked applications (e.g. static MFC). Set `-DYAML_MSVC_SHARED_RT=ON` if you need + the dynamic CRT (`/MD`) instead. When using CMake, link the `yaml-cpp::yaml-cpp` imported target + (e.g. `target_link_libraries(your_target PRIVATE yaml-cpp::yaml-cpp)`), which sets the needed + defines automatically. If you are not using CMake, define `YAML_CPP_STATIC_DEFINE` for your + target when linking the static library. * [Debug mode of the GNU standard C++ library](https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html)