2016-04-28 18:22:01 +00:00
|
|
|
include(CMakePushCheckState)
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
2013-01-18 16:05:21 +00:00
|
|
|
# Because compiler-rt spends a lot of time setting up custom compile flags,
|
|
|
|
# define a handy helper function for it. The compile flags setting in CMake
|
|
|
|
# has serious issues that make its syntax challenging at best.
|
|
|
|
function(set_target_compile_flags target)
|
2022-03-30 10:33:40 -07:00
|
|
|
set_property(TARGET ${target} PROPERTY COMPILE_OPTIONS ${ARGN})
|
2013-01-18 16:05:21 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(set_target_link_flags target)
|
2022-03-30 10:33:40 -07:00
|
|
|
set_property(TARGET ${target} PROPERTY LINK_OPTIONS ${ARGN})
|
2013-01-18 16:05:21 +00:00
|
|
|
endfunction()
|
|
|
|
|
2013-10-25 23:03:34 +00:00
|
|
|
# Set the variable var_PYBOOL to True if var holds a true-ish string,
|
|
|
|
# otherwise set it to False.
|
|
|
|
macro(pythonize_bool var)
|
|
|
|
if (${var})
|
|
|
|
set(${var}_PYBOOL True)
|
|
|
|
else()
|
|
|
|
set(${var}_PYBOOL False)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2014-02-18 07:52:40 +00:00
|
|
|
|
2014-03-13 09:31:36 +00:00
|
|
|
# Appends value to all lists in ARGN, if the condition is true.
|
2014-10-15 22:47:54 +00:00
|
|
|
macro(append_list_if condition value)
|
2014-03-13 09:31:36 +00:00
|
|
|
if(${condition})
|
|
|
|
foreach(list ${ARGN})
|
|
|
|
list(APPEND ${list} ${value})
|
|
|
|
endforeach()
|
2014-02-18 07:52:40 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2014-03-13 11:31:10 +00:00
|
|
|
# Appends value to all strings in ARGN, if the condition is true.
|
|
|
|
macro(append_string_if condition value)
|
|
|
|
if(${condition})
|
|
|
|
foreach(str ${ARGN})
|
|
|
|
set(${str} "${${str}} ${value}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2016-03-05 10:01:04 +00:00
|
|
|
macro(append_rtti_flag polarity list)
|
2016-08-22 18:30:37 +00:00
|
|
|
if(${polarity})
|
2016-03-05 10:01:04 +00:00
|
|
|
append_list_if(COMPILER_RT_HAS_FRTTI_FLAG -frtti ${list})
|
|
|
|
append_list_if(COMPILER_RT_HAS_GR_FLAG /GR ${list})
|
|
|
|
else()
|
|
|
|
append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
|
|
|
|
append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
|
|
|
|
endif()
|
2014-02-18 07:52:40 +00:00
|
|
|
endmacro()
|
2015-04-09 08:06:49 +00:00
|
|
|
|
2016-01-27 09:28:01 +00:00
|
|
|
macro(list_intersect output input1 input2)
|
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-13 20:38:16 +00:00
|
|
|
set(${output})
|
|
|
|
foreach(it ${${input1}})
|
|
|
|
list(FIND ${input2} ${it} index)
|
|
|
|
if( NOT (index EQUAL -1))
|
|
|
|
list(APPEND ${output} ${it})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2016-02-17 16:57:38 +00:00
|
|
|
|
2016-08-19 15:13:21 +00:00
|
|
|
function(list_replace input_list old new)
|
|
|
|
set(replaced_list)
|
|
|
|
foreach(item ${${input_list}})
|
|
|
|
if(${item} STREQUAL ${old})
|
|
|
|
list(APPEND replaced_list ${new})
|
|
|
|
else()
|
|
|
|
list(APPEND replaced_list ${item})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${input_list} "${replaced_list}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2016-02-17 16:57:38 +00:00
|
|
|
# Takes ${ARGN} and puts only supported architectures in @out_var list.
|
|
|
|
function(filter_available_targets out_var)
|
|
|
|
set(archs ${${out_var}})
|
|
|
|
foreach(arch ${ARGN})
|
|
|
|
list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
|
|
|
|
if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
|
|
|
|
list(APPEND archs ${arch})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${out_var} ${archs} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2016-12-12 23:14:02 +00:00
|
|
|
# Add $arch as supported with no additional flags.
|
|
|
|
macro(add_default_target_arch arch)
|
|
|
|
set(TARGET_${arch}_CFLAGS "")
|
|
|
|
set(CAN_TARGET_${arch} 1)
|
|
|
|
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
|
|
|
endmacro()
|
|
|
|
|
2016-02-17 16:57:38 +00:00
|
|
|
function(check_compile_definition def argstring out_var)
|
|
|
|
if("${def}" STREQUAL "")
|
|
|
|
set(${out_var} TRUE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
cmake_push_check_state()
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
|
|
|
|
check_symbol_exists(${def} "" ${out_var})
|
|
|
|
cmake_pop_check_state()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# test_target_arch(<arch> <def> <target flags...>)
|
|
|
|
# Checks if architecture is supported: runs host compiler with provided
|
|
|
|
# flags to verify that:
|
|
|
|
# 1) <def> is defined (if non-empty)
|
|
|
|
# 2) simple file can be successfully built.
|
|
|
|
# If successful, saves target flags for this architecture.
|
|
|
|
macro(test_target_arch arch def)
|
|
|
|
set(TARGET_${arch}_CFLAGS ${ARGN})
|
2017-01-10 04:33:04 +00:00
|
|
|
set(TARGET_${arch}_LINK_FLAGS ${ARGN})
|
2016-02-17 16:57:38 +00:00
|
|
|
set(argstring "")
|
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
|
2016-07-22 10:15:09 +00:00
|
|
|
if(NOT DEFINED CAN_TARGET_${arch})
|
|
|
|
if(NOT HAS_${arch}_DEF)
|
|
|
|
set(CAN_TARGET_${arch} FALSE)
|
|
|
|
elseif(TEST_COMPILE_ONLY)
|
2022-06-22 16:10:33 +03:00
|
|
|
try_compile_only(CAN_TARGET_${arch}
|
|
|
|
SOURCE "#include <limits.h>\nint foo(int x, int y) { return x + y; }\n"
|
|
|
|
FLAGS ${TARGET_${arch}_CFLAGS})
|
2016-07-22 10:15:09 +00:00
|
|
|
else()
|
2016-09-21 05:44:06 +00:00
|
|
|
set(FLAG_NO_EXCEPTIONS "")
|
|
|
|
if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
|
|
|
|
set(FLAG_NO_EXCEPTIONS " -fno-exceptions ")
|
|
|
|
endif()
|
[compiler-rt] respect CMAKE_EXE_LINKER_FLAGS in compiler and library tests
Summary: check_cxx_compiler_flag and check_library_exists could fail because they ignored CMAKE_EXE_LINKER_FLAGS and therefore would always fail to produce executables. Cmake policy CMP0056 fixes this, but was explicitly set to OLD in our CMakeLists because it caused problems with test_target_arch. This change sets the policy to NEW to fix the problem with the compiler and library tests, and temporarily clears CMAKE_EXE_LINKER_FLAGS inside test_target_arch to emulate the old behavior there. This allows, for example, LTO builds that require lld to succeed.
Reviewers: davidxl, beanz
Reviewed By: beanz
Subscribers: fjricci, dberris, mgorny, mehdi_amini, tejohnson, rnk, llvm-commits
Differential Revision: https://reviews.llvm.org/D31098
llvm-svn: 298413
2017-03-21 18:25:35 +00:00
|
|
|
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
|
2018-06-17 09:51:33 +00:00
|
|
|
try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
|
2016-09-21 05:44:06 +00:00
|
|
|
COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS} ${FLAG_NO_EXCEPTIONS}"
|
[compiler-rt] respect CMAKE_EXE_LINKER_FLAGS in compiler and library tests
Summary: check_cxx_compiler_flag and check_library_exists could fail because they ignored CMAKE_EXE_LINKER_FLAGS and therefore would always fail to produce executables. Cmake policy CMP0056 fixes this, but was explicitly set to OLD in our CMakeLists because it caused problems with test_target_arch. This change sets the policy to NEW to fix the problem with the compiler and library tests, and temporarily clears CMAKE_EXE_LINKER_FLAGS inside test_target_arch to emulate the old behavior there. This allows, for example, LTO builds that require lld to succeed.
Reviewers: davidxl, beanz
Reviewed By: beanz
Subscribers: fjricci, dberris, mgorny, mehdi_amini, tejohnson, rnk, llvm-commits
Differential Revision: https://reviews.llvm.org/D31098
llvm-svn: 298413
2017-03-21 18:25:35 +00:00
|
|
|
OUTPUT_VARIABLE TARGET_${arch}_OUTPUT)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
|
2016-07-22 10:15:09 +00:00
|
|
|
endif()
|
2016-02-17 16:57:38 +00:00
|
|
|
endif()
|
|
|
|
if(${CAN_TARGET_${arch}})
|
|
|
|
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
2016-07-20 18:06:31 +00:00
|
|
|
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND
|
2016-02-17 16:57:38 +00:00
|
|
|
COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
|
|
|
|
# Bail out if we cannot target the architecture we plan to test.
|
|
|
|
message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2016-06-03 17:34:02 +00:00
|
|
|
|
2020-07-14 15:04:30 -07:00
|
|
|
macro(detect_target_arch)
|
2024-07-10 15:07:11 -05:00
|
|
|
check_symbol_exists(__AMDGPU__ "" __AMDGPU)
|
2020-07-14 15:04:30 -07:00
|
|
|
check_symbol_exists(__arm__ "" __ARM)
|
2022-04-06 10:45:50 +00:00
|
|
|
check_symbol_exists(__AVR__ "" __AVR)
|
2020-07-14 15:04:30 -07:00
|
|
|
check_symbol_exists(__aarch64__ "" __AARCH64)
|
|
|
|
check_symbol_exists(__x86_64__ "" __X86_64)
|
|
|
|
check_symbol_exists(__i386__ "" __I386)
|
2024-07-12 20:10:03 -05:00
|
|
|
check_symbol_exists(__hexagon__ "" __HEXAGON)
|
2022-11-01 20:08:06 +08:00
|
|
|
check_symbol_exists(__loongarch__ "" __LOONGARCH)
|
2020-07-14 15:04:30 -07:00
|
|
|
check_symbol_exists(__mips__ "" __MIPS)
|
|
|
|
check_symbol_exists(__mips64__ "" __MIPS64)
|
2024-07-10 15:07:11 -05:00
|
|
|
check_symbol_exists(__NVPTX__ "" __NVPTX)
|
2020-09-03 11:40:13 -04:00
|
|
|
check_symbol_exists(__powerpc__ "" __PPC)
|
2020-07-14 15:04:30 -07:00
|
|
|
check_symbol_exists(__powerpc64__ "" __PPC64)
|
|
|
|
check_symbol_exists(__powerpc64le__ "" __PPC64LE)
|
|
|
|
check_symbol_exists(__riscv "" __RISCV)
|
|
|
|
check_symbol_exists(__s390x__ "" __S390X)
|
|
|
|
check_symbol_exists(__sparc "" __SPARC)
|
|
|
|
check_symbol_exists(__sparcv9 "" __SPARCV9)
|
|
|
|
check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
|
|
|
|
check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
|
|
|
|
check_symbol_exists(__ve__ "" __VE)
|
2024-07-10 15:07:11 -05:00
|
|
|
if(__AMDGPU)
|
|
|
|
add_default_target_arch(amdgcn)
|
|
|
|
elseif(__ARM)
|
2020-07-14 15:04:30 -07:00
|
|
|
add_default_target_arch(arm)
|
2022-04-06 10:45:50 +00:00
|
|
|
elseif(__AVR)
|
|
|
|
add_default_target_arch(avr)
|
2020-07-14 15:04:30 -07:00
|
|
|
elseif(__AARCH64)
|
|
|
|
add_default_target_arch(aarch64)
|
|
|
|
elseif(__X86_64)
|
2021-06-11 19:44:04 +01:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL "4")
|
|
|
|
add_default_target_arch(x32)
|
|
|
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL "8")
|
|
|
|
add_default_target_arch(x86_64)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported pointer size for X86_64")
|
|
|
|
endif()
|
2024-07-12 20:10:03 -05:00
|
|
|
elseif(__HEXAGON)
|
|
|
|
add_default_target_arch(hexagon)
|
2020-07-14 15:04:30 -07:00
|
|
|
elseif(__I386)
|
|
|
|
add_default_target_arch(i386)
|
2022-11-01 20:08:06 +08:00
|
|
|
elseif(__LOONGARCH)
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL "4")
|
|
|
|
add_default_target_arch(loongarch32)
|
|
|
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL "8")
|
|
|
|
add_default_target_arch(loongarch64)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported pointer size for LoongArch")
|
|
|
|
endif()
|
2020-07-14 15:04:30 -07:00
|
|
|
elseif(__MIPS64) # must be checked before __MIPS
|
|
|
|
add_default_target_arch(mips64)
|
|
|
|
elseif(__MIPS)
|
|
|
|
add_default_target_arch(mips)
|
2024-07-10 15:07:11 -05:00
|
|
|
elseif(__NVPTX)
|
|
|
|
add_default_target_arch(nvptx64)
|
2020-09-03 11:40:13 -04:00
|
|
|
elseif(__PPC64) # must be checked before __PPC
|
2020-07-14 15:04:30 -07:00
|
|
|
add_default_target_arch(powerpc64)
|
|
|
|
elseif(__PPC64LE)
|
|
|
|
add_default_target_arch(powerpc64le)
|
2020-09-03 11:40:13 -04:00
|
|
|
elseif(__PPC)
|
|
|
|
add_default_target_arch(powerpc)
|
2020-07-14 15:04:30 -07:00
|
|
|
elseif(__RISCV)
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL "4")
|
|
|
|
add_default_target_arch(riscv32)
|
|
|
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL "8")
|
|
|
|
add_default_target_arch(riscv64)
|
|
|
|
else()
|
2025-03-28 12:51:13 -07:00
|
|
|
message(FATAL_ERROR "Unsupported XLEN for RISC-V")
|
2020-07-14 15:04:30 -07:00
|
|
|
endif()
|
|
|
|
elseif(__S390X)
|
|
|
|
add_default_target_arch(s390x)
|
|
|
|
elseif(__SPARCV9)
|
|
|
|
add_default_target_arch(sparcv9)
|
|
|
|
elseif(__SPARC)
|
|
|
|
add_default_target_arch(sparc)
|
|
|
|
elseif(__WEBASSEMBLY32)
|
|
|
|
add_default_target_arch(wasm32)
|
|
|
|
elseif(__WEBASSEMBLY64)
|
|
|
|
add_default_target_arch(wasm64)
|
|
|
|
elseif(__VE)
|
|
|
|
add_default_target_arch(ve)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2021-03-30 12:50:59 -07:00
|
|
|
function(get_compiler_rt_root_source_dir ROOT_DIR_VAR)
|
|
|
|
# Compute the path to the root of the Compiler-RT source tree
|
|
|
|
# regardless of how the project was configured.
|
|
|
|
#
|
|
|
|
# This function is useful because using `${CMAKE_SOURCE_DIR}`
|
|
|
|
# is error prone due to the numerous ways Compiler-RT can be
|
|
|
|
# configured.
|
|
|
|
#
|
|
|
|
# `ROOT_DIR_VAR` - the name of the variable to write the result to.
|
|
|
|
#
|
|
|
|
# TODO(dliew): When CMake min version is 3.17 or newer use
|
|
|
|
# `CMAKE_CURRENT_FUNCTION_LIST_DIR` instead.
|
|
|
|
if ("${ROOT_DIR_VAR}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "ROOT_DIR_VAR cannot be empty")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Compiler-rt supports different source root paths.
|
|
|
|
# Handle each case here.
|
|
|
|
set(PATH_TO_COMPILER_RT_SOURCE_ROOT "")
|
|
|
|
if (DEFINED CompilerRTBuiltins_SOURCE_DIR)
|
|
|
|
# Compiler-RT Builtins standalone build.
|
|
|
|
# `llvm-project/compiler-rt/lib/builtins`
|
|
|
|
set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRTBuiltins_SOURCE_DIR}/../../")
|
2022-02-28 12:21:11 -08:00
|
|
|
elseif (DEFINED CompilerRTCRT_SOURCE_DIR)
|
|
|
|
# Compiler-RT CRT standalone build.
|
|
|
|
# `llvm-project/compiler-rt/lib/crt`
|
|
|
|
set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRTCRT_SOURCE_DIR}/../../")
|
2021-03-30 12:50:59 -07:00
|
|
|
elseif(DEFINED CompilerRT_SOURCE_DIR)
|
|
|
|
# Compiler-RT standalone build.
|
|
|
|
# `llvm-project/compiler-rt`
|
|
|
|
set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRT_SOURCE_DIR}")
|
|
|
|
elseif (EXISTS "${CMAKE_SOURCE_DIR}/../compiler-rt")
|
|
|
|
# In tree build with LLVM as the root project.
|
|
|
|
# See `llvm-project/projects/`.
|
|
|
|
# Assumes monorepo layout.
|
|
|
|
set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/../compiler-rt")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unhandled Compiler-RT source root configuration.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_filename_component(ROOT_DIR "${PATH_TO_COMPILER_RT_SOURCE_ROOT}" ABSOLUTE)
|
|
|
|
if (NOT EXISTS "${ROOT_DIR}")
|
|
|
|
message(FATAL_ERROR "Path \"${ROOT_DIR}\" doesn't exist")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Sanity check: Make sure we can locate the current source file via the
|
|
|
|
# computed path.
|
|
|
|
set(PATH_TO_CURRENT_FILE "${ROOT_DIR}/cmake/Modules/CompilerRTUtils.cmake")
|
|
|
|
if (NOT EXISTS "${PATH_TO_CURRENT_FILE}")
|
|
|
|
message(FATAL_ERROR "Could not find \"${PATH_TO_CURRENT_FILE}\"")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set("${ROOT_DIR_VAR}" "${ROOT_DIR}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2016-08-02 05:51:05 +00:00
|
|
|
macro(load_llvm_config)
|
2022-10-29 19:03:37 +02:00
|
|
|
if (LLVM_CONFIG_PATH AND NOT LLVM_CMAKE_DIR)
|
|
|
|
message(WARNING
|
|
|
|
"LLVM_CONFIG_PATH is deprecated, please use LLVM_CMAKE_DIR instead")
|
|
|
|
# Compute the path to the LLVM install prefix and pass it as LLVM_CMAKE_DIR,
|
|
|
|
# CMake will locate the appropriate lib*/cmake subdirectory from there.
|
|
|
|
# For example. for -DLLVM_CONFIG_PATH=/usr/lib/llvm/16/bin/llvm-config
|
|
|
|
# this will yield LLVM_CMAKE_DIR=/usr/lib/llvm/16.
|
|
|
|
get_filename_component(LLVM_CMAKE_DIR "${LLVM_CONFIG_PATH}" DIRECTORY)
|
|
|
|
get_filename_component(LLVM_CMAKE_DIR "${LLVM_CMAKE_DIR}" DIRECTORY)
|
2022-11-01 05:49:24 +01:00
|
|
|
endif()
|
|
|
|
|
2021-03-30 12:50:59 -07:00
|
|
|
# Compute path to LLVM sources assuming the monorepo layout.
|
|
|
|
# We don't set `LLVM_MAIN_SRC_DIR` directly to avoid overriding a user provided
|
|
|
|
# CMake cache value.
|
|
|
|
get_compiler_rt_root_source_dir(COMPILER_RT_ROOT_SRC_PATH)
|
|
|
|
get_filename_component(LLVM_MAIN_SRC_DIR_DEFAULT "${COMPILER_RT_ROOT_SRC_PATH}/../llvm" ABSOLUTE)
|
|
|
|
if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_DEFAULT}")
|
|
|
|
# TODO(dliew): Remove this legacy fallback path.
|
|
|
|
message(WARNING
|
|
|
|
"LLVM source tree not found at \"${LLVM_MAIN_SRC_DIR_DEFAULT}\". "
|
|
|
|
"You are not using the monorepo layout. This configuration is DEPRECATED.")
|
|
|
|
endif()
|
|
|
|
|
2022-10-29 19:03:37 +02:00
|
|
|
find_package(LLVM HINTS "${LLVM_CMAKE_DIR}")
|
|
|
|
if (NOT LLVM_FOUND)
|
|
|
|
message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
|
|
|
|
"LLVM cmake package not found.\n"
|
|
|
|
"Reconfigure with -DLLVM_CMAKE_DIR=/path/to/llvm.")
|
|
|
|
else()
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
|
|
|
|
# Turn into CACHE PATHs for overwritting
|
|
|
|
set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
|
|
|
|
set(LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE PATH "Path to llvm/lib")
|
|
|
|
set(LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin")
|
|
|
|
set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
|
|
|
|
|
|
|
|
list(FIND LLVM_AVAILABLE_LIBS LLVMXRay XRAY_INDEX)
|
|
|
|
set(COMPILER_RT_HAS_LLVMXRAY TRUE)
|
|
|
|
if (XRAY_INDEX EQUAL -1)
|
|
|
|
message(WARNING "LLVMXRay not found in LLVM_AVAILABLE_LIBS")
|
[XRay] Clean up XRay build configuration
Summary:
This change spans both LLVM and compiler-rt, where we do the following:
- Add XRay to the LLVMBuild system, to allow for distributing the XRay
trace loading library along with the LLVM distributions.
- Use `llvm-config` better in the compiler-rt XRay implementation, to
depend on the potentially already-distributed LLVM XRay library.
While this is tested with the standalone compiler-rt build, it does
require that the LLVMXRay library (and LLVMSupport as well) are
available during the build. In case the static libraries are available,
the unit tests will build and work fine. We're still having issues with
attempting to use a shared library version of the LLVMXRay library since
the shared library might not be accessible from the standard shared
library lookup paths.
The larger change here is the inclusion of the LLVMXRay library in the
distribution, which allows for building tools around the XRay traces and
profiles that the XRay runtime already generates.
Reviewers: echristo, beanz
Subscribers: mgorny, hiraditya, mboerger, llvm-commits
Differential Revision: https://reviews.llvm.org/D52349
llvm-svn: 342859
2018-09-24 05:28:01 +00:00
|
|
|
set(COMPILER_RT_HAS_LLVMXRAY FALSE)
|
|
|
|
endif()
|
|
|
|
|
2022-10-29 19:03:37 +02:00
|
|
|
list(FIND LLVM_AVAILABLE_LIBS LLVMTestingSupport TESTINGSUPPORT_INDEX)
|
|
|
|
set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
|
|
|
|
if (TESTINGSUPPORT_INDEX EQUAL -1)
|
|
|
|
message(WARNING "LLVMTestingSupport not found in LLVM_AVAILABLE_LIBS")
|
|
|
|
set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
|
2022-11-01 05:49:24 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
2022-10-29 19:03:37 +02:00
|
|
|
|
2022-10-29 19:03:37 +02:00
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR
|
|
|
|
${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
|
2021-03-30 12:50:59 -07:00
|
|
|
set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree")
|
|
|
|
message(STATUS "LLVM_MAIN_SRC_DIR: \"${LLVM_MAIN_SRC_DIR}\"")
|
|
|
|
if (NOT EXISTS "${LLVM_MAIN_SRC_DIR}")
|
|
|
|
# TODO(dliew): Make this a hard error
|
|
|
|
message(WARNING "LLVM_MAIN_SRC_DIR (${LLVM_MAIN_SRC_DIR}) does not exist. "
|
|
|
|
"You can override the inferred path by adding "
|
|
|
|
"`-DLLVM_MAIN_SRC_DIR=<path_to_llvm_src>` to your CMake invocation "
|
|
|
|
"where `<path_to_llvm_src>` is the path to the `llvm` directory in "
|
|
|
|
"the `llvm-project` repo. "
|
|
|
|
"This will be treated as error in the future.")
|
|
|
|
endif()
|
2021-03-30 13:47:07 -07:00
|
|
|
|
2022-10-29 19:03:37 +02:00
|
|
|
if (NOT LLVM_FOUND)
|
2021-03-30 13:47:07 -07:00
|
|
|
# This configuration tries to configure without the prescence of `LLVMConfig.cmake`. It is
|
|
|
|
# intended for testing purposes (generating the lit test suites) and will likely not support
|
|
|
|
# a build of the runtimes in compiler-rt.
|
|
|
|
include(CompilerRTMockLLVMCMakeConfig)
|
|
|
|
compiler_rt_mock_llvm_cmake_config()
|
|
|
|
endif()
|
|
|
|
|
2016-08-02 05:51:05 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(construct_compiler_rt_default_triple)
|
2016-12-12 23:14:02 +00:00
|
|
|
if(COMPILER_RT_DEFAULT_TARGET_ONLY)
|
|
|
|
if(DEFINED COMPILER_RT_DEFAULT_TARGET_TRIPLE)
|
|
|
|
message(FATAL_ERROR "COMPILER_RT_DEFAULT_TARGET_TRIPLE isn't supported when building for default target only")
|
|
|
|
endif()
|
2023-04-05 09:00:54 +00:00
|
|
|
if ("${CMAKE_C_COMPILER_TARGET}" STREQUAL "")
|
2023-05-02 10:31:37 +02:00
|
|
|
message(FATAL_ERROR "CMAKE_C_COMPILER_TARGET must also be set when COMPILER_RT_DEFAULT_TARGET_ONLY is ON")
|
2023-04-05 09:00:54 +00:00
|
|
|
endif()
|
|
|
|
message(STATUS "cmake c compiler target: ${CMAKE_C_COMPILER_TARGET}")
|
2024-04-15 00:12:42 +08:00
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET})
|
2016-12-12 23:14:02 +00:00
|
|
|
else()
|
2024-04-15 00:12:42 +08:00
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${LLVM_TARGET_TRIPLE} CACHE STRING
|
|
|
|
"Default triple for which compiler-rt runtimes will be built.")
|
2016-12-12 23:14:02 +00:00
|
|
|
endif()
|
|
|
|
|
2024-07-05 22:56:15 -07:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2024-05-02 18:27:23 +05:00
|
|
|
set(option_prefix "")
|
|
|
|
if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
|
|
|
|
set(option_prefix "/clang:")
|
|
|
|
endif()
|
2024-07-05 22:56:15 -07:00
|
|
|
set(print_target_triple ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple)
|
|
|
|
execute_process(COMMAND ${print_target_triple}
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
OUTPUT_VARIABLE output
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
if(result EQUAL 0)
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${output})
|
|
|
|
else()
|
|
|
|
string(REPLACE ";" " " print_target_triple "${print_target_triple}")
|
|
|
|
# TODO(#97876): Report an error.
|
|
|
|
message(WARNING "Failed to execute `${print_target_triple}` to normalize target triple.")
|
|
|
|
endif()
|
2024-04-19 11:19:36 +08:00
|
|
|
endif()
|
|
|
|
|
2021-12-02 01:04:46 -08:00
|
|
|
string(REPLACE "-" ";" LLVM_TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
|
|
|
|
list(GET LLVM_TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
|
2021-03-08 13:38:52 +02:00
|
|
|
|
|
|
|
# Map various forms of the architecture names to the canonical forms
|
|
|
|
# (as they are used by clang, see getArchNameForCompilerRTLib).
|
|
|
|
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "^i.86$")
|
|
|
|
# Android uses i686, but that's remapped at a later stage.
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_ARCH "i386")
|
|
|
|
endif()
|
|
|
|
|
2024-07-10 15:07:11 -05:00
|
|
|
# If we are directly targeting a GPU we need to check that the compiler is
|
|
|
|
# compatible and pass some default arguments.
|
|
|
|
if(COMPILER_RT_DEFAULT_TARGET_ONLY)
|
|
|
|
|
|
|
|
# Pass the necessary flags to make flag detection work.
|
|
|
|
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
|
|
|
|
set(COMPILER_RT_GPU_BUILD ON)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
|
|
|
|
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx")
|
|
|
|
set(COMPILER_RT_GPU_BUILD ON)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS
|
|
|
|
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-08-02 05:51:05 +00:00
|
|
|
# Determine if test target triple is specified explicitly, and doesn't match the
|
|
|
|
# default.
|
2021-12-02 01:04:46 -08:00
|
|
|
if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL LLVM_TARGET_TRIPLE)
|
2016-08-02 05:51:05 +00:00
|
|
|
set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE)
|
|
|
|
else()
|
|
|
|
set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2017-08-30 17:12:57 +00:00
|
|
|
|
2020-06-18 23:59:36 -07:00
|
|
|
# Filter out generic versions of routines that are re-implemented in an
|
|
|
|
# architecture specific manner. This prevents multiple definitions of the same
|
|
|
|
# symbols, making the symbol selection non-deterministic.
|
|
|
|
#
|
|
|
|
# We follow the convention that a source file that exists in a sub-directory
|
|
|
|
# (e.g. `ppc/divtc3.c`) is architecture-specific and that if a generic
|
|
|
|
# implementation exists it will be a top-level source file with the same name
|
|
|
|
# modulo the file extension (e.g. `divtc3.c`).
|
|
|
|
function(filter_builtin_sources inout_var name)
|
|
|
|
set(intermediate ${${inout_var}})
|
|
|
|
foreach(_file ${intermediate})
|
|
|
|
get_filename_component(_file_dir ${_file} DIRECTORY)
|
|
|
|
if (NOT "${_file_dir}" STREQUAL "")
|
|
|
|
# Architecture specific file. If a generic version exists, print a notice
|
|
|
|
# and ensure that it is removed from the file list.
|
2017-08-30 17:12:57 +00:00
|
|
|
get_filename_component(_name ${_file} NAME)
|
2020-06-18 23:59:36 -07:00
|
|
|
string(REGEX REPLACE "\\.S$" ".c" _cname "${_name}")
|
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_cname}")
|
|
|
|
message(STATUS "For ${name} builtins preferring ${_file} to ${_cname}")
|
|
|
|
list(REMOVE_ITEM intermediate ${_cname})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${inout_var} ${intermediate} PARENT_SCOPE)
|
2017-08-30 17:12:57 +00:00
|
|
|
endfunction()
|
2018-06-28 03:11:52 +00:00
|
|
|
|
|
|
|
function(get_compiler_rt_target arch variable)
|
2018-08-14 18:01:19 +00:00
|
|
|
string(FIND ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} "-" dash_index)
|
|
|
|
string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${dash_index} -1 triple_suffix)
|
2022-10-18 04:49:25 +00:00
|
|
|
string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} 0 ${dash_index} triple_cpu)
|
2018-11-16 04:14:23 +00:00
|
|
|
if(COMPILER_RT_DEFAULT_TARGET_ONLY)
|
|
|
|
# Use exact spelling when building only for the target specified to CMake.
|
|
|
|
set(target "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
|
|
|
|
elseif(ANDROID AND ${arch} STREQUAL "i386")
|
2020-06-18 23:57:08 -07:00
|
|
|
set(target "i686${triple_suffix}")
|
2022-09-11 11:25:53 +02:00
|
|
|
elseif(${arch} STREQUAL "amd64")
|
|
|
|
set(target "x86_64${triple_suffix}")
|
|
|
|
elseif(${arch} STREQUAL "sparc64")
|
|
|
|
set(target "sparcv9${triple_suffix}")
|
2022-10-18 04:49:25 +00:00
|
|
|
elseif("${arch}" MATCHES "mips64|mips64el")
|
|
|
|
string(REGEX REPLACE "-gnu.*" "-gnuabi64" triple_suffix_gnu "${triple_suffix}")
|
|
|
|
string(REGEX REPLACE "mipsisa32" "mipsisa64" triple_cpu_mips "${triple_cpu}")
|
|
|
|
string(REGEX REPLACE "^mips$" "mips64" triple_cpu_mips "${triple_cpu_mips}")
|
|
|
|
string(REGEX REPLACE "^mipsel$" "mips64el" triple_cpu_mips "${triple_cpu_mips}")
|
|
|
|
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
|
|
|
|
elseif("${arch}" MATCHES "mips|mipsel")
|
|
|
|
string(REGEX REPLACE "-gnuabi.*" "-gnu" triple_suffix_gnu "${triple_suffix}")
|
|
|
|
string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}")
|
|
|
|
string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
|
|
|
|
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
|
2022-12-01 14:54:17 +00:00
|
|
|
elseif("${arch}" MATCHES "^arm")
|
|
|
|
# Arch is arm, armhf, armv6m (anything else would come from using
|
|
|
|
# COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
|
|
|
|
if (${arch} STREQUAL "armhf")
|
|
|
|
# If we are building for hard float but our ABI is soft float.
|
|
|
|
if ("${triple_suffix}" MATCHES ".*eabi$")
|
|
|
|
# Change "eabi" -> "eabihf"
|
|
|
|
set(triple_suffix "${triple_suffix}hf")
|
|
|
|
endif()
|
|
|
|
# ABI is already set in the triple, don't repeat it in the architecture.
|
|
|
|
set(arch "arm")
|
|
|
|
else ()
|
|
|
|
# If we are building for soft float, but the triple's ABI is hard float.
|
|
|
|
if ("${triple_suffix}" MATCHES ".*eabihf$")
|
|
|
|
# Change "eabihf" -> "eabi"
|
|
|
|
string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
set(target "${arch}${triple_suffix}")
|
2024-07-10 15:07:11 -05:00
|
|
|
elseif("${arch}" MATCHES "^amdgcn")
|
|
|
|
set(target "amdgcn-amd-amdhsa")
|
|
|
|
elseif("${arch}" MATCHES "^nvptx")
|
|
|
|
set(target "nvptx64-nvidia-cuda")
|
2018-06-28 03:11:52 +00:00
|
|
|
else()
|
2018-08-14 18:01:19 +00:00
|
|
|
set(target "${arch}${triple_suffix}")
|
2018-06-28 03:11:52 +00:00
|
|
|
endif()
|
|
|
|
set(${variable} ${target} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(get_compiler_rt_install_dir arch install_dir)
|
|
|
|
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
|
|
|
get_compiler_rt_target(${arch} target)
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE)
|
2018-06-28 03:11:52 +00:00
|
|
|
else()
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR} PARENT_SCOPE)
|
2018-06-28 03:11:52 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(get_compiler_rt_output_dir arch output_dir)
|
|
|
|
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
|
|
|
get_compiler_rt_target(${arch} target)
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE)
|
2018-06-28 03:11:52 +00:00
|
|
|
else()
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR} PARENT_SCOPE)
|
2018-06-28 03:11:52 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
2018-07-10 13:00:17 +00:00
|
|
|
|
|
|
|
# compiler_rt_process_sources(
|
|
|
|
# <OUTPUT_VAR>
|
|
|
|
# <SOURCE_FILE> ...
|
|
|
|
# [ADDITIONAL_HEADERS <header> ...]
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# Process the provided sources and write the list of new sources
|
|
|
|
# into `<OUTPUT_VAR>`.
|
|
|
|
#
|
|
|
|
# ADDITIONAL_HEADERS - Adds the supplied header to list of sources for IDEs.
|
|
|
|
#
|
|
|
|
# This function is very similar to `llvm_process_sources()` but exists here
|
|
|
|
# because we need to support standalone builds of compiler-rt.
|
|
|
|
function(compiler_rt_process_sources OUTPUT_VAR)
|
|
|
|
cmake_parse_arguments(
|
|
|
|
ARG
|
|
|
|
""
|
|
|
|
""
|
|
|
|
"ADDITIONAL_HEADERS"
|
|
|
|
${ARGN}
|
|
|
|
)
|
|
|
|
set(sources ${ARG_UNPARSED_ARGUMENTS})
|
|
|
|
set(headers "")
|
|
|
|
if (XCODE OR MSVC_IDE OR CMAKE_EXTRA_GENERATOR)
|
|
|
|
# For IDEs we need to tell CMake about header files.
|
|
|
|
# Otherwise they won't show up in UI.
|
|
|
|
set(headers ${ARG_ADDITIONAL_HEADERS})
|
|
|
|
list(LENGTH headers headers_length)
|
|
|
|
if (${headers_length} GREATER 0)
|
|
|
|
set_source_files_properties(${headers}
|
|
|
|
PROPERTIES HEADER_FILE_ONLY ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
set("${OUTPUT_VAR}" ${sources} ${headers} PARENT_SCOPE)
|
|
|
|
endfunction()
|
2019-05-07 19:00:37 +00:00
|
|
|
|
|
|
|
# Create install targets for a library and its parent component (if specified).
|
|
|
|
function(add_compiler_rt_install_targets name)
|
|
|
|
cmake_parse_arguments(ARG "" "PARENT_TARGET" "" ${ARGN})
|
|
|
|
|
|
|
|
if(ARG_PARENT_TARGET AND NOT TARGET install-${ARG_PARENT_TARGET})
|
|
|
|
# The parent install target specifies the parent component to scrape up
|
|
|
|
# anything not installed by the individual install targets, and to handle
|
|
|
|
# installation when running the multi-configuration generators.
|
|
|
|
add_custom_target(install-${ARG_PARENT_TARGET}
|
|
|
|
DEPENDS ${ARG_PARENT_TARGET}
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=${ARG_PARENT_TARGET}
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
add_custom_target(install-${ARG_PARENT_TARGET}-stripped
|
|
|
|
DEPENDS ${ARG_PARENT_TARGET}
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=${ARG_PARENT_TARGET}
|
|
|
|
-DCMAKE_INSTALL_DO_STRIP=1
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
set_target_properties(install-${ARG_PARENT_TARGET} PROPERTIES
|
2024-06-04 09:26:45 +02:00
|
|
|
FOLDER "Compiler-RT/Installation")
|
2019-05-07 19:00:37 +00:00
|
|
|
set_target_properties(install-${ARG_PARENT_TARGET}-stripped PROPERTIES
|
2024-06-04 09:26:45 +02:00
|
|
|
FOLDER "Compiler-RT/Installation")
|
2019-05-07 19:00:37 +00:00
|
|
|
add_dependencies(install-compiler-rt install-${ARG_PARENT_TARGET})
|
|
|
|
add_dependencies(install-compiler-rt-stripped install-${ARG_PARENT_TARGET}-stripped)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# We only want to generate per-library install targets if you aren't using
|
|
|
|
# an IDE because the extra targets get cluttered in IDEs.
|
|
|
|
if(NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
add_custom_target(install-${name}
|
|
|
|
DEPENDS ${name}
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=${name}
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
add_custom_target(install-${name}-stripped
|
|
|
|
DEPENDS ${name}
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=${name}
|
|
|
|
-DCMAKE_INSTALL_DO_STRIP=1
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
# If you have a parent target specified, we bind the new install target
|
|
|
|
# to the parent install target.
|
|
|
|
if(LIB_PARENT_TARGET)
|
|
|
|
add_dependencies(install-${LIB_PARENT_TARGET} install-${name})
|
|
|
|
add_dependencies(install-${LIB_PARENT_TARGET}-stripped install-${name}-stripped)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2022-08-25 21:34:09 -07:00
|
|
|
|
|
|
|
# Add warnings to catch potential errors that can lead to security
|
|
|
|
# vulnerabilities.
|
|
|
|
function(add_security_warnings out_flags macosx_sdk_version)
|
|
|
|
set(flags "${${out_flags}}")
|
|
|
|
|
|
|
|
append_list_if(COMPILER_RT_HAS_ARRAY_BOUNDS_FLAG -Werror=array-bounds flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_UNINITIALIZED_FLAG -Werror=uninitialized flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_SHADOW_FLAG -Werror=shadow flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_EMPTY_BODY_FLAG -Werror=empty-body flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_SIZEOF_POINTER_MEMACCESS_FLAG -Werror=sizeof-pointer-memaccess flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_SIZEOF_ARRAY_ARGUMENT_FLAG -Werror=sizeof-array-argument flags)
|
2022-09-13 08:47:43 -07:00
|
|
|
append_list_if(COMPILER_RT_HAS_SUSPICIOUS_MEMACCESS_FLAG -Werror=suspicious-memaccess flags)
|
2022-08-25 21:34:09 -07:00
|
|
|
append_list_if(COMPILER_RT_HAS_BUILTIN_MEMCPY_CHK_SIZE_FLAG -Werror=builtin-memcpy-chk-size flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_ARRAY_BOUNDS_POINTER_ARITHMETIC_FLAG -Werror=array-bounds-pointer-arithmetic flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_RETURN_STACK_ADDRESS_FLAG -Werror=return-stack-address flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_SIZEOF_ARRAY_DECAY_FLAG -Werror=sizeof-array-decay flags)
|
|
|
|
append_list_if(COMPILER_RT_HAS_FORMAT_INSUFFICIENT_ARGS_FLAG -Werror=format-insufficient-args flags)
|
2024-03-08 00:45:02 -08:00
|
|
|
# GCC complains if we pass -Werror=format-security without -Wformat
|
|
|
|
append_list_if(COMPILER_RT_HAS_BUILTIN_FORMAL_SECURITY_FLAG -Wformat -Werror=format-security flags)
|
2022-09-13 08:47:43 -07:00
|
|
|
append_list_if(COMPILER_RT_HAS_SIZEOF_ARRAY_DIV_FLAG -Werror=sizeof-array-div)
|
|
|
|
append_list_if(COMPILER_RT_HAS_SIZEOF_POINTER_DIV_FLAG -Werror=sizeof-pointer-div)
|
2022-08-25 21:34:09 -07:00
|
|
|
|
|
|
|
# Add -Wformat-nonliteral only if we can avoid adding the definition of
|
|
|
|
# eprintf. On Apple platforms, eprintf is needed only on macosx and only if
|
|
|
|
# its version is older than 10.7.
|
|
|
|
if ("${macosx_sdk_version}" VERSION_GREATER_EQUAL 10.7)
|
|
|
|
list(APPEND flags -Werror=format-nonliteral -DDONT_DEFINE_EPRINTF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(${out_flags} "${flags}" PARENT_SCOPE)
|
|
|
|
endfunction()
|