[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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292001 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -39,6 +39,12 @@ MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
|
|||||||
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
|
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
|
# Setup CMake Options
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
@@ -377,6 +383,11 @@ if (NOT LIBCXX_STANDALONE_BUILD)
|
|||||||
endif()
|
endif()
|
||||||
remove_flags(-stdlib=libc++ -stdlib=libstdc++)
|
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.
|
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
|
||||||
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
|
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
|
||||||
# so they don't get transformed into -Wno and -errors respectivly.
|
# so they don't get transformed into -Wno and -errors respectivly.
|
||||||
@@ -476,7 +487,7 @@ define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
|
|||||||
define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
|
define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
|
||||||
if (LIBCXX_ENABLE_ASSERTIONS)
|
if (LIBCXX_ENABLE_ASSERTIONS)
|
||||||
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
# 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()
|
endif()
|
||||||
|
|
||||||
# Modules flags ===============================================================
|
# Modules flags ===============================================================
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ endmacro()
|
|||||||
# or added in other parts of LLVM's cmake configuration.
|
# or added in other parts of LLVM's cmake configuration.
|
||||||
macro(remove_flags)
|
macro(remove_flags)
|
||||||
foreach(var ${ARGN})
|
foreach(var ${ARGN})
|
||||||
|
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||||
string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
|
|||||||
@@ -104,6 +104,17 @@ if (NOT WIN32)
|
|||||||
endif()
|
endif()
|
||||||
add_link_flags_if_supported(-nodefaultlibs)
|
add_link_flags_if_supported(-nodefaultlibs)
|
||||||
|
|
||||||
|
if (LIBCXX_TARGETING_MSVC)
|
||||||
|
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
|
||||||
|
# Required for standards-complaint wide character formatting functions
|
||||||
|
# (e.g. `printfw`/`scanfw`)
|
||||||
|
add_library_flags(iso_stdio_wide_specifiers)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY)
|
if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY)
|
||||||
if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION)
|
if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION)
|
||||||
set(LIBCXX_LIBCPPABI_VERSION "2") # Default value
|
set(LIBCXX_LIBCPPABI_VERSION "2") # Default value
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ class Configuration(object):
|
|||||||
self.cxx.link_flags += ['-lcxxrt']
|
self.cxx.link_flags += ['-lcxxrt']
|
||||||
elif cxx_abi == 'none' or cxx_abi == 'default':
|
elif cxx_abi == 'none' or cxx_abi == 'default':
|
||||||
if self.is_windows:
|
if self.is_windows:
|
||||||
self.cxx.link_flags += ['-lmsvcrtd']
|
self.cxx.link_flags += ['-lmsvcrt']
|
||||||
else:
|
else:
|
||||||
self.lit_config.fatal(
|
self.lit_config.fatal(
|
||||||
'C++ ABI setting %s unsupported for tests' % cxx_abi)
|
'C++ ABI setting %s unsupported for tests' % cxx_abi)
|
||||||
|
|||||||
Reference in New Issue
Block a user