From 125e8ef10ba468d41b27bf9c7569c1a0520d1ab9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Mon, 13 Sep 2021 23:05:23 +0300 Subject: [PATCH] [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 --- runtimes/CMakeLists.txt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index 16953e8..ee73e5b 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -87,12 +87,19 @@ endif() include(CheckLibraryExists) include(CheckCCompilerFlag) - -# Disable use of the installed C++ standard library when building runtimes. If -# MSVC is true, we must be using the clang-cl driver, which doesn't understand -# these flags. -if (NOT MSVC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++") +include(CheckCXXCompilerFlag) + +# Disable use of the installed C++ standard library when building runtimes. +# Check for -nostdlib++ first; if there's no C++ standard library yet, +# all check_cxx_compiler_flag commands will fail until we add -nostdlib++ +# (or -nodefaultlibs). +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() # Avoid checking whether the compiler is working. -- 2.7.4