Files
TheRock/compiler/amd-llvm/compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

81 lines
3.2 KiB
CMake

# This macro mocks enough of the changes `LLVMConfig.cmake` makes so that
# compiler-rt can successfully configure itself when a LLVM toolchain is
# available but the corresponding CMake build files are not.
#
# The motivation for this is to be able to generate the compiler-rt
# lit tests suites and run them against an arbitrary LLVM toolchain
# which doesn't ship the LLVM CMake build files.
macro(compiler_rt_mock_llvm_cmake_config)
message(STATUS "Attempting to mock the changes made by LLVMConfig.cmake")
compiler_rt_mock_llvm_cmake_config_set_cmake_path()
compiler_rt_mock_llvm_cmake_config_set_target_triple()
compiler_rt_mock_llvm_cmake_config_include_cmake_files()
endmacro()
macro(compiler_rt_mock_llvm_cmake_config_set_cmake_path)
# Point `LLVM_CMAKE_DIR` at the source tree in the monorepo.
set(LLVM_CMAKE_DIR "${LLVM_MAIN_SRC_DIR}/cmake/modules")
if (NOT EXISTS "${LLVM_CMAKE_DIR}")
message(FATAL_ERROR "LLVM_CMAKE_DIR (${LLVM_CMAKE_DIR}) does not exist")
endif()
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
message(STATUS "LLVM_CMAKE_DIR: \"${LLVM_CMAKE_DIR}\"")
endmacro()
function(compiler_rt_mock_llvm_cmake_config_set_target_triple)
# Various bits of compiler-rt depend on the `LLVM_TARGET_TRIPLE` variable
# being defined. This function tries to set a sensible value for the
# variable. This is a function rather than a macro to avoid polluting the
# variable namespace.
set(COMPILER_OUTPUT "")
# If the user provides `COMPILER_RT_DEFAULT_TARGET_ONLY` and `CMAKE_C_COMPILER_TARGET`
# (see `construct_compiler_rt_default_triple`) then prefer that to examining the
# compiler.
if (COMPILER_RT_DEFAULT_TARGET_ONLY)
if (NOT "${CMAKE_C_COMPILER_TARGET}" STREQUAL "")
message(STATUS
"Using CMAKE_C_COMPILER_TARGET (${CMAKE_C_COMPILER_TARGET}) as LLVM_TARGET_TRIPLE")
endif()
set(COMPILER_OUTPUT "${CMAKE_C_COMPILER_TARGET}")
endif()
# Try asking the compiler for its default target triple.
set(HAD_ERROR FALSE)
if ("${COMPILER_OUTPUT}" STREQUAL "")
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang|GNU")
# Note: Clang also supports `-print-target-triple` but gcc doesn't
# support this flag.
set(DUMPMACHINE_ARG -dumpmachine)
if(MSVC)
# Use /clang:-dumpmachine for clang-cl.
set(DUMPMACHINE_ARG /clang:-dumpmachine)
endif()
execute_process(
COMMAND "${CMAKE_C_COMPILER}" ${DUMPMACHINE_ARG}
RESULT_VARIABLE HAD_ERROR
OUTPUT_VARIABLE COMPILER_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
message(FATAL_ERROR
"Fetching target triple from compiler \"${CMAKE_C_COMPILER_ID}\" "
"is not implemented.")
endif()
endif()
if (HAD_ERROR)
message(FATAL_ERROR "Fetching target triple from compiler failed")
endif()
set(LLVM_TARGET_TRIPLE "${COMPILER_OUTPUT}")
message(STATUS "TARGET_TRIPLE: \"${LLVM_TARGET_TRIPLE}\"")
if ("${LLVM_TARGET_TRIPLE}" STREQUAL "")
message(FATAL_ERROR "TARGET_TRIPLE cannot be empty")
endif()
set(LLVM_TARGET_TRIPLE "${LLVM_TARGET_TRIPLE}" PARENT_SCOPE)
endfunction()
macro(compiler_rt_mock_llvm_cmake_config_include_cmake_files)
# Some compiler-rt CMake code needs to call code in this file.
include("${LLVM_CMAKE_DIR}/AddLLVM.cmake")
endmacro()