[CMake] Use LLVM tools external project build where possible

This reduces the reliance on host tools and makes the build more
hermetic. Some of the runtimes already assume that certain tools are
always available, for example libc++ and libc++abi archive merging
relies on ar to extract files out of the archive, even on Darwin.

Differential Revision: https://reviews.llvm.org/D74107
This commit is contained in:
Petr Hosek 2020-02-05 19:37:50 -08:00
parent 9c1c825b72
commit fdfdd275fd

View File

@ -45,10 +45,18 @@ function(llvm_ExternalProject_Add name source_dir)
"CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES;STRIP_TOOL"
${ARGN})
canonicalize_tool_name(${name} nameCanon)
foreach(arg ${ARG_CMAKE_ARGS})
if(arg MATCHES "^-DCMAKE_SYSTEM_NAME=")
string(REGEX REPLACE "^-DCMAKE_SYSTEM_NAME=(.*)$" "\\1" _cmake_system_name "${arg}")
endif()
endforeach()
if(NOT ARG_TOOLCHAIN_TOOLS)
set(ARG_TOOLCHAIN_TOOLS clang lld)
if(NOT APPLE AND NOT WIN32)
list(APPEND ARG_TOOLCHAIN_TOOLS llvm-ar llvm-lipo llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip)
set(ARG_TOOLCHAIN_TOOLS clang lld llvm-ar llvm-lipo llvm-ranlib llvm-nm llvm-objdump)
if(NOT _cmake_system_name STREQUAL Darwin)
# TODO: These tools don't fully support Mach-O format yet.
list(APPEND ARG_TOOLCHAIN_TOOLS llvm-objcopy llvm-strip)
endif()
endif()
foreach(tool ${ARG_TOOLCHAIN_TOOLS})
@ -104,12 +112,6 @@ function(llvm_ExternalProject_Add name source_dir)
endforeach()
endforeach()
foreach(arg ${ARG_CMAKE_ARGS})
if(arg MATCHES "^-DCMAKE_SYSTEM_NAME=")
string(REGEX REPLACE "^-DCMAKE_SYSTEM_NAME=(.*)$" "\\1" _cmake_system_name "${arg}")
endif()
endforeach()
if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
if(CLANG_IN_TOOLCHAIN)
if(_cmake_system_name STREQUAL Windows)