2016-04-29 02:22:01 +08:00
|
|
|
include(CMakePushCheckState)
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
2013-01-19 00:05:21 +08: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)
|
2014-10-24 06:13:52 +08:00
|
|
|
set(argstring "")
|
2013-01-19 00:05:21 +08:00
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(set_target_link_flags target)
|
2014-10-24 06:13:52 +08:00
|
|
|
set(argstring "")
|
2013-01-19 00:05:21 +08:00
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
|
|
|
|
endfunction()
|
|
|
|
|
2013-10-26 07:03:34 +08: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 15:52:40 +08:00
|
|
|
|
2014-03-13 17:31:36 +08:00
|
|
|
# Appends value to all lists in ARGN, if the condition is true.
|
2014-10-16 06:47:54 +08:00
|
|
|
macro(append_list_if condition value)
|
2014-03-13 17:31:36 +08:00
|
|
|
if(${condition})
|
|
|
|
foreach(list ${ARGN})
|
|
|
|
list(APPEND ${list} ${value})
|
|
|
|
endforeach()
|
2014-02-18 15:52:40 +08:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2014-03-13 19:31:10 +08: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 18:01:04 +08:00
|
|
|
macro(append_rtti_flag polarity list)
|
2016-08-23 02:30:37 +08:00
|
|
|
if(${polarity})
|
2016-03-05 18:01:04 +08: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 15:52:40 +08:00
|
|
|
endmacro()
|
2015-04-09 16:06:49 +08:00
|
|
|
|
2016-01-27 17:28:01 +08: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-14 04:38:16 +08: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-18 00:57:38 +08:00
|
|
|
|
2016-08-19 23:13:21 +08: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-18 00:57:38 +08: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-13 07:14:02 +08: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-18 00:57:38 +08: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 12:33:04 +08:00
|
|
|
set(TARGET_${arch}_LINK_FLAGS ${ARGN})
|
2016-02-18 00:57:38 +08:00
|
|
|
set(argstring "")
|
|
|
|
foreach(arg ${ARGN})
|
|
|
|
set(argstring "${argstring} ${arg}")
|
|
|
|
endforeach()
|
|
|
|
check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
|
2016-07-22 18:15:09 +08:00
|
|
|
if(NOT DEFINED CAN_TARGET_${arch})
|
|
|
|
if(NOT HAS_${arch}_DEF)
|
|
|
|
set(CAN_TARGET_${arch} FALSE)
|
|
|
|
elseif(TEST_COMPILE_ONLY)
|
2019-03-16 04:14:46 +08:00
|
|
|
try_compile_only(CAN_TARGET_${arch} FLAGS ${TARGET_${arch}_CFLAGS})
|
2016-07-22 18:15:09 +08:00
|
|
|
else()
|
2016-09-21 13:44:06 +08: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-22 02:25:35 +08:00
|
|
|
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
|
2018-06-17 17:51:33 +08:00
|
|
|
try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
|
2016-09-21 13:44:06 +08: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-22 02:25:35 +08:00
|
|
|
OUTPUT_VARIABLE TARGET_${arch}_OUTPUT)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS})
|
2016-07-22 18:15:09 +08:00
|
|
|
endif()
|
2016-02-18 00:57:38 +08:00
|
|
|
endif()
|
|
|
|
if(${CAN_TARGET_${arch}})
|
|
|
|
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
2016-07-21 02:06:31 +08:00
|
|
|
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" STREQUAL "${arch}" AND
|
2016-02-18 00:57:38 +08: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-04 01:34:02 +08:00
|
|
|
|
|
|
|
macro(detect_target_arch)
|
|
|
|
check_symbol_exists(__arm__ "" __ARM)
|
|
|
|
check_symbol_exists(__aarch64__ "" __AARCH64)
|
|
|
|
check_symbol_exists(__x86_64__ "" __X86_64)
|
|
|
|
check_symbol_exists(__i386__ "" __I386)
|
|
|
|
check_symbol_exists(__mips__ "" __MIPS)
|
|
|
|
check_symbol_exists(__mips64__ "" __MIPS64)
|
2017-12-01 05:04:11 +08:00
|
|
|
check_symbol_exists(__powerpc64__ "" __PPC64)
|
|
|
|
check_symbol_exists(__powerpc64le__ "" __PPC64LE)
|
2018-03-01 15:47:27 +08:00
|
|
|
check_symbol_exists(__riscv "" __RISCV)
|
2016-06-04 01:34:02 +08:00
|
|
|
check_symbol_exists(__s390x__ "" __S390X)
|
2019-07-12 16:30:17 +08:00
|
|
|
check_symbol_exists(__sparc "" __SPARC)
|
|
|
|
check_symbol_exists(__sparcv9 "" __SPARCV9)
|
2016-06-04 01:34:02 +08:00
|
|
|
check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
|
|
|
|
check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
|
|
|
|
if(__ARM)
|
|
|
|
add_default_target_arch(arm)
|
|
|
|
elseif(__AARCH64)
|
|
|
|
add_default_target_arch(aarch64)
|
|
|
|
elseif(__X86_64)
|
|
|
|
add_default_target_arch(x86_64)
|
|
|
|
elseif(__I386)
|
|
|
|
add_default_target_arch(i386)
|
|
|
|
elseif(__MIPS64) # must be checked before __MIPS
|
|
|
|
add_default_target_arch(mips64)
|
|
|
|
elseif(__MIPS)
|
|
|
|
add_default_target_arch(mips)
|
2017-12-01 05:04:11 +08:00
|
|
|
elseif(__PPC64)
|
|
|
|
add_default_target_arch(powerpc64)
|
|
|
|
elseif(__PPC64LE)
|
|
|
|
add_default_target_arch(powerpc64le)
|
2018-03-01 15:47:27 +08: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()
|
|
|
|
message(FATAL_ERROR "Unsupport XLEN for RISC-V")
|
|
|
|
endif()
|
2016-06-04 01:34:02 +08:00
|
|
|
elseif(__S390X)
|
|
|
|
add_default_target_arch(s390x)
|
2019-07-12 16:30:17 +08:00
|
|
|
elseif(__SPARCV9)
|
|
|
|
add_default_target_arch(sparcv9)
|
|
|
|
elseif(__SPARC)
|
|
|
|
add_default_target_arch(sparc)
|
2016-06-04 01:34:02 +08:00
|
|
|
elseif(__WEBASSEMBLY32)
|
|
|
|
add_default_target_arch(wasm32)
|
|
|
|
elseif(__WEBASSEMBLY64)
|
|
|
|
add_default_target_arch(wasm64)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2016-08-02 13:51:05 +08:00
|
|
|
|
|
|
|
macro(load_llvm_config)
|
|
|
|
if (NOT LLVM_CONFIG_PATH)
|
|
|
|
find_program(LLVM_CONFIG_PATH "llvm-config"
|
|
|
|
DOC "Path to llvm-config binary")
|
|
|
|
if (NOT LLVM_CONFIG_PATH)
|
2018-08-03 13:50:33 +08:00
|
|
|
message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
|
|
|
|
"llvm-config not found.\n"
|
|
|
|
"Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config.")
|
2016-08-02 13:51:05 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
2018-08-03 13:50:33 +08:00
|
|
|
if (LLVM_CONFIG_PATH)
|
|
|
|
execute_process(
|
2018-09-20 13:22:37 +08:00
|
|
|
COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir"
|
2018-08-03 13:50:33 +08:00
|
|
|
RESULT_VARIABLE HAD_ERROR
|
|
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT)
|
|
|
|
if (HAD_ERROR)
|
|
|
|
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
|
|
|
endif()
|
|
|
|
string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
|
|
list(GET CONFIG_OUTPUT 0 BINARY_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR)
|
2018-09-20 13:22:37 +08:00
|
|
|
list(GET CONFIG_OUTPUT 4 INCLUDE_DIR)
|
2016-09-14 21:42:31 +08:00
|
|
|
|
2018-08-03 13:50:33 +08:00
|
|
|
set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree")
|
|
|
|
set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
|
|
|
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
2018-09-20 13:22:37 +08:00
|
|
|
set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
|
|
|
set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers")
|
2016-08-02 13:51:05 +08:00
|
|
|
|
[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 13:28:01 +08:00
|
|
|
# Detect if we have the LLVMXRay and TestingSupport library installed and
|
|
|
|
# available from llvm-config.
|
|
|
|
execute_process(
|
2018-12-21 21:37:30 +08:00
|
|
|
COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
|
[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 13:28:01 +08:00
|
|
|
RESULT_VARIABLE HAD_ERROR
|
2019-02-12 09:09:07 +08:00
|
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
|
|
ERROR_QUIET)
|
[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 13:28:01 +08:00
|
|
|
if (HAD_ERROR)
|
|
|
|
message(WARNING "llvm-config finding xray failed with status ${HAD_ERROR}")
|
|
|
|
set(COMPILER_RT_HAS_LLVMXRAY FALSE)
|
|
|
|
else()
|
|
|
|
string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
|
|
list(GET CONFIG_OUTPUT 0 LDFLAGS)
|
|
|
|
list(GET CONFIG_OUTPUT 1 LIBLIST)
|
2020-01-28 11:20:02 +08:00
|
|
|
file(TO_CMAKE_PATH "${LDFLAGS}" LDFLAGS)
|
|
|
|
file(TO_CMAKE_PATH "${LIBLIST}" LIBLIST)
|
[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 13:28:01 +08:00
|
|
|
set(LLVM_XRAY_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags for LLVMXRay library")
|
|
|
|
set(LLVM_XRAY_LIBLIST ${LIBLIST} CACHE STRING "Library list for LLVMXRay")
|
|
|
|
set(COMPILER_RT_HAS_LLVMXRAY TRUE)
|
|
|
|
endif()
|
|
|
|
|
2018-12-21 21:37:30 +08:00
|
|
|
set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
|
|
|
|
RESULT_VARIABLE HAD_ERROR
|
2019-02-12 09:09:07 +08:00
|
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
|
|
ERROR_QUIET)
|
2018-12-21 21:37:30 +08:00
|
|
|
if (HAD_ERROR)
|
|
|
|
message(WARNING "llvm-config finding testingsupport failed with status ${HAD_ERROR}")
|
2020-04-09 17:18:42 +08:00
|
|
|
elseif(COMPILER_RT_INCLUDE_TESTS)
|
2018-12-21 21:37:30 +08:00
|
|
|
string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
|
|
list(GET CONFIG_OUTPUT 0 LDFLAGS)
|
|
|
|
list(GET CONFIG_OUTPUT 1 LIBLIST)
|
|
|
|
if (LIBLIST STREQUAL "")
|
|
|
|
message(WARNING "testingsupport library not installed, some tests will be skipped")
|
|
|
|
else()
|
2020-01-28 11:20:02 +08:00
|
|
|
file(TO_CMAKE_PATH "${LDFLAGS}" LDFLAGS)
|
|
|
|
file(TO_CMAKE_PATH "${LIBLIST}" LIBLIST)
|
2018-12-21 21:37:30 +08:00
|
|
|
set(LLVM_TESTINGSUPPORT_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags for LLVMTestingSupport library")
|
|
|
|
set(LLVM_TESTINGSUPPORT_LIBLIST ${LIBLIST} CACHE STRING "Library list for LLVMTestingSupport")
|
|
|
|
set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-08-03 13:50:33 +08:00
|
|
|
# Make use of LLVM CMake modules.
|
|
|
|
# --cmakedir is supported since llvm r291218 (4.0 release)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${LLVM_CONFIG_PATH} --cmakedir
|
|
|
|
RESULT_VARIABLE HAD_ERROR
|
|
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT)
|
|
|
|
if(NOT HAD_ERROR)
|
|
|
|
string(STRIP "${CONFIG_OUTPUT}" LLVM_CMAKE_PATH_FROM_LLVM_CONFIG)
|
|
|
|
file(TO_CMAKE_PATH ${LLVM_CMAKE_PATH_FROM_LLVM_CONFIG} LLVM_CMAKE_PATH)
|
|
|
|
else()
|
|
|
|
file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE)
|
|
|
|
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
|
|
|
|
endif()
|
2017-01-10 07:23:56 +08:00
|
|
|
|
2018-08-03 13:50:33 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
|
|
|
# Get some LLVM variables from LLVMConfig.
|
|
|
|
include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
|
2016-08-02 13:51:05 +08:00
|
|
|
|
2018-08-03 13:50:33 +08:00
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR
|
|
|
|
${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
endif()
|
2016-08-02 13:51:05 +08:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(construct_compiler_rt_default_triple)
|
2016-12-13 07:14:02 +08: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()
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET})
|
|
|
|
else()
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING
|
|
|
|
"Default triple for which compiler-rt runtimes will be built.")
|
|
|
|
endif()
|
|
|
|
|
2016-08-02 13:51:05 +08:00
|
|
|
if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE)
|
|
|
|
# Backwards compatibility: this variable used to be called
|
|
|
|
# COMPILER_RT_TEST_TARGET_TRIPLE.
|
|
|
|
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
|
|
|
|
list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
|
|
|
|
# Determine if test target triple is specified explicitly, and doesn't match the
|
|
|
|
# default.
|
|
|
|
if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE)
|
|
|
|
set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE)
|
|
|
|
else()
|
|
|
|
set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2017-08-31 01:12:57 +08:00
|
|
|
|
|
|
|
# Filter out generic versions of routines that are re-implemented in
|
|
|
|
# architecture specific manner. This prevents multiple definitions of the
|
|
|
|
# same symbols, making the symbol selection non-deterministic.
|
|
|
|
function(filter_builtin_sources output_var exclude_or_include excluded_list)
|
|
|
|
if(exclude_or_include STREQUAL "EXCLUDE")
|
|
|
|
set(filter_action GREATER)
|
|
|
|
set(filter_value -1)
|
|
|
|
elseif(exclude_or_include STREQUAL "INCLUDE")
|
|
|
|
set(filter_action LESS)
|
|
|
|
set(filter_value 0)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "filter_builtin_sources called without EXCLUDE|INCLUDE")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(intermediate ${ARGN})
|
|
|
|
foreach (_file ${intermediate})
|
|
|
|
get_filename_component(_name_we ${_file} NAME_WE)
|
|
|
|
list(FIND ${excluded_list} ${_name_we} _found)
|
|
|
|
if(_found ${filter_action} ${filter_value})
|
|
|
|
list(REMOVE_ITEM intermediate ${_file})
|
|
|
|
elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c")
|
|
|
|
get_filename_component(_name ${_file} NAME)
|
|
|
|
string(REPLACE ".S" ".c" _cname "${_name}")
|
|
|
|
list(REMOVE_ITEM intermediate ${_cname})
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
set(${output_var} ${intermediate} PARENT_SCOPE)
|
|
|
|
endfunction()
|
2018-06-28 11:11:52 +08:00
|
|
|
|
|
|
|
function(get_compiler_rt_target arch variable)
|
2018-08-15 02:01:19 +08:00
|
|
|
string(FIND ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} "-" dash_index)
|
|
|
|
string(SUBSTRING ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${dash_index} -1 triple_suffix)
|
2018-11-16 12:14:23 +08: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")
|
2018-08-15 02:01:19 +08:00
|
|
|
set(target "i686${COMPILER_RT_OS_SUFFIX}${triple_suffix}")
|
2018-06-28 11:11:52 +08:00
|
|
|
else()
|
2018-08-15 02:01:19 +08:00
|
|
|
set(target "${arch}${triple_suffix}")
|
2018-06-28 11:11:52 +08: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)
|
2019-05-28 07:23:50 +08:00
|
|
|
set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE)
|
2018-06-28 11:11:52 +08:00
|
|
|
else()
|
|
|
|
set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE)
|
|
|
|
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)
|
2019-05-28 07:23:50 +08:00
|
|
|
set(${output_dir} ${COMPILER_RT_OUTPUT_DIR}/lib/${target} PARENT_SCOPE)
|
2018-06-28 11:11:52 +08:00
|
|
|
else()
|
|
|
|
set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2018-07-10 21:00:17 +08: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-08 03:00:37 +08: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
|
|
|
|
FOLDER "Compiler-RT Misc")
|
|
|
|
set_target_properties(install-${ARG_PARENT_TARGET}-stripped PROPERTIES
|
|
|
|
FOLDER "Compiler-RT Misc")
|
|
|
|
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()
|