Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake =================================================================== --- compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -600,6 +600,7 @@ -DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib -DCOMPILER_RT_LIBCXX_PATH=${COMPILER_RT_LIBCXX_PATH} -DCOMPILER_RT_LIBCXXABI_PATH=${COMPILER_RT_LIBCXXABI_PATH} + -DRUNTIMES_BUILD=${RUNTIMES_BUILD} ${LIBCXX_CMAKE_ARGS} INSTALL_COMMAND "" STEP_TARGETS configure build Index: compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt =================================================================== --- compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt +++ compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt @@ -1,5 +1,24 @@ cmake_minimum_required(VERSION 3.4.3) +# TODO: We shouldn't need a working C++ library, we're building C++ library +# using this file after all. However, libc++abi and libc++ in standalone mode +# include LLVM's HandleLLVMOptions which checks whether the compiler support +# C++ using check_cxx_compiler_flag which tries to link C++ library and that +# breaks C++ library hasn't been built yet (e.g. in the runtimes build where +# C++ library is being built using the just built compiler). +# +# We need to prevent CMake from trying to use the C++ library. One way to do +# that is by using -nostdlib and then only including -lc plus runtimes which +# requires handling runtimes compiler-rt builtins and libgcc which adds another +# layer of complexity. We could use -nostdlib++ but that flag is only supported +# by newer Clang versions. +# +# For now, we pass the RUNTIMES_BUILD option through to detect whether we're +# performing the runtimes build, and if so we use the -nostdlib++ flag. +if (RUNTIMES_BUILD) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++") +endif() + # Build static libcxxabi. set(LIBCXXABI_STANDALONE_BUILD 1) set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")