mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[CMake] Split the target side of runtimes build
Previously, llvm/runtimes/CMakeLists.txt played two different roles: 1. host side which could used to set up the build of runtimes for different targets in the right order; 2. target side to build the runtimes for the specified target. This change splits llvm/runtimes/CMakeLists.txt and moves the target side to runtimes/CMakeLists laying down the foundation for the "A vision for building the runtimes" proposal. From the user perspective, there shouldn't be any visible difference at the moment. Differential Revision: https://reviews.llvm.org/D93408
This commit is contained in:
parent
f1b751d17b
commit
e0d03e7b34
@ -1,26 +1,13 @@
|
||||
# This file handles building LLVM runtime sub-projects.
|
||||
# TODO: This file assumes the Clang toolchain so it'd be better if it lived in
|
||||
# Clang, except there already is clang/runtime directory which contains
|
||||
# similar although simpler functionality. We should figure out how to merge
|
||||
# the two files.
|
||||
|
||||
# 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.
|
||||
|
||||
# Setting CMake minimum required version should be at the very top of the file
|
||||
# if this is the entry point.
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
cmake_minimum_required(VERSION 3.13.4)
|
||||
project(Runtimes C CXX ASM)
|
||||
endif()
|
||||
|
||||
# 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()
|
||||
|
||||
# Side-by-side subprojects layout.
|
||||
set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt;openmp")
|
||||
# TODO: Selecting runtimes should be always performed inside the runtimes
|
||||
# build, see runtimes/CMakeLists.txt, except that we currently check whether
|
||||
# compiler-rt is being built to determine whether to first build builtins
|
||||
# or not so we need that information in this file as well.
|
||||
set(LLVM_ALL_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind;openmp")
|
||||
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
|
||||
"Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
|
||||
if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
|
||||
@ -48,188 +35,13 @@ function(get_compiler_rt_path path)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# 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})
|
||||
include(LLVMExternalProjectUtils)
|
||||
|
||||
function(runtime_register_component name)
|
||||
set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
|
||||
endfunction()
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.4)
|
||||
project(Runtimes C CXX ASM)
|
||||
|
||||
find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
||||
find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
||||
|
||||
# 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"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
|
||||
)
|
||||
|
||||
# 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.
|
||||
get_compiler_rt_path(compiler_rt_path)
|
||||
if(compiler_rt_path)
|
||||
list(REMOVE_ITEM runtimes ${compiler_rt_path})
|
||||
if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
|
||||
list(INSERT runtimes 0 ${compiler_rt_path})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# 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})
|
||||
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
|
||||
|
||||
# This variable makes sure that e.g. llvm-lit is found.
|
||||
set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
|
||||
set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
|
||||
|
||||
# This variable is used by individual runtimes to locate LLVM files.
|
||||
set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
|
||||
|
||||
if(APPLE)
|
||||
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
|
||||
endif()
|
||||
|
||||
include(CheckLibraryExists)
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
# We don't have libc++ (yet)...
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++")
|
||||
|
||||
# ...but we need access to libc++ headers for CMake checks to succeed.
|
||||
if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -isystem ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include")
|
||||
endif()
|
||||
|
||||
# Avoid checking whether the compiler is working.
|
||||
set(LLVM_COMPILER_CHECKED ON)
|
||||
|
||||
# Handle common options used by all runtimes.
|
||||
include(AddLLVM)
|
||||
include(HandleLLVMOptions)
|
||||
include(FindPythonInterp)
|
||||
|
||||
# Remove the -nostdlib++ option we've added earlier.
|
||||
string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|
||||
|
||||
# Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
|
||||
if(CMAKE_HOST_APPLE AND APPLE)
|
||||
include(UseLibtool)
|
||||
endif()
|
||||
|
||||
# This can be used to detect whether we're in the runtimes build.
|
||||
set(RUNTIMES_BUILD ON)
|
||||
|
||||
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. D57992 tried
|
||||
# to get rid of this, but the runtimes treat *_STANDALONE_BUILD=OFF as if
|
||||
# llvm & clang are configured in the same CMake, and setup dependencies
|
||||
# against their targets. OpenMP has fixed the issue so we don't set the
|
||||
# variable.
|
||||
if (NOT ${canon_name} STREQUAL "OPENMP")
|
||||
set(${canon_name}_STANDALONE_BUILD ON)
|
||||
endif()
|
||||
|
||||
if(LLVM_RUNTIMES_LIBDIR_SUBDIR)
|
||||
set(${canon_name}_LIBDIR_SUBDIR "${LLVM_RUNTIMES_LIBDIR_SUBDIR}" CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
# Setting a variable to let sub-projects detect which other projects
|
||||
# will be included under here.
|
||||
set(HAVE_${canon_name} ON)
|
||||
endforeach()
|
||||
|
||||
# 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)
|
||||
|
||||
# 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)
|
||||
|
||||
add_subdirectory(${entry} ${projName})
|
||||
|
||||
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})
|
||||
endforeach()
|
||||
|
||||
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.
|
||||
|
||||
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}
|
||||
)
|
||||
add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
|
||||
endif()
|
||||
|
||||
get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
|
||||
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()
|
||||
|
||||
if(TARGET check-${component})
|
||||
list(APPEND SUB_CHECK_TARGETS check-${component})
|
||||
endif()
|
||||
|
||||
if(TARGET install-${component})
|
||||
list(APPEND SUB_INSTALL_TARGETS install-${component})
|
||||
endif()
|
||||
if(TARGET install-${component}-stripped)
|
||||
list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
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()
|
||||
endif()
|
||||
|
||||
else() # if this is included from LLVM's CMake
|
||||
include(LLVMExternalProjectUtils)
|
||||
|
||||
if(NOT LLVM_BUILD_RUNTIMES)
|
||||
if(NOT LLVM_BUILD_RUNTIMES)
|
||||
set(EXTRA_ARGS EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(check_apple_target triple builtin_or_runtime)
|
||||
function(check_apple_target triple builtin_or_runtime)
|
||||
set(error "\
|
||||
compiler-rt for Darwin builds for all platforms and architectures using a \
|
||||
single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \
|
||||
@ -255,9 +67,9 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
message(FATAL_ERROR "${error}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
function(builtin_default_target compiler_rt_path)
|
||||
function(builtin_default_target compiler_rt_path)
|
||||
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
|
||||
|
||||
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
|
||||
@ -281,9 +93,9 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
PASSTHROUGH_PREFIXES COMPILER_RT
|
||||
USE_TOOLCHAIN
|
||||
${EXTRA_ARGS})
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
function(builtin_register_target compiler_rt_path target)
|
||||
function(builtin_register_target compiler_rt_path target)
|
||||
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
|
||||
|
||||
check_apple_target(${target} builtin)
|
||||
@ -313,13 +125,13 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
${${target}_extra_args}
|
||||
USE_TOOLCHAIN
|
||||
${EXTRA_ARGS})
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
# 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.
|
||||
get_compiler_rt_path(compiler_rt_path)
|
||||
if(compiler_rt_path)
|
||||
# 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.
|
||||
get_compiler_rt_path(compiler_rt_path)
|
||||
if(compiler_rt_path)
|
||||
if(NOT LLVM_BUILTIN_TARGETS)
|
||||
builtin_default_target(${compiler_rt_path}
|
||||
DEPENDS clang-resource-headers)
|
||||
@ -349,12 +161,12 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
|
||||
add_dependencies(clang-bootstrap-deps builtins)
|
||||
endif()
|
||||
endif()
|
||||
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})
|
||||
# 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)
|
||||
@ -373,17 +185,17 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
string(SUBSTRING ${projName} 3 -1 projName)
|
||||
endif()
|
||||
list(APPEND runtime_names ${projName})
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
|
||||
if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/llvm-strip-link.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link
|
||||
@ONLY
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(runtime_default_target)
|
||||
function(runtime_default_target)
|
||||
cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
|
||||
|
||||
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
|
||||
@ -416,7 +228,7 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
endif()
|
||||
|
||||
llvm_ExternalProject_Add(runtimes
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
|
||||
DEPENDS ${ARG_DEPENDS}
|
||||
# Builtins were built separately above
|
||||
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
|
||||
@ -440,11 +252,11 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
${SUB_INSTALL_TARGETS}
|
||||
USE_TOOLCHAIN
|
||||
${EXTRA_ARGS})
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
# runtime_register_target(target)
|
||||
# Utility function to register external runtime target.
|
||||
function(runtime_register_target name target)
|
||||
# runtime_register_target(target)
|
||||
# Utility function to register external runtime target.
|
||||
function(runtime_register_target name target)
|
||||
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN})
|
||||
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
|
||||
@ -522,7 +334,7 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
endif()
|
||||
|
||||
llvm_ExternalProject_Add(runtimes-${name}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
|
||||
DEPENDS ${${name}_deps}
|
||||
# Builtins were built separately above
|
||||
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
|
||||
@ -543,9 +355,9 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
${${name}_test_targets}
|
||||
USE_TOOLCHAIN
|
||||
${EXTRA_ARGS})
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
if(runtimes)
|
||||
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.
|
||||
@ -655,5 +467,4 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
|
||||
add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1,3 +0,0 @@
|
||||
set(SUB_COMPONENTS @SUB_COMPONENTS@)
|
||||
set(SUB_CHECK_TARGETS @SUB_CHECK_TARGETS@)
|
||||
set(SUB_INSTALL_TARGETS @SUB_INSTALL_TARGETS@)
|
Loading…
x
Reference in New Issue
Block a user