[libc++] [CMake] Link with /nodefaultlibs on Windows
Summary:
This patch attempts to fix the libc++ build/link so that it doesn't use an default C++ libraries on Windows. This is needed to prevent linking to MSVC's STL library.
Additionally this patch changes libc++ so that it is always linked with the non-debug DLL's (e.g. `/MD`). This is needed so that the test suite can correctly link the same libraries without needing to know which configuration `c++.dll` was linked with.
Reviewers: compnerd, rnk, majnemer, kimgr, awson, halyavin, smeenai
Subscribers: cfe-commits, mgorny
Differential Revision: https://reviews.llvm.org/D28441
llvm-svn: 292001
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 9fa0ed3..b12910f 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -39,6 +39,12 @@
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
)
+if (MSVC)
+ set(LIBCXX_TARGETING_MSVC ON)
+else()
+ set(LIBCXX_TARGETING_MSVC OFF)
+endif()
+
#===============================================================================
# Setup CMake Options
#===============================================================================
@@ -377,6 +383,11 @@
endif()
remove_flags(-stdlib=libc++ -stdlib=libstdc++)
+# FIXME: Remove all debug flags and flags that change which Windows
+# default libraries are linked. Currently we only support linking the
+# non-debug DLLs
+remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md" "/RTC1")
+
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
# so they don't get transformed into -Wno and -errors respectivly.
@@ -476,7 +487,7 @@
define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
if (LIBCXX_ENABLE_ASSERTIONS)
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
- define_if_not(MSVC -D_DEBUG)
+ define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG)
endif()
# Modules flags ===============================================================