2016-06-24 06:07:21 +08:00
|
|
|
# This file handles building LLVM runtime sub-projects.
|
|
|
|
|
|
|
|
# Runtimes are different from tools or other drop-in projects because runtimes
|
|
|
|
# should be built with the LLVM toolchain from the build directory. This file is
|
|
|
|
# a first step to formalizing runtime build interfaces.
|
|
|
|
|
|
|
|
# In the current state this file only works with compiler-rt, other runtimes
|
|
|
|
# will work as the runtime build interface standardizes.
|
|
|
|
|
|
|
|
# Find all subdirectories containing CMake projects
|
|
|
|
file(GLOB entries *)
|
|
|
|
foreach(entry ${entries})
|
|
|
|
if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
|
|
|
|
list(APPEND runtimes ${entry})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2017-11-28 06:31:11 +08:00
|
|
|
# Side-by-side subprojects layout.
|
|
|
|
set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt")
|
|
|
|
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
|
|
|
|
"Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
|
|
|
|
if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
|
|
|
|
set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
|
|
|
|
endif()
|
|
|
|
foreach(proj ${LLVM_ENABLE_RUNTIMES})
|
|
|
|
set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
|
|
|
|
if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
|
|
|
|
list(APPEND runtimes ${proj_dir})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
|
|
|
|
endif()
|
|
|
|
string(TOUPPER "${proj}" canon_name)
|
|
|
|
STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
|
|
|
|
set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
function(get_compiler_rt_path path)
|
|
|
|
foreach(entry ${runtimes})
|
|
|
|
get_filename_component(projName ${entry} NAME)
|
|
|
|
if("${projName}" MATCHES "compiler-rt")
|
|
|
|
set(${path} ${entry} PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
# If this file is acting as a top-level CMake invocation, this code path is
|
|
|
|
# triggered by the external project call for the runtimes target below.
|
|
|
|
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
2016-08-26 04:49:51 +08:00
|
|
|
function(runtime_register_component name)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
|
|
|
|
endfunction()
|
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
cmake_minimum_required(VERSION 3.4.3)
|
2017-09-01 09:05:59 +08:00
|
|
|
project(Runtimes C CXX ASM)
|
2016-06-24 06:07:21 +08:00
|
|
|
|
|
|
|
# Add the root project's CMake modules, and the LLVM build's modules to the
|
|
|
|
# CMake module path.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
|
2017-04-14 05:29:03 +08:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
|
2017-07-14 08:35:21 +08:00
|
|
|
"${LLVM_LIBRARY_DIR}/cmake/llvm"
|
2016-06-24 06:07:21 +08:00
|
|
|
)
|
|
|
|
|
2016-08-31 05:29:21 +08:00
|
|
|
# Some of the runtimes will conditionally use the compiler-rt sanitizers
|
|
|
|
# to make this work smoothly we ensure that compiler-rt is added first in
|
|
|
|
# the list of sub-projects. This allows other sub-projects to have checks
|
|
|
|
# like `if(TARGET asan)` to enable building with asan.
|
2017-11-28 06:31:11 +08:00
|
|
|
get_compiler_rt_path(compiler_rt_path)
|
2016-08-31 05:29:21 +08:00
|
|
|
if(compiler_rt_path)
|
|
|
|
list(REMOVE_ITEM runtimes ${compiler_rt_path})
|
2017-08-17 03:13:45 +08:00
|
|
|
if(NOT LLVM_BUILD_COMPILER_RT)
|
|
|
|
list(INSERT runtimes 0 ${compiler_rt_path})
|
|
|
|
endif()
|
2016-08-31 05:29:21 +08:00
|
|
|
endif()
|
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
# LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
|
|
|
|
# This file is installed as part of LLVM distributions, so this can be used
|
|
|
|
# either from a build directory or an installed LLVM.
|
|
|
|
include(LLVMConfig)
|
|
|
|
|
|
|
|
# Setting these variables will allow the sub-build to put their outputs into
|
|
|
|
# the library and bin directories of the top-level build.
|
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
|
2016-08-26 01:18:41 +08:00
|
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
|
2016-06-24 06:07:21 +08:00
|
|
|
|
2016-09-15 14:14:13 +08:00
|
|
|
# This variable makes sure that e.g. llvm-lit is found.
|
|
|
|
set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
|
|
|
|
|
2017-03-24 10:21:11 +08:00
|
|
|
if(APPLE)
|
2017-07-12 07:41:15 +08:00
|
|
|
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
|
2017-03-24 10:21:11 +08:00
|
|
|
endif()
|
|
|
|
|
2017-04-14 05:29:03 +08:00
|
|
|
set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
|
|
set(SAFE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
|
|
|
|
|
|
|
|
include(CheckLibraryExists)
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
|
|
|
|
check_library_exists(c fopen "" LLVM_HAS_C_LIB)
|
|
|
|
check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG)
|
|
|
|
if(LLVM_HAS_NODEFAULTLIBS_FLAG)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
|
|
|
|
if(LLVM_HAS_C_LIB)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES c)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-04-11 13:18:03 +08:00
|
|
|
# Avoid checking whether the compiler is working.
|
|
|
|
set(LLVM_COMPILER_CHECKED ON)
|
2018-04-27 23:10:50 +08:00
|
|
|
# Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions
|
|
|
|
# resulting in unjustified successes by check_cxx_compiler_flag.
|
|
|
|
set(LLVM_ENABLE_WARNINGS ON)
|
2018-04-11 13:18:03 +08:00
|
|
|
|
|
|
|
# Handle common options used by all runtimes.
|
|
|
|
include(AddLLVM)
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
|
2017-04-14 05:29:03 +08:00
|
|
|
set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
|
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
foreach(entry ${runtimes})
|
|
|
|
get_filename_component(projName ${entry} NAME)
|
|
|
|
|
|
|
|
# TODO: Clean this up as part of an interface standardization
|
|
|
|
string(REPLACE "-" "_" canon_name ${projName})
|
|
|
|
string(TOUPPER ${canon_name} canon_name)
|
|
|
|
# The subdirectories need to treat this as standalone builds
|
|
|
|
set(${canon_name}_STANDALONE_BUILD On)
|
|
|
|
|
2018-07-11 03:13:33 +08:00
|
|
|
if(LLVM_RUNTIMES_LIBDIR_SUFFIX)
|
|
|
|
set(${canon_name}_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}" CACHE STRING "" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2016-08-19 06:18:11 +08:00
|
|
|
# Setting a variable to let sub-projects detect which other projects
|
|
|
|
# will be included under here.
|
|
|
|
set(HAVE_${canon_name} On)
|
2017-01-03 04:33:33 +08:00
|
|
|
endforeach()
|
2016-08-19 06:18:11 +08:00
|
|
|
|
2017-01-03 04:33:33 +08:00
|
|
|
# We do this in two loops so that HAVE_* is set for each runtime before the
|
|
|
|
# other runtimes are added.
|
|
|
|
foreach(entry ${runtimes})
|
|
|
|
get_filename_component(projName ${entry} NAME)
|
2017-07-12 07:41:15 +08:00
|
|
|
|
2016-08-26 01:18:41 +08:00
|
|
|
# Between each sub-project we want to cache and clear the LIT properties
|
|
|
|
set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
|
|
set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
|
|
set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
|
|
set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
|
|
|
2017-11-28 06:31:11 +08:00
|
|
|
add_subdirectory(${entry} ${projName})
|
2016-08-26 01:18:41 +08:00
|
|
|
|
|
|
|
get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
|
|
get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
|
|
get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
|
|
get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
|
|
|
|
|
|
list(APPEND RUNTIMES_LIT_TESTSUITES ${LLVM_LIT_TESTSUITES})
|
|
|
|
list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
|
|
|
|
list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
|
|
|
|
list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
|
2016-06-24 06:07:21 +08:00
|
|
|
endforeach()
|
|
|
|
|
2016-08-26 04:49:51 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
# Add a global check rule now that all subdirectories have been traversed
|
|
|
|
# and we know the total set of lit testsuites.
|
2017-07-14 08:35:21 +08:00
|
|
|
|
2016-08-26 04:49:51 +08:00
|
|
|
add_lit_target(check-runtimes
|
|
|
|
"Running all regression tests"
|
|
|
|
${RUNTIMES_LIT_TESTSUITES}
|
|
|
|
PARAMS ${RUNTIMES_LIT_PARAMS}
|
|
|
|
DEPENDS ${RUNTIMES_LIT_DEPENDS}
|
|
|
|
ARGS ${RUNTIMES_LIT_EXTRA_ARGS}
|
|
|
|
)
|
2016-08-27 04:08:57 +08:00
|
|
|
add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
|
2016-08-26 04:49:51 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
|
2016-08-27 08:19:51 +08:00
|
|
|
if(SUB_COMPONENTS)
|
|
|
|
list(REMOVE_DUPLICATES SUB_COMPONENTS)
|
|
|
|
foreach(component ${SUB_COMPONENTS})
|
|
|
|
if(NOT TARGET ${component})
|
|
|
|
message(SEND_ERROR "Missing target for runtime component ${component}!")
|
|
|
|
continue()
|
|
|
|
endif()
|
2017-07-12 07:41:15 +08:00
|
|
|
|
|
|
|
if(TARGET check-${component})
|
|
|
|
list(APPEND SUB_CHECK_TARGETS check-${component})
|
2016-08-27 08:19:51 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(TARGET install-${component})
|
|
|
|
list(APPEND SUB_INSTALL_TARGETS install-${component})
|
|
|
|
endif()
|
2017-12-09 03:42:46 +08:00
|
|
|
if(TARGET install-${component}-stripped)
|
|
|
|
list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
|
|
|
|
endif()
|
2016-08-27 08:19:51 +08:00
|
|
|
endforeach()
|
|
|
|
|
2017-07-12 07:41:15 +08:00
|
|
|
if(LLVM_RUNTIMES_TARGET)
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
|
|
|
|
${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
|
|
|
|
else()
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
|
|
|
|
${LLVM_BINARY_DIR}/runtimes/Components.cmake)
|
|
|
|
endif()
|
2016-08-27 08:19:51 +08:00
|
|
|
endif()
|
2016-08-26 01:18:41 +08:00
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
else() # if this is included from LLVM's CMake
|
|
|
|
include(LLVMExternalProjectUtils)
|
|
|
|
|
2017-03-24 06:40:10 +08:00
|
|
|
if(NOT LLVM_BUILD_RUNTIMES)
|
|
|
|
set(EXTRA_ARGS EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
|
|
|
|
2017-11-28 06:31:11 +08:00
|
|
|
function(builtin_default_target compiler_rt_path)
|
2017-09-09 06:26:50 +08:00
|
|
|
llvm_ExternalProject_Add(builtins
|
2017-11-28 06:31:11 +08:00
|
|
|
${compiler_rt_path}/lib/builtins
|
2017-09-09 06:26:50 +08:00
|
|
|
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
|
|
|
|
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
|
2018-06-28 11:11:52 +08:00
|
|
|
-DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
|
|
|
|
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
|
2017-09-09 06:26:50 +08:00
|
|
|
-DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
|
|
|
|
-DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
|
2017-11-15 07:47:20 +08:00
|
|
|
-DCMAKE_C_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_ASM_COMPILER_WORKS=ON
|
2017-09-09 06:26:50 +08:00
|
|
|
PASSTHROUGH_PREFIXES COMPILER_RT
|
|
|
|
USE_TOOLCHAIN
|
|
|
|
${EXTRA_ARGS})
|
|
|
|
endfunction()
|
|
|
|
|
2017-11-28 06:31:11 +08:00
|
|
|
function(builtin_register_target compiler_rt_path target)
|
2017-09-09 06:26:50 +08:00
|
|
|
string(REPLACE "-" ";" builtin_target_list ${target})
|
|
|
|
foreach(item ${builtin_target_list})
|
|
|
|
string(TOLOWER "${item}" item_lower)
|
|
|
|
if(item_lower MATCHES "darwin")
|
|
|
|
message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
get_cmake_property(variableNames VARIABLES)
|
|
|
|
foreach(variableName ${variableNames})
|
|
|
|
if(variableName MATCHES "^BUILTINS_${target}")
|
|
|
|
string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
|
|
|
|
list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
llvm_ExternalProject_Add(builtins-${target}
|
2017-11-28 06:31:11 +08:00
|
|
|
${compiler_rt_path}/lib/builtins
|
2017-09-09 06:26:50 +08:00
|
|
|
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
|
|
|
|
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
|
2018-06-28 11:11:52 +08:00
|
|
|
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
|
|
|
|
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
|
2017-09-09 06:26:50 +08:00
|
|
|
-DCMAKE_C_COMPILER_TARGET=${target}
|
|
|
|
-DCMAKE_ASM_COMPILER_TARGET=${target}
|
2017-11-15 07:47:20 +08:00
|
|
|
-DCMAKE_C_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_ASM_COMPILER_WORKS=ON
|
|
|
|
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
|
2017-09-09 06:26:50 +08:00
|
|
|
${${target}_extra_args}
|
2018-06-07 05:43:37 +08:00
|
|
|
TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
|
2017-09-09 06:26:50 +08:00
|
|
|
USE_TOOLCHAIN
|
|
|
|
${EXTRA_ARGS})
|
|
|
|
endfunction()
|
|
|
|
|
2016-06-24 06:07:21 +08:00
|
|
|
# If compiler-rt is present we need to build the builtin libraries first. This
|
|
|
|
# is required because the other runtimes need the builtin libraries present
|
|
|
|
# before the just-built compiler can pass the configuration tests.
|
2017-11-28 06:31:11 +08:00
|
|
|
get_compiler_rt_path(compiler_rt_path)
|
|
|
|
if(compiler_rt_path)
|
2017-03-24 10:21:11 +08:00
|
|
|
if(NOT LLVM_BUILTIN_TARGETS)
|
2017-11-28 06:31:11 +08:00
|
|
|
builtin_default_target(${compiler_rt_path})
|
2016-12-13 07:15:10 +08:00
|
|
|
else()
|
2017-09-09 06:26:50 +08:00
|
|
|
if("default" IN_LIST LLVM_BUILTIN_TARGETS)
|
2017-11-28 06:31:11 +08:00
|
|
|
builtin_default_target(${compiler_rt_path})
|
2017-09-09 06:26:50 +08:00
|
|
|
list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
|
|
|
|
else()
|
|
|
|
add_custom_target(builtins)
|
|
|
|
add_custom_target(install-builtins)
|
2017-12-09 03:42:46 +08:00
|
|
|
add_custom_target(install-builtins-stripped)
|
2017-09-09 06:26:50 +08:00
|
|
|
endif()
|
|
|
|
|
2016-12-13 07:15:10 +08:00
|
|
|
foreach(target ${LLVM_BUILTIN_TARGETS})
|
2017-11-28 06:31:11 +08:00
|
|
|
builtin_register_target(${compiler_rt_path} ${target})
|
2017-07-12 07:41:15 +08:00
|
|
|
|
2016-12-13 07:15:10 +08:00
|
|
|
add_dependencies(builtins builtins-${target})
|
2017-06-03 03:38:11 +08:00
|
|
|
add_dependencies(install-builtins install-builtins-${target})
|
2017-12-09 03:42:46 +08:00
|
|
|
add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
|
2016-12-13 07:15:10 +08:00
|
|
|
endforeach()
|
|
|
|
endif()
|
2016-06-24 06:07:21 +08:00
|
|
|
set(deps builtins)
|
2016-10-20 05:50:25 +08:00
|
|
|
# We don't need to depend on the builtins if we're building instrumented
|
|
|
|
# because the next stage will use the same compiler used to build this stage.
|
|
|
|
if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
|
|
|
|
add_dependencies(clang-bootstrap-deps builtins)
|
|
|
|
endif()
|
2016-06-24 06:07:21 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# We create a list the names of all the runtime projects in all uppercase and
|
|
|
|
# with dashes turned to underscores. This gives us the CMake variable prefixes
|
|
|
|
# for all variables that will apply to runtimes.
|
|
|
|
foreach(entry ${runtimes})
|
|
|
|
get_filename_component(projName ${entry} NAME)
|
|
|
|
string(REPLACE "-" "_" canon_name ${projName})
|
|
|
|
string(TOUPPER ${canon_name} canon_name)
|
|
|
|
list(APPEND prefixes ${canon_name})
|
2016-08-19 05:47:18 +08:00
|
|
|
|
|
|
|
string(FIND ${projName} "lib" LIB_IDX)
|
|
|
|
if(LIB_IDX EQUAL 0)
|
|
|
|
string(SUBSTRING ${projName} 3 -1 projName)
|
|
|
|
endif()
|
|
|
|
list(APPEND runtime_names ${projName})
|
2016-06-24 06:07:21 +08:00
|
|
|
endforeach()
|
|
|
|
|
2017-11-17 05:28:54 +08:00
|
|
|
function(runtime_default_target)
|
|
|
|
cmake_parse_arguments(ARG "" "" "DEPS;PREFIXES" ${ARGN})
|
|
|
|
|
2017-09-09 06:26:50 +08:00
|
|
|
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
|
|
|
|
|
|
|
|
foreach(runtime_name ${runtime_names})
|
|
|
|
list(APPEND extra_targets
|
|
|
|
${runtime_name}
|
2017-12-09 03:42:46 +08:00
|
|
|
install-${runtime_name}
|
|
|
|
install-${runtime_name}-stripped)
|
2017-09-09 06:26:50 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
list(APPEND test_targets check-${runtime_name})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-05-18 00:58:44 +08:00
|
|
|
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
|
|
|
|
if(NOT ${component} IN_LIST SUB_COMPONENTS)
|
|
|
|
list(APPEND extra_targets ${component} install-${component} install-${component}-stripped)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2017-09-09 06:26:50 +08:00
|
|
|
|
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
list(APPEND test_targets runtimes-test-depends check-runtimes)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
llvm_ExternalProject_Add(runtimes
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
2017-11-17 05:28:54 +08:00
|
|
|
DEPENDS ${ARG_DEPS}
|
2017-09-09 06:26:50 +08:00
|
|
|
# Builtins were built separately above
|
|
|
|
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
|
|
|
|
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
|
|
|
|
-DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
|
2018-06-28 11:11:52 +08:00
|
|
|
-DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
|
|
|
|
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
|
2018-01-09 07:50:59 +08:00
|
|
|
-DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
|
|
|
|
-DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
|
|
|
|
-DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
|
2017-11-15 07:47:20 +08:00
|
|
|
-DCMAKE_C_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_CXX_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_ASM_COMPILER_WORKS=ON
|
2017-11-28 06:31:11 +08:00
|
|
|
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
|
|
|
|
${ARG_PREFIXES}
|
2017-09-09 06:26:50 +08:00
|
|
|
EXTRA_TARGETS ${extra_targets}
|
|
|
|
${test_targets}
|
|
|
|
${SUB_COMPONENTS}
|
|
|
|
${SUB_CHECK_TARGETS}
|
|
|
|
${SUB_INSTALL_TARGETS}
|
|
|
|
USE_TOOLCHAIN
|
|
|
|
${EXTRA_ARGS})
|
|
|
|
endfunction()
|
|
|
|
|
2017-07-12 07:41:15 +08:00
|
|
|
# runtime_register_target(target)
|
|
|
|
# Utility function to register external runtime target.
|
2017-11-17 05:28:54 +08:00
|
|
|
function(runtime_register_target name target)
|
|
|
|
cmake_parse_arguments(ARG "" "" "DEPS" ${ARGN})
|
2017-09-09 06:26:50 +08:00
|
|
|
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
|
2017-08-17 03:13:45 +08:00
|
|
|
|
2017-11-17 05:28:54 +08:00
|
|
|
set(${name}_deps ${ARG_DEPS})
|
2017-08-17 03:13:45 +08:00
|
|
|
if(NOT name STREQUAL target)
|
|
|
|
list(APPEND ${name}_deps runtimes-${target})
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
2016-08-26 01:18:41 +08:00
|
|
|
|
|
|
|
foreach(runtime_name ${runtime_names})
|
2018-06-27 11:14:41 +08:00
|
|
|
set(${runtime_name}-${name} ${runtime_name})
|
|
|
|
set(install-${runtime_name}-${name} install-${runtime_name})
|
|
|
|
set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
|
|
|
|
list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
|
2017-07-11 03:23:28 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2018-06-27 11:14:41 +08:00
|
|
|
set(check-${runtime_name}-${name} check-${runtime_name} )
|
|
|
|
list(APPEND ${name}_test_targets check-${runtime_name}-${name})
|
2017-07-11 03:23:28 +08:00
|
|
|
endif()
|
2016-08-26 01:18:41 +08:00
|
|
|
endforeach()
|
|
|
|
|
2017-09-02 10:28:03 +08:00
|
|
|
foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
|
2018-06-27 11:14:41 +08:00
|
|
|
set(${target_name}-${name} ${target_name})
|
|
|
|
list(APPEND ${name}_extra_targets ${target_name}-${name})
|
2017-07-12 07:41:15 +08:00
|
|
|
endforeach()
|
|
|
|
|
2018-05-18 00:58:44 +08:00
|
|
|
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
|
|
|
|
if(NOT "${target_name}:${target_name}-${component}" IN_LIST extra_targets)
|
|
|
|
list(APPEND ${name}_extra_targets
|
|
|
|
"${target_name}:${target_name}-${component}"
|
|
|
|
"${target_name}:${target_name}-install-${component}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2016-08-27 04:08:57 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2018-06-27 11:14:41 +08:00
|
|
|
set(runtimes-test-depends-${name} runtimes-test-depends)
|
|
|
|
set(check-runtimes-${name} check-runtimes)
|
|
|
|
list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
|
2017-08-17 03:13:45 +08:00
|
|
|
foreach(target_name IN LISTS SUB_CHECK_TARGETS)
|
2018-06-27 11:14:41 +08:00
|
|
|
set(${target_name}-${name} ${target_name})
|
|
|
|
list(APPEND ${name}_test_targets ${target_name}-${name})
|
|
|
|
list(APPEND test_targets ${target_name}-${name})
|
2016-08-27 04:34:11 +08:00
|
|
|
endforeach()
|
2017-07-12 07:41:15 +08:00
|
|
|
set(test_targets "${test_targets}" PARENT_SCOPE)
|
2016-08-27 04:08:57 +08:00
|
|
|
endif()
|
|
|
|
|
2017-07-12 07:41:15 +08:00
|
|
|
get_cmake_property(variableNames VARIABLES)
|
|
|
|
foreach(variableName ${variableNames})
|
2017-08-17 03:13:45 +08:00
|
|
|
if(variableName MATCHES "^RUNTIMES_${name}")
|
|
|
|
string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
|
|
|
|
list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
|
|
|
|
elseif(variableName MATCHES "^RUNTIMES_${target}")
|
2017-07-12 07:41:15 +08:00
|
|
|
string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
|
2017-08-17 03:13:45 +08:00
|
|
|
list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2017-08-17 03:13:45 +08:00
|
|
|
llvm_ExternalProject_Add(runtimes-${name}
|
2016-06-24 06:07:21 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
2017-08-17 03:13:45 +08:00
|
|
|
DEPENDS ${${name}_deps}
|
2016-06-24 06:07:21 +08:00
|
|
|
# Builtins were built separately above
|
|
|
|
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
|
2016-08-27 04:08:57 +08:00
|
|
|
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
|
2017-07-14 08:35:21 +08:00
|
|
|
-DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
|
2018-06-28 11:11:52 +08:00
|
|
|
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
|
|
|
|
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
|
2017-07-12 07:41:15 +08:00
|
|
|
-DCMAKE_C_COMPILER_TARGET=${target}
|
|
|
|
-DCMAKE_CXX_COMPILER_TARGET=${target}
|
|
|
|
-DCMAKE_ASM_COMPILER_TARGET=${target}
|
|
|
|
-DCMAKE_C_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_CXX_COMPILER_WORKS=ON
|
|
|
|
-DCMAKE_ASM_COMPILER_WORKS=ON
|
|
|
|
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
|
2017-09-09 06:26:50 +08:00
|
|
|
-DLLVM_RUNTIMES_TARGET=${name}
|
2017-08-17 03:13:45 +08:00
|
|
|
${${name}_extra_args}
|
2017-11-28 06:31:11 +08:00
|
|
|
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
|
2018-06-07 05:43:37 +08:00
|
|
|
TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
|
2017-08-17 03:13:45 +08:00
|
|
|
EXTRA_TARGETS ${${name}_extra_targets}
|
|
|
|
${${name}_test_targets}
|
2017-03-24 06:40:10 +08:00
|
|
|
USE_TOOLCHAIN
|
|
|
|
${EXTRA_ARGS})
|
2017-07-12 07:41:15 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
if(runtimes)
|
|
|
|
# Create a runtimes target that uses this file as its top-level CMake file.
|
|
|
|
# The runtimes target is a configuration of all the runtime libraries
|
|
|
|
# together in a single CMake invocaiton.
|
|
|
|
if(NOT LLVM_RUNTIME_TARGETS)
|
2017-11-17 05:28:54 +08:00
|
|
|
runtime_default_target(
|
|
|
|
DEPS ${deps}
|
|
|
|
PREFIXES ${prefixes}
|
|
|
|
)
|
2017-09-09 06:26:50 +08:00
|
|
|
else()
|
|
|
|
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
|
2017-11-17 05:28:54 +08:00
|
|
|
runtime_default_target(
|
|
|
|
DEPS ${deps}
|
|
|
|
PREFIXES ${prefixes})
|
2017-09-09 06:26:50 +08:00
|
|
|
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
|
|
|
|
else()
|
|
|
|
add_custom_target(runtimes)
|
|
|
|
add_custom_target(runtimes-configure)
|
|
|
|
add_custom_target(install-runtimes)
|
2017-12-09 03:42:46 +08:00
|
|
|
add_custom_target(install-runtimes-stripped)
|
2017-07-12 07:41:15 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2017-09-09 06:26:50 +08:00
|
|
|
add_custom_target(check-runtimes)
|
|
|
|
add_custom_target(runtimes-test-depends)
|
|
|
|
set(test_targets "")
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
2018-05-18 00:58:44 +08:00
|
|
|
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
|
|
|
|
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
|
|
|
|
add_custom_target(${component})
|
|
|
|
add_custom_target(install-${component})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
|
|
|
|
2017-08-17 03:13:45 +08:00
|
|
|
foreach(name ${LLVM_RUNTIME_TARGETS})
|
2018-06-27 11:35:53 +08:00
|
|
|
runtime_register_target(${name} ${name}
|
2017-11-17 05:28:54 +08:00
|
|
|
DEPS ${deps}
|
|
|
|
)
|
2017-07-12 07:41:15 +08:00
|
|
|
|
2017-08-17 03:13:45 +08:00
|
|
|
add_dependencies(runtimes runtimes-${name})
|
|
|
|
add_dependencies(runtimes-configure runtimes-${name}-configure)
|
|
|
|
add_dependencies(install-runtimes install-runtimes-${name})
|
2017-12-09 03:42:46 +08:00
|
|
|
add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
|
2017-07-12 07:41:15 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2017-08-17 03:13:45 +08:00
|
|
|
add_dependencies(check-runtimes check-runtimes-${name})
|
|
|
|
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-06-27 11:35:53 +08:00
|
|
|
|
|
|
|
foreach(sanitizer ${LLVM_RUNTIME_SANITIZERS})
|
|
|
|
if (sanitizer STREQUAL "Address")
|
|
|
|
set(sanitizer_name "asan")
|
|
|
|
elseif (sanitizer STREQUAL "Memory")
|
|
|
|
set(sanitizer_name "msan")
|
|
|
|
elseif (sanitizer STREQUAL "Thread")
|
|
|
|
set(sanitizer_name "tsan")
|
|
|
|
elseif (sanitizer STREQUAL "Undefined")
|
|
|
|
set(sanitizer_name "ubsan")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported value of LLVM_RUNTIME_TARGET_SANITIZERS: ${sanitizers}")
|
|
|
|
endif()
|
|
|
|
foreach(name ${LLVM_RUNTIME_SANITIZER_${sanitizer}_TARGETS})
|
|
|
|
runtime_register_target(${name}-${sanitizer_name} ${name}
|
|
|
|
DEPS runtimes-${name}
|
|
|
|
CMAKE_ARGS -DLLVM_USE_SANITIZER=${sanitizer}
|
|
|
|
-DLLVM_RUNTIMES_PREFIX=${name}/
|
|
|
|
-DLLVM_RUNTIMES_LIBDIR_SUFFIX=/${sanitizer_name}
|
|
|
|
)
|
|
|
|
add_dependencies(runtimes runtimes-${name}-${sanitizer_name})
|
|
|
|
add_dependencies(runtimes-configure runtimes-${name}-${sanitizer_name}-configure)
|
|
|
|
add_dependencies(install-runtimes install-runtimes-${name}-${sanitizer_name})
|
|
|
|
add_dependencies(install-runtimes-stripped install-runtimes-${name}-${sanitizer_name}-stripped)
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
2017-07-12 07:41:15 +08:00
|
|
|
endif()
|
|
|
|
|
2016-10-20 05:50:25 +08:00
|
|
|
# TODO: This is a hack needed because the libcxx headers are copied into the
|
|
|
|
# build directory during configuration. Without that step the clang in the
|
|
|
|
# build directory cannot find the C++ headers in certain configurations.
|
|
|
|
# I need to build a mechanism for runtime projects to provide CMake code
|
|
|
|
# that executes at LLVM configuration time to handle this case.
|
|
|
|
if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
|
|
|
|
add_dependencies(clang-bootstrap-deps runtimes-configure)
|
|
|
|
endif()
|
|
|
|
|
2016-08-27 04:08:57 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2016-09-02 02:26:01 +08:00
|
|
|
set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-runtimes)
|
2017-07-11 03:23:28 +08:00
|
|
|
|
|
|
|
set(RUNTIMES_TEST_DEPENDS
|
|
|
|
FileCheck
|
|
|
|
count
|
|
|
|
llvm-nm
|
|
|
|
llvm-objdump
|
|
|
|
llvm-xray
|
|
|
|
not
|
|
|
|
obj2yaml
|
|
|
|
sancov
|
|
|
|
sanstats
|
|
|
|
)
|
2017-07-12 07:41:15 +08:00
|
|
|
foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
|
2017-07-11 03:23:28 +08:00
|
|
|
add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
|
|
|
|
endforeach()
|
2016-08-27 04:08:57 +08:00
|
|
|
endif()
|
2016-06-24 06:07:21 +08:00
|
|
|
endif()
|
|
|
|
endif()
|