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") diff --git a/README.md b/README.md index fb46a1713..f8a92d7c7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 2ee23679b..961b7ce81 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -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$<$:Debug>DLL) + else() + set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY + MultiThreaded$<$:Debug>) + endif() +endif() target_link_libraries(main PRIVATE ${YAML_CPP_LIBRARIES})