Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ 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 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)
can be used when both `yaml-cpp` and client code is compiled with the
Expand Down
9 changes: 9 additions & 0 deletions test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ add_executable(main main.cpp)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set_target_properties(main PROPERTIES CXX_STANDARD 11)
endif()
if(MSVC)
if(YAML_CPP_SHARED_LIBS_BUILT)
set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY
MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)
else()
set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY
MultiThreaded$<$<CONFIG:Debug>:Debug>)
endif()
endif()
target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES})