llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-libcxx Author: Matt Arsenault (arsenm) <details> <summary>Changes</summary> Compute the cmake system name from the target triple, rather than passing through the host's. This is primarily to stop forwarding OSX specific cmake variables. This fixes build failures when trying to build gpu libc on mac hosts. Previously it would fail on several issues, starting with an unused argument -mmacos-version-min error, followed by other errors caused by passing -isysroot. Secondarily, restrict the cmake imported targets when cross compiling. Without this, the amdgpu build prints many cmake warnings about the target not supporting shared libraries. Claude did most of the actual work, though it required quite a few rounds of prodding to get it into the right place. In particular it took care of handling all of the cmake platform recognized names from the triple. Co-authored-by: Claude Opus 4.6 <noreply@<!-- -->anthropic.com> --- Patch is 21.97 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/203504.diff 19 Files Affected: - (modified) clang/cmake/modules/ClangConfig.cmake.in (+4-1) - (added) cmake/Modules/GetTripleCMakeSystemName.cmake (+89) - (added) cmake/Modules/NormalizeTriple.cmake (+36) - (modified) libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp (-2) - (modified) libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp (-2) - (modified) libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp (-2) - (modified) llvm/cmake/modules/LLVMConfig.cmake.in (+32-37) - (modified) llvm/cmake/modules/LLVMExternalProjectUtils.cmake (+49-15) - (modified) llvm/runtimes/CMakeLists.txt (-4) - (modified) runtimes/CMakeLists.txt (+2-16) ``````````diff diff --git a/clang/cmake/modules/ClangConfig.cmake.in b/clang/cmake/modules/ClangConfig.cmake.in index 68f723d050117..e199c7e17b6b7 100644 --- a/clang/cmake/modules/ClangConfig.cmake.in +++ b/clang/cmake/modules/ClangConfig.cmake.in @@ -13,7 +13,10 @@ set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@") set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@") # Provide all our library targets to users. -@CLANG_CONFIG_INCLUDE_EXPORTS@ +# Skip when cross-compiling, as host library targets are not usable. +if(NOT CMAKE_CROSSCOMPILING) + @CLANG_CONFIG_INCLUDE_EXPORTS@ +endif() # By creating clang-tablegen-targets here, subprojects that depend on Clang's # tablegen-generated headers can always depend on this target whether building diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake b/cmake/Modules/GetTripleCMakeSystemName.cmake new file mode 100644 index 0000000000000..6cd8d3c59324e --- /dev/null +++ b/cmake/Modules/GetTripleCMakeSystemName.cmake @@ -0,0 +1,89 @@ +#===--------------------------------------------------------------------===// +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for details. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===--------------------------------------------------------------------===// + +# Extract the OS component from a target triple and map it to the +# corresponding CMake system name. +# +# Usage: +# get_triple_cmake_system_name(<triple> <out_var>) +# +# Parses the triple (arch-vendor-os[-env]) and sets <out_var> to the +# CMake-style system name (e.g. "Darwin", "Linux", "Windows"). +# Unrecognized OS values are mapped to "Generic". This expects a +# normalized triple. + +function(get_triple_cmake_system_name triple out_var) + string(REPLACE "-" ";" _components "${triple}") + list(LENGTH _components _len) + if(_len LESS 3) + set(${out_var} "${CMAKE_HOST_SYSTEM_NAME}" PARENT_SCOPE) + return() + endif() + + list(GET _components 1 _vendor) + list(GET _components 2 _os) + set(_env "") + if(_len GREATER_EQUAL 4) + list(GET _components 3 _env) + endif() + + # Check the special environment components first, since it can + # override the usual OS mapping. + if("${_env}" MATCHES "^android") + set(${out_var} "Android" PARENT_SCOPE) + elseif("${_env}" MATCHES "^cygnus") + set(${out_var} "CYGWIN" PARENT_SCOPE) + elseif("${_os}" MATCHES "^darwin|^macos") + set(${out_var} "Darwin" PARENT_SCOPE) + elseif("${_os}" MATCHES "^ios") + set(${out_var} "iOS" PARENT_SCOPE) + elseif("${_os}" MATCHES "^tvos") + set(${out_var} "tvOS" PARENT_SCOPE) + elseif("${_os}" MATCHES "^watchos") + set(${out_var} "watchOS" PARENT_SCOPE) + elseif("${_os}" MATCHES "^xros|^visionos") + set(${out_var} "visionOS" PARENT_SCOPE) + elseif("${_vendor}" STREQUAL "apple") + # Catch-all for other Apple triples (e.g. driverkit, bridgeos). + set(${out_var} "Darwin" PARENT_SCOPE) + elseif("${_os}" MATCHES "^linux") + set(${out_var} "Linux" PARENT_SCOPE) + elseif("${_os}" MATCHES "^windows") + set(${out_var} "Windows" PARENT_SCOPE) + elseif("${_os}" MATCHES "^freebsd|^kfreebsd") + set(${out_var} "FreeBSD" PARENT_SCOPE) + elseif("${_os}" MATCHES "^netbsd") + set(${out_var} "NetBSD" PARENT_SCOPE) + elseif("${_os}" MATCHES "^openbsd") + set(${out_var} "OpenBSD" PARENT_SCOPE) + elseif("${_os}" MATCHES "^dragonfly") + set(${out_var} "DragonFly" PARENT_SCOPE) + elseif("${_os}" MATCHES "^solaris") + set(${out_var} "SunOS" PARENT_SCOPE) + elseif("${_os}" MATCHES "^aix") + set(${out_var} "AIX" PARENT_SCOPE) + elseif("${_os}" MATCHES "^fuchsia") + set(${out_var} "Fuchsia" PARENT_SCOPE) + elseif("${_os}" MATCHES "^haiku") + set(${out_var} "Haiku" PARENT_SCOPE) + elseif("${_os}" MATCHES "^emscripten") + set(${out_var} "Emscripten" PARENT_SCOPE) + elseif("${_os}" MATCHES "^wasi") + set(${out_var} "WASI" PARENT_SCOPE) + elseif("${_os}" MATCHES "^rtems") + set(${out_var} "RTEMS" PARENT_SCOPE) + elseif("${_os}" MATCHES "^zos") + set(${out_var} "OS390" PARENT_SCOPE) + elseif("${_os}" MATCHES "^hurd") + set(${out_var} "GNU" PARENT_SCOPE) + elseif("${_os}" MATCHES "^serenity") + set(${out_var} "SerenityOS" PARENT_SCOPE) + else() + set(${out_var} "Generic" PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/Modules/NormalizeTriple.cmake b/cmake/Modules/NormalizeTriple.cmake new file mode 100644 index 0000000000000..08f09a22bdbb0 --- /dev/null +++ b/cmake/Modules/NormalizeTriple.cmake @@ -0,0 +1,36 @@ +#===--------------------------------------------------------------------===// +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for details. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===--------------------------------------------------------------------===// + +# Normalize a target triple using clang's -print-target-triple. +# +# Usage: +# normalize_triple(<compiler> <triple> <out_var>) +# +# Runs <compiler> --target=<triple> -print-target-triple to produce a +# canonical triple. If the compiler invocation fails (e.g. the compiler +# is not clang), <triple> is returned unchanged. + +function(normalize_triple compiler triple out_var) + set(_prefix "") + if(CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") + set(_prefix "/clang:") + endif() + execute_process( + COMMAND "${compiler}" "${_prefix}--target=${triple}" "${_prefix}-print-target-triple" + RESULT_VARIABLE _result + OUTPUT_VARIABLE _output + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + if(_result EQUAL 0 AND _output) + set(${out_var} "${_output}" PARENT_SCOPE) + else() + # TODO(#97876): Report an error. + message(WARNING "Failed to execute `${compiler} ${_prefix}--target=${triple} ${_prefix}-print-target-triple` to normalize target triple.") + set(${out_var} "${triple}" PARENT_SCOPE) + endif() +endfunction() diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp index 3f210aca6b436..17dce2e54ea3d 100644 --- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // [container.adaptors.format] // For each of queue, priority_queue, and stack, the library provides the diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp index 21aab0a2c2f94..4b07dab790f92 100644 --- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // [container.adaptors.format] // For each of queue, priority_queue, and stack, the library provides the diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp index e6691a57f2d11..830ad92d89321 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp index 1529b6ee65beb..41281a6eca458 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp index 0f92158fffe5c..7ab0a30af76e4 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp index 9a4a0f763b707..e591b8178a905 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp index f003123a417be..7d44f9554539f 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp index 9a464e6e38d13..d08e8658f1e10 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp index 3b8dea6031470..bd71bd4c3b0b4 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp index 54332754de6f6..ae85301d91434 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp @@ -8,8 +8,6 @@ // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp index eb267637a0411..f1a9cd8178ab7 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp index 9d206312f3c75..5412a47cd7e35 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp @@ -12,8 +12,6 @@ // XFAIL: availability-fp_to_chars-missing -// Missing mkstemp -// XFAIL: LLVM-LIBC-FIXME // <format> diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in index 300c25e7c6101..6ef0cef7d0296 100644 --- a/llvm/cmake/modules/LLVMConfig.cmake.in +++ b/llvm/cmake/modules/LLVMConfig.cmake.in @@ -56,52 +56,47 @@ set(LLVM_ENABLE_ASSERTIONS @LLVM_ENABLE_ASSERTIONS@) set(LLVM_ENABLE_EH @LLVM_ENABLE_EH@) set(LLVM_ENABLE_FFI @LLVM_ENABLE_FFI@) -if(LLVM_ENABLE_FFI) - find_package(FFI) -endif() - set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@) - -set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@) -if(LLVM_ENABLE_LIBEDIT) - find_package(LibEdit) -endif() - set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@) - set(LLVM_ENABLE_UNWIND_TABLES @LLVM_ENABLE_UNWIND_TABLES@) - set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@) -if(LLVM_ENABLE_ZLIB) - set(ZLIB_ROOT @ZLIB_ROOT@) - find_package(ZLIB) -endif() - set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@) -if(LLVM_ENABLE_ZSTD) - find_package(zstd) -endif() - set(LLVM_ENABLE_LIBXML2 @LLVM_ENABLE_LIBXML2@) -if(LLVM_ENABLE_LIBXML2) - find_package(LibXml2) -endif() - set(LLVM_ENABLE_CURL @LLVM_ENABLE_CURL@) -if(LLVM_ENABLE_CURL) - find_package(CURL) -endif() - set(LLVM_ENABLE_HTTPLIB @LLVM_ENABLE_HTTPLIB@) -if(LLVM_ENABLE_HTTPLIB) - find_package(httplib) -endif() - set(LLVM_WITH_Z3 @LLVM_WITH_Z3@) - set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@) -if(LLVM_ENABLE_DIA_SDK) - find_package(DIASDK) +set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@) + +# These are host libraries that LLVM was built with. Only find them when the +# consumer can actually use them (i.e. not when cross-compiling for an +# incompatible target). +if(NOT CMAKE_CROSSCOMPILING) + if(LLVM_ENABLE_FFI) + find_package(FFI) + endif() + if(LLVM_ENABLE_LIBEDIT) + find_package(LibEdit) + endif() + if(LLVM_ENABLE_ZLIB) + set(ZLIB_ROOT @ZLIB_ROOT@) + find_package(ZLIB) + endif() + if(LLVM_ENABLE_ZSTD) + find_package(zstd) + endif() + if(LLVM_ENABLE_LIBXML2) + find_package(LibXml2) + endif() + if(LLVM_ENABLE_CURL) + find_package(CURL) + endif() + if(LLVM_ENABLE_HTTPLIB) + find_package(httplib) + endif() + if(LLVM_ENABLE_DIA_SDK) + find_package(DIASDK) + endif() endif() set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@) @@ -152,7 +147,7 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@) set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@") set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@") -if(NOT TARGET LLVMSupport) +if(NOT TARGET LLVMSupport AND NOT CMAKE_CROSSCOMPILING) @LLVM_CONFIG_INCLUDE_EXPORTS@ @llvm_config_include_buildtree_only_exports@ endif() diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index 47b12dc9a3d8c..3d32d3cb45d24 100644 --- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -84,12 +84,6 @@ function(llvm_ExternalProject_Add name source_dir) endif() endforeach() - # If CMAKE_SYSTEM_NAME is not set explicitly in the arguments passed to us, - # reflect CMake's own default. - if (NOT _cmake_system_name) - set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}") - endif() - if(NOT ARG_TARGET_TRIPLE) set(target_triple ${LLVM_DEFAULT_TARGET_TRIPLE}) else() @@ -98,6 +92,36 @@ function(llvm_ExternalProject_Add name source_dir) is_msvc_triple(is_msvc_target "${target_triple}") + if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING) + set(_cmake_c_compiler "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}") + set(_cmake_cxx_compiler "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}") + set(_cmake_asm_compiler "${_cmake_c_compiler}") + if(is_msvc_target) + set(_cmake_c_compiler "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}") + set(_cmake_cxx_compiler "${_cmake_c_compiler}") + set(_cmake_asm_compiler "${_cmake_c_compiler}") + endif() + else() + set(_cmake_c_compiler "${CMAKE_C_COMPILER}") + set(_cmake_cxx_compiler "${CMAKE_CXX_COMPILER}") + set(_cmake_asm_compiler "${CMAKE_C_COMPILER}") + endif() + + # If CMAKE_SYSTEM_NAME is not set explicitly in the arguments passed to us, + # derive it from the target triple if available, otherwise reflect CMake's + # own default. This ensures that cross-compilation targets get the correct + # platform files (e.g. AMDGPU targets on a Darwin host won't get macOS flags). + if (NOT _cmake_system_name) + if(ARG_TARGET_TRIPLE) + include(NormalizeTriple) + normalize_triple("${_cmake_c_compiler}" "${ARG_TARGET_TRIPLE}" _normalized_triple) + include(GetTripleCMakeSystemName) + get_triple_cmake_system_name("${_normalized_triple}" _cmake_system_name) + else() + set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}") + endif() + endif() + if(NOT ARG_TOOLCHAIN_TOOLS) set(ARG_TOOLCHAIN_TOOLS clang) # AIX 64-bit XCOFF and big AR format is not yet supported in some of these tools. @@ -228,15 +252,9 @@ function(llvm_ExternalProject_Add name source_dir) if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING) if(CLANG_IN_TOOLCHAIN) - if(is_msvc_target) - set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}) - else() - set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}) - endif() + set(compiler_args -DCMAKE_C_COMPILER=${_cmake_c_compiler} + -DCMAKE_CXX_COMPILER=${_cmake_cxx_compiler} + -DCMAKE_ASM_COMPILER=${_cmake_asm_compiler}) endif() if(FLANG_IN_TOOLCHAIN) list(APPEND compiler_args -DCMAKE_Fortran_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/flang${CMAKE_EXECUTABLE_SUFFIX}) @@ -376,6 +394,22 @@ function(llvm_ExternalProject_Add name source_dir) list(APPEND compiler_args -DCMAKE_CXX_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) list(APPEND compiler_args -DCMAKE_Fortran_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) list(APPEND compiler_args -DCMAKE_ASM_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) + + # Pass CMAKE_SYSTEM_NAME derived from the target triple so the sub-build + # loads the correct platform files instead of the host's. + if(NOT "${_cmake_system_name}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}") + list(APPEND compiler_args -DCMAKE_SYSTEM_NAME=${_cmake_system_name}) + endif() + + # Forward Darwin-specific variables only when targeting Darwin. + if("${_cmake_system_name}" STREQUAL "Darwin") + if(CMAKE_OSX_SYSROOT) + list(APPEND compiler_args -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}) + endif() + if(CMAKE_OSX_DEPLOYMENT_TARGET) + list(APPEND compiler_args -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif()... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/203504 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
