[runtimes] Check whether -nostdinc++ and -nostdlib++ are supported

Don't blindly assume they're supported - GCC doesn't support -nostdlib++.

The llvm-project/runtimes directory is supposed to allow building the
runtimes standalone from a newly built Clang, and thus should allow
building with other compilers too.

Differential Revision: https://reviews.llvm.org/D109719
This commit is contained in:
Martin Storsjö 2021-09-13 23:05:23 +03:00
parent e248d69036
commit 125e8ef10b
1 changed files with 12 additions and 5 deletions

View File

@ -87,12 +87,19 @@ endif()
include(CheckLibraryExists) include(CheckLibraryExists)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
# Disable use of the installed C++ standard library when building runtimes. If # Disable use of the installed C++ standard library when building runtimes.
# MSVC is true, we must be using the clang-cl driver, which doesn't understand # Check for -nostdlib++ first; if there's no C++ standard library yet,
# these flags. # all check_cxx_compiler_flag commands will fail until we add -nostdlib++
if (NOT MSVC) # (or -nodefaultlibs).
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++") check_c_compiler_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
if (LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
endif()
check_cxx_compiler_flag(-nostdinc++ LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG)
if (LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
endif() endif()
# Avoid checking whether the compiler is working. # Avoid checking whether the compiler is working.