[libc++][CMake] Use debug MSVC runtimes when libc++ is built in debug mode

Summary: This patch allows libc++ to be built against the debug MSVC runtimes instead of just the release ones.

Reviewers: rnk, majnemer, compnerd, smeenai

Subscribers: mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D28725

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292006 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index f83051f..23a17dd 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -102,14 +102,21 @@
 if (NOT WIN32)
   add_flags_if_supported(-fPIC)
 endif()
+
 add_link_flags_if_supported(-nodefaultlibs)
 
 if (LIBCXX_TARGETING_MSVC)
+  if (LIBCXX_DEBUG_BUILD)
+    set(LIB_SUFFIX "d")
+  else()
+    set(LIB_SUFFIX "")
+  endif()
   add_compile_flags(/Zl)
   add_link_flags(/nodefaultlib)
-  add_library_flags(ucrt) # Universal C runtime
-  add_library_flags(vcruntime) # C++ runtime
-  add_library_flags(msvcrt) # C runtime startup files
+
+  add_library_flags(ucrt${LIB_SUFFIX}) # Universal C runtime
+  add_library_flags(vcruntime${LIB_SUFFIX}) # C++ runtime
+  add_library_flags(msvcrt${LIB_SUFFIX}) # C runtime startup files
   # Required for standards-complaint wide character formatting functions
   # (e.g. `printfw`/`scanfw`)
   add_library_flags(iso_stdio_wide_specifiers)