From fdfdd275fd79504ee4ab5c78162713db986a72b1 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Wed, 5 Feb 2020 19:37:50 -0800 Subject: [PATCH] [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 --- .../modules/LLVMExternalProjectUtils.cmake | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index e027c13f07e0..a69a4720b8b0 100644 --- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -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)