From e6975c4ced27fe93945393603df79557aeb23d83 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Tue, 29 Jun 2021 23:34:18 -0700 Subject: [PATCH] [CMake] Support runtimes targets without specifying triple Currently, for BUILTIN_TARGETS and RUNTIME_TARGETS you can either use the special "default" value, or a target triple. For the "default" value, we don't set any target triple and passthrough a subset of CMake variables into the subbuild. This is typically used on Darwin where we build universal binaries and a single target triple therefore isn't sufficient. For the target triple value, you can set arbitrary CMake variables through RUNTIMES__, but we always set target triple to . This gives more flexibility, because we can precisely control what variables are set in the subbuild, but is unsuitable for platforms like Darwin. To address this, we would like to introduce a third option which is similar to the second option, except we won't set target triple in the subbuild (you can always do so yourself by setting the appropriate CMake variable, e.g. RUNTIMES__CMAKE_C_COMPILER_TARGET=). This change is a first step in that direction, by eliminating the support of target triples from builtin_register_target and runtime_register_target helper functions. Differential Revision: https://reviews.llvm.org/D117263 --- llvm/runtimes/CMakeLists.txt | 111 ++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index 5bb8904..9d5cc31 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -96,36 +96,33 @@ function(builtin_default_target compiler_rt_path) ${EXTRA_ARGS}) endfunction() -function(builtin_register_target compiler_rt_path target) - cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) - - check_apple_target(${target} builtin) +function(builtin_register_target compiler_rt_path name) + cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN}) - get_cmake_property(variableNames VARIABLES) - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "BUILTINS_${target}" out) + set(${name}_extra_args ${ARG_CMAKE_ARGS}) + get_cmake_property(variable_names VARIABLES) + foreach(variable_name ${variable_names}) + string(FIND "${variable_name}" "BUILTINS_${name}" out) if("${out}" EQUAL 0) - string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") - list(APPEND ${target}_extra_args "-D${new_name}=${new_value}") + string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name}) + string(REPLACE ";" "|" new_value "${${variable_name}}") + list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") endif() endforeach() - llvm_ExternalProject_Add(builtins-${target} + llvm_ExternalProject_Add(builtins-${name} ${compiler_rt_path}/lib/builtins DEPENDS ${ARG_DEPENDS} CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} - -DLLVM_DEFAULT_TARGET_TRIPLE=${target} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON ${COMMON_CMAKE_ARGS} - ${${target}_extra_args} + ${${name}_extra_args} USE_TOOLCHAIN - TARGET_TRIPLE ${target} - ${EXTRA_ARGS}) + ${EXTRA_ARGS} ${ARG_EXTRA_ARGS}) endfunction() # If compiler-rt is present we need to build the builtin libraries first. This @@ -148,8 +145,12 @@ if(compiler_rt_path) endif() foreach(target ${LLVM_BUILTIN_TARGETS}) + check_apple_target(${target} builtin) + builtin_register_target(${compiler_rt_path} ${target} - DEPENDS clang-resource-headers) + DEPENDS clang-resource-headers + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target} + EXTRA_ARGS TARGET_TRIPLE ${target}) add_dependencies(builtins builtins-${target}) add_dependencies(install-builtins install-builtins-${target}) @@ -249,20 +250,13 @@ function(runtime_default_target) ${EXTRA_ARGS}) endfunction() -# runtime_register_target(target) +# runtime_register_target(name) # Utility function to register external runtime target. -function(runtime_register_target name target) - cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN}) +function(runtime_register_target name) + cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;BASE_NAME;EXTRA_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) - check_apple_target(${target} runtime) - - set(${name}_deps ${ARG_DEPENDS}) - if(NOT name STREQUAL target) - list(APPEND ${name}_deps runtimes-${target}) - endif() - foreach(runtime_name ${runtime_names}) set(${runtime_name}-${name} ${runtime_name}) set(install-${runtime_name}-${name} install-${runtime_name}) @@ -274,9 +268,9 @@ function(runtime_register_target name target) endif() endforeach() - foreach(target_name IN LISTS SUB_COMPONENTS) - set(${target_name}-${name} ${target_name}) - list(APPEND ${name}_extra_targets ${target_name}-${name}) + foreach(target IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS) + set(${target}-${name} ${target}) + list(APPEND ${name}_extra_targets ${target}-${name}) endforeach() foreach(target_name IN LISTS SUB_INSTALL_TARGETS) @@ -308,36 +302,28 @@ function(runtime_register_target name target) endif() endforeach() - foreach(target_name IN LISTS SUB_CHECK_TARGETS component_check_targets) - set(${target_name}-${name} ${target_name}) - list(APPEND ${name}_test_targets ${target_name}-${name}) - list(APPEND test_targets ${target_name}-${name}) + foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets) + set(${target}-${name} ${target}) + list(APPEND ${name}_test_targets ${target}-${name}) + list(APPEND test_targets ${target}-${name}) endforeach() set(test_targets "${test_targets}" PARENT_SCOPE) endif() set(${name}_extra_args ${ARG_CMAKE_ARGS}) - get_cmake_property(variableNames VARIABLES) - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "RUNTIMES_${target}_" out) - if("${out}" EQUAL 0) - string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") - list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") - endif() - endforeach() - if(NOT "${name}" STREQUAL "${target}") - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "RUNTIMES_${name}_" out) + get_cmake_property(variable_names VARIABLES) + foreach(extra_name IN ITEMS ${name} ${ARG_BASE_NAME}) + foreach(variable_name ${variable_names}) + string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out) if("${out}" EQUAL 0) - string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") + string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name}) + string(REPLACE ";" "|" new_value "${${variable_name}}") list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") endif() endforeach() - endif() + endforeach() - if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES AND NOT RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES) + if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES) string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}") list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH}) endif() @@ -350,11 +336,10 @@ function(runtime_register_target name target) llvm_ExternalProject_Add(runtimes-${name} ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes - DEPENDS ${${name}_deps} + DEPENDS ${ARG_DEPENDS} # Builtins were built separately above - CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} - -DLLVM_DEFAULT_TARGET_TRIPLE=${target} -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR} -DCMAKE_C_COMPILER_WORKS=ON @@ -367,8 +352,7 @@ function(runtime_register_target name target) EXTRA_TARGETS ${${name}_extra_targets} ${${name}_test_targets} USE_TOOLCHAIN - TARGET_TRIPLE ${target} - ${EXTRA_ARGS}) + ${EXTRA_ARGS} ${ARG_EXTRA_ARGS}) endfunction() if(runtimes) @@ -427,8 +411,13 @@ if(runtimes) set(builtins_dep_name ${builtins_dep}) endif() endif() - runtime_register_target(${name} ${name} - DEPENDS ${builtins_dep_name}) + + check_apple_target(${name} runtime) + + runtime_register_target(${name} + DEPENDS ${builtins_dep_name} + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} + EXTRA_ARGS TARGET_TRIPLE ${name}) add_dependencies(runtimes runtimes-${name}) add_dependencies(runtimes-configure runtimes-${name}-configure) @@ -452,10 +441,14 @@ if(runtimes) foreach(multilib ${LLVM_RUNTIME_MULTILIBS}) foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS}) - runtime_register_target(${name}+${multilib} ${name} + runtime_register_target(${name}+${multilib} DEPENDS runtimes-${name} - CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/ - -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}) + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} + -DLLVM_RUNTIMES_PREFIX=${name}/ + -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib} + BASE_NAME ${name} + EXTRA_ARGS TARGET_TRIPLE ${name}) + add_dependencies(runtimes runtimes-${name}+${multilib}) add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure) add_dependencies(install-runtimes install-runtimes-${name}+${multilib}) -- 2.7.4