diff options
author | Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de> | 2016-08-02 05:51:05 +0000 |
---|---|---|
committer | Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de> | 2016-08-02 05:51:05 +0000 |
commit | cd0c0833dc50db8114bed2653d12be3902757a81 (patch) | |
tree | 6a6450523abdc0952f981584aaaee6efaa45ef5f /cmake/Modules/CompilerRTUtils.cmake | |
parent | 54743f73cc896fca706c687059906d3e95c4ea09 (diff) |
[CMake] Load LLVMConfig for standalone build of builtins
Therefore move some code into reusable macros.
Differential Revision: https://reviews.llvm.org/D22866
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277418 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules/CompilerRTUtils.cmake')
-rw-r--r-- | cmake/Modules/CompilerRTUtils.cmake | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake index 2ced895b6..25692974b 100644 --- a/cmake/Modules/CompilerRTUtils.cmake +++ b/cmake/Modules/CompilerRTUtils.cmake @@ -168,3 +168,57 @@ macro(detect_target_arch) add_default_target_arch(wasm64) endif() endmacro() + +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) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") + endif() + endif() + execute_process( + COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" + 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 LLVM_BINARY_DIR) + list(GET CONFIG_OUTPUT 1 LLVM_TOOLS_BINARY_DIR) + list(GET CONFIG_OUTPUT 2 LLVM_LIBRARY_DIR) + list(GET CONFIG_OUTPUT 3 LLVM_MAIN_SRC_DIR) + + # Make use of LLVM CMake modules. + 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") + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + + set(LLVM_LIBRARY_OUTPUT_INTDIR + ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +endmacro() + +macro(construct_compiler_rt_default_triple) + set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING + "Default triple for which compiler-rt runtimes will be built.") + 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) + list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS) + list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI) + # 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() |