Skip to content

Commit 125e8ef

Browse files
committed
[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
1 parent e248d69 commit 125e8ef

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

runtimes/CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ endif()
8787

8888
include(CheckLibraryExists)
8989
include(CheckCCompilerFlag)
90-
91-
# Disable use of the installed C++ standard library when building runtimes. If
92-
# MSVC is true, we must be using the clang-cl driver, which doesn't understand
93-
# these flags.
94-
if (NOT MSVC)
95-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++")
90+
include(CheckCXXCompilerFlag)
91+
92+
# Disable use of the installed C++ standard library when building runtimes.
93+
# Check for -nostdlib++ first; if there's no C++ standard library yet,
94+
# all check_cxx_compiler_flag commands will fail until we add -nostdlib++
95+
# (or -nodefaultlibs).
96+
check_c_compiler_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
97+
if (LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG)
98+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
99+
endif()
100+
check_cxx_compiler_flag(-nostdinc++ LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG)
101+
if (LLVM_RUNTIMES_SUPPORT_NOSTDINCXX_FLAG)
102+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
96103
endif()
97104

98105
# Avoid checking whether the compiler is working.

0 commit comments

Comments
 (0)